# Find Lines Example
#
# This example shows off how to find lines in the image. For each line object
# found in the image a line object is returned which includes the line's rotation.
# Note: Line detection is done by using the Hough Transform:
# http://en.wikipedia.org/wiki/Hough_transform
# Please read about it above for more information on what `theta` and `rho` are.
# find_lines() finds infinite length lines. Use find_line_segments() to find non-infinite lines.
enable_lens_corr = False # turn on for straighter lines...
import sensor, image, time,lcd,pyb
p = pyb.Pin("P7", pyb.Pin.OUT_PP)
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA2)
sensor.skip_frames(time = 2000)
clock = time.clock()
lcd.init()
# All line objects have a `theta()` method to get their rotation angle in degrees.
# You can filter lines based on their rotation angle.
min_degree = 175
max_degree = 185
a=False
b=False
# All lines also have `x1()`, `y1()`, `x2()`, and `y2()` methods to get their end-points
# and a `line()` method to get all the above as one 4 value tuple for `draw_line()`.
while(True):
lcd.display(sensor.snapshot()) # Take a picture and display the image.
clock.tick()
img = sensor.snapshot().gamma_corr(gamma = 0.5, contrast = 0.5, brightness = 0.3)
img = sensor.snapshot()
if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens...
# `threshold` controls how many lines in the image are found. Only lines with
# edge difference magnitude sums greater than `threshold` are detected...
# More about `threshold` - each pixel in the image contributes a magnitude value
# to a line. The sum of all contributions is the magintude for that line. Then
# when lines are merged their magnitudes are added togheter. Note that `threshold`
# filters out lines with low magnitudes before merging. To see the magnitude of
# un-merged lines set `theta_margin` and `rho_margin` to 0...
# `theta_margin` and `rho_margin` control merging similar lines. If two lines
# theta and rho value differences are less than the margins then they are merged.
for l in img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25):
if (min_degree <= l.theta()) and (l.theta() <= max_degree):
# img.draw_line(l.line(), color = (255, 0, 0))
if l.x1()>55 and l.x1()<75 :
img.draw_line(l.line(), color = (255, 0, 0))
a=True
#if ( abs ( l.x2()-l.x1() )<=5 ):
# print(l)
img.draw_string(70, 10, "ok-A", color = (255,255,255), scale = 2, mono_space = False,char_rotation = 0, char_hmirror = False, char_vflip = False,string_rotation = 0, string_hmirror = False, string_vflip = False)
# print(l)
if (85 <= l.theta()) and (l.theta() <= 95):
if l.y1()>60 and l.y1()<90 :
img.draw_line(l.line(), color = (255, 0, 0))
b=True
img.draw_string(80, 60, "ok-B", color = (255,255,255), scale = 2, mono_space = False,char_rotation = 0, char_hmirror = False, char_vflip = False,string_rotation = 0, string_hmirror = False, string_vflip = False)
img.draw_rectangle(0,60 , 128, 30, color = (255,255,255), thickness = 2, fill = False)
img.draw_rectangle(55,0 , 20, 160, color = (255,255,255), thickness = 2, fill = False)
if (a==True): p.high()
# or p.value(1) to make the pin high (3.3V)
lcd.display(img)
print("FPS %f" % clock.fps())
# About negative rho values:
#
# A [theta+0:-rho] tuple is the same as [theta+180:+rho].
C
c5xl
@c5xl
0
声望
4
楼层
311
资料浏览
0
粉丝
0
关注
c5xl 发布的帖子
-
openmv3 cam7 gpio 控制高低电平 在循环中 硬件lcd 白屏 ,pc 显示图像。后死机
-
运行报错 。硬件设备openmv3 cam7.固件4.02
# Find Line Segments Example # # This example shows off how to find line segments in the image. For each line object # found in the image a line object is returned which includes the line's rotation. # find_line_segments() finds finite length lines (but is slow). # Use find_line_segments() to find non-infinite lines (and is fast). enable_lens_corr = False # turn on for straighter lines... import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) # grayscale is faster sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() # All lines also have `x1()`, `y1()`, `x2()`, and `y2()` methods to get their end-points # and a `line()` method to get all the above as one 4 value tuple for `draw_line()`. while(True): clock.tick() img = sensor.snapshot() if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens... # `merge_distance` controls the merging of nearby lines. At 0 (the default), no # merging is done. At 1, any line 1 pixel away from another is merged... and so # on as you increase this value. You may wish to merge lines as line segment # detection produces a lot of line segment results. # `max_theta_diff` controls the maximum amount of rotation difference between # any two lines about to be merged. The default setting allows for 15 degrees. for l in img.find_line_segments(merge_distance = 0, max_theta_diff = 5): img.draw_line(l.line(), color = (255, 0, 0)) # print(l) print("FPS %f" % clock.fps()) ![0_1625494858820_无标题.png](https://fcdn.singtown.com/e258a9ff-3637-4137-985d-e2374b07b7aa.png)