学MaixPy之机器视觉,在MaixPy IDE开发环境,用Maix Dock K210开发板,实现动态识别色块,包括红、蓝、绿、黄四个色。
red_threshold = (60, 68, 50, 62, 28, 42) #(55, 70, 42, 65, 52, 8)green_threshold= (85, 95, -80, -49, 55, 70) #(0, 88, -42, -6, -9, 13)blue_threshold = (79, 85, -24, -11, -27, -15) #(0, 80, -128, 35, -128, -18)yellow_threshold =(69, 80, 5, 21, 55, 73) # (88, 95, 0, -44, 93, 48)printfinish_Y = 0printfinish_R = 0printfinish_G = 0printfinish_B = 0while True: img=sensor.snapshot() #使用摄像头拍摄一张照片 blobs_R = img.find_blobs([red_threshold]) blobs_G = img.find_blobs([green_threshold]) blobs_B = img.find_blobs([blue_threshold]) blobs_Y = img.find_blobs([yellow_threshold]) if blobs_R: img.draw_string(60, 100, "color is : Red!", scale=2) if printfinish_R == 0: print("color is : Red!") print("blobs: ",blobs_R) printfinish_R = 1 led_r.value(0) for b in blobs_R: tmp=img.draw_rectangle(b[0:4],225) tmp=img.draw_cross(b[5], b[6]) c=img.get_pixel(b[5], b[6]) else: led_r.value(1) printfinish_R = 0
评论