logo

调用find_line函数之后,打印返回image.line的对象列表会报错,携带源码和报错图片,help

2021-07-11 22:09
0
aucy
# Single Color RGB565 Blob Tracking Example
#
# This example shows off single color RGB565 tracking using the OpenMV Cam.

import sensor, image, time, math

threshold_index = 0 # 0 for red, 1 for green, 2 for blue

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
# The below thresholds track in general red/green/blue things. You may wish to tune them...
sb = (8, 21, -36, 9, -11, 17)
ng=(29, 81, 30, 80, 30, 80)# generic_green_thresholds
THRESHOLD=(70, 0, -128, 127, -128, 127)             
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

while(True):
    clock.tick()
    img = sensor.snapshot()
    blobsb=img.find_blobs([sb], pixels_threshold=200, area_threshold=200)
    blobng=img.find_blobs([ng], pixels_threshold=200, area_threshold=200)
    if blobsb or blobng:
        for s in blobsb:
            img.draw_cross(s.cx(), s.cy())
            #img.draw_rectangle(s.rect())
        for blobn in  blobng:
            img.draw_cross(blobn.cx(), blobn.cy())
            #img.draw_rectangle(blobn.rect())
            img.draw_line(s.cx(), s.cy(),blobn.cx(), blobn.cy(), color = [0, 0, 255])
            #img.binary([THRESHOLD])
            line=img.find_line_segments()
            if (line):
                rho_err = abs(line.rho())-img.width()/2
                if line.theta()>90:
                    theta_err = line.theta()-180
                else:
                    theta_err = line.theta()
                img.draw_line(line.line(), color = 127)
                print(line.theta())

        # Note - the blob rotation is unique to 0-180 only.
        #img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20)
0
aucy
6a24698b-dcf9-4abb-8a5e-0980aa37ebf6.png
2021-07-12 20:24
I
网红小智智 星瞳科技

line=img.find_line_segments()

这里返回的是数组,应该是

lines=img.find_line_segments()
for line in lines:
    pass