如何识别三个颜色,我这点开只能识别红色不能识别绿色蓝色
-
# 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 #设置颜色的阈值,LAB的三个最大值,三个最小值 # 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... thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds (30, 100, -64, -8, -32, 32), # generic_green_thresholds (0, 15, 0, 40, -80, -2)] # generic_blue_thresholds sensor.reset()#重置感光元件,重置摄像机 sensor.set_pixformat(sensor.RGB565)#重置颜色格式为RGB56 sensor.set_framesize(sensor.QVGA)#图像的大小是QVGA sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # 务必要关闭白平衡 sensor.set_auto_whitebal(False) # 务必要关闭自动增益 #因为打开会影响颜色识别的效果,会使颜色的阈值发生改变 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()#先截取感光元件的一张图片 #在img.find_blobs这个函数中,进行颜色识别 for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=200, area_threshold=200, merge=True): #此处没有设置roi的值,便是对整个图像进行颜色识别 # These values depend on the blob not being circular - otherwise they will be shaky. if blob.elongation() > 0.5: img.draw_edges(blob.min_corners(), color=(255,0,0)) img.draw_line(blob.major_axis_line(), color=(0,255,0)) img.draw_line(blob.minor_axis_line(), color=(0,0,255)) # These values are stable all the time. img.draw_rectangle(blob.rect()) #如果识别到了颜色,我们就在这个色块的周围画一个框把它圈出来 img.draw_cross(blob.cx(), blob.cy()) #中间画一个十字,(blob.cx(), blob.cy())是色块的中心坐标 # Note - the blob rotation is unique to 0-180 only. img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) #blob是find_blobs返回的参数 print(clock.fps())
请在这里粘贴代码
-
你的阈值是使用阈值助手测试的?