I
iear 发布的帖子
-
RE: 怎样识别随机颜色红绿蓝其中一种颜色的色卡呢?还有threshold_index ,color_code又是怎么得到值的
@kidswong999 那用获取颜色信息阈值( l_max,l_min,a_max,a_min,b_max,b_min)然后 再通过这个阈值范围用find_circles去找到附近的气球相对应的颜色吗 还是说需要find_blobs. 之前用获取颜色信息这个就怕识别红绿蓝的阈值的时候 有误差
-
RE: 怎样识别随机颜色红绿蓝其中一种颜色的色卡呢?还有threshold_index ,color_code又是怎么得到值的
@kidswong999 我说的随机颜色 是可能红 或绿或蓝 没有固定是红之类的这些
-
RE: 怎样识别随机颜色红绿蓝其中一种颜色的色卡呢?还有threshold_index ,color_code又是怎么得到值的
@kidswong999 这样子是红色的色卡就识别是红色吗 那可以通过设置这三个的颜色阈值然后find_blobs识别到的颜色通过color_code去获取颜色代码,然后用if那些去判断color_code是红或绿或蓝 然后在这个if语句里面用find_circles去找到位于色卡前面的颜色气球吗
-
RE: 识别色卡颜色并找到相对应颜色的气球扎破,我写的这个代码可以实现吗?
import sensor, image, time red_threshold=(0, 100, 7, 127, -128, 127) green_threshold=(0, 100, -128, -28, -128, 127) blue_threshold=(14, 87, -83, 127, -113, -14) red_color_code = 1 blue_color_code = 4 green_color_code = 8 sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(10) # 跳过10帧,使新设置生效 sensor.set_auto_whitebal(False) sensor.set_auto_gain(False) clock=time.clock() ROI=(0,0,80,80) while(True): img = sensor.snapshot() statistics=img.get_statistics(roi=ROI) color_l_min=statistics.l_min() color_a_min=statistics.a_min() color_b_min=statistics.b_min() color_l_max=statistics.l_max() color_a_max=statistics.a_max() color_b_max=statistics.b_max() anycolor_threshold=(color_l_min,color_l_max,color_a_min,color_a_max,color_b_min,color_b_max) blobs=img.find_blobs([anycolor_threshold],area_threshold=100) if anycolor_threshold==red_threshold: blobs =img.find_blobs([red_threshold],area_threshold=100) elif anycolor_threshold==green_threshold: blobs =img.find_blobs([green_threshold],area_threshold=100) elif anycolor_threshold==blue_threshold: blobs =img.find_blobs([blue_threshold],area_threshold=100) if blobs: for blob in blobs: #迭代找到的目标颜色区域 x = blob[0] y = blob[1] width = blob[2] height = blob[3] center_x = blob[5] center_y = blob[6] color_code = blob[8] if color_code == red_color_code: img.draw_string(x, y - 10, "red", color = (0xFF, 0x00, 0x00)) elif color_code == blue_color_code: img.draw_string(x, y - 10, "blue", color = (0xFF, 0x00, 0x00)) elif color_code == green_color_code: img.draw_string(x, y - 10, "green", color = (0xFF, 0x00, 0x00)) #用矩形标记出目标颜色区域 img.draw_rectangle(blob[0],blob[1],blob[2],blob[3]) #在目标颜色区域的中心画十字形标记 img.draw_cross(blob[5], blob[6]) print(clock.fps())
-
RE: 识别色卡颜色并找到相对应颜色的气球扎破,我写的这个代码可以实现吗?
@kidswong999 这个代码测出来的画面有跟踪颜色的,是可以的,是我这个的代码不对吗,用统计信息得到的LAB颜色值是不等同于颜色阈值吗,我把roi调成(0,0,320,240)还是这样 黑色也出现好多+
-
识别色卡颜色并找到相对应颜色的气球扎破,我写的这个代码可以实现吗?
import sensor, image, time sensor.reset() # 初始化摄像头 sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565. sensor.set_framesize(sensor.QVGA) sensor.skip_frames(10) # 跳过10帧,使新设置生效 sensor.set_auto_whitebal(False) sensor.set_auto_gain(False) clock=time.clock() ROI=(0,0,300,300) while(True): img = sensor.snapshot() statistics=img.get_statistics(roi=ROI) color_l=statistics.l_mode() color_a=statistics.a_mode() color_b=statistics.b_mode() print(color_l,color_a,color_b) img.draw_rectangle(ROI) anycolor_threshold=(color_l,color_a,color_b) blobs =img.find_blobs([anycolor_threshold]) if blobs: #如果找到了目标颜色 for b in blobs: img.draw_rectangle(b[0:4]) img.draw_cross(b[5], b[6]) print(clock.fps())
-
RE: 请问 用openmv如何判断色卡的颜色,并找出相对应颜色的小球?(小白不懂,求大佬帮忙解答一下啊) 谢谢啦!
@kidswong99
import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 10) sensor.set_auto_whitebal(False) sensor.set_auto_gain(False) clock = time.clock() 、 ROI=(0,0,80,80) while(True): clock.tick() img = sensor.snapshot() statistics=img.get_statistics(roi=ROI) color_l=statistics.l_mode() color_a=statistics.a_mode() color_b=statistics.b_mode() print(color_l,color_a,color_b) img.draw_rectangle(ROI) pyb.delay(2000) img = sensor.snapshot().lens_corr(1.8) for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2): area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r()) statistics = img.get_statistics(roi=area)#像素颜色统计 print(statistics) if 20<statistics.l_mode()<100 and 15<statistics.a_mode()<127 and 15<statistics.b_mode()<12:#if the circle is red img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的红色圆形用红色的圆框出来 if 30<statistics.l_mode()<100 and -64<statistics.a_mode()<-8 and -32<statistics.b_mode()<32:#if the corcle is green img.draw_circle(c.x(),c.y(),c.r(),color=(0,255,0)) if 0<statistics.l_mode()<15 and 0<statistics.a_mode()<40 and -80<statistics.b_mode()<-20:#if the circle is blue img.draw_circle(c.x(),c.y(),c.r(),color=(0,0,255)) else: img.draw_rectangle(area, color = (255, 255, 255)) #将非红色的圆用白色的矩形框出来 print("FPS %f" % clock.fps())