logo

为什么颜色识别的时候画面稳定圈出来的框和十字叉一直在抖呢?可不可以删除该代码if中的那些语句?

2019-10-08 12:54
M
_14ak
请在这里粘贴代码

import sensor, image, time, math

thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds

(30, 100, -64, -8, -32, 32), # generic_green_thresholds

(0, 15, 0, 40, -80, -20), # generic_blue_thresholds

(88, 44, 6, 51, -57, -7)] # generic_pink_thresholds

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 2000)

sensor.set_auto_gain(False) # 关闭白平衡

sensor.set_auto_whitebal(False) # 关闭感官原件

clock = time.clock()

while(True):

clock.tick()

img = sensor.snapshot()

for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200): #这些值使得blob是圆形时则稳定

if blob.elongation() > 0.5: #延伸率

img.draw_edges(blob.min_corners(), color=(255,0,0)) #红色对应的RGB

img.draw_line(blob.major_axis_line(), color=(0,255,0)) #绿色对应RGB

img.draw_line(blob.minor_axis_line(), color=(0,0,255)) #color为蓝色的RGB

img.draw_line(blob.minor_axis_line(), color=(255,192,203)) #粉色RGB

img.draw_rectangle(blob.rect())

img.draw_cross(blob.cx(), blob.cy())

img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20)

print(clock.fps())

2019-10-10 14:43
I
网红小智智 星瞳科技

阈值设置的好一些。如果可以的话,加一个滤波。