如何把二维码识别和颜色形状识别放在一个程序里
-
import sensor, image, time from pyb import UART import json black_threshold = (0, 20, -18, 127, -8, 22) #black green_threshold = (0, 70, -128, -28, 22, 127) #green red_threshold = (0, 50, -128, 127, 12, 127) #red 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() uart = UART(3, 115200) def find_max(blobs): max_size=0 for blob in blobs: if blob.pixels() > max_size: max_blob=blob max_size = blob.pixels() return max_blob while(True): clock.tick() img = sensor.snapshot() img.lens_corr(1.8) # 1.8的强度参数对于2.8mm镜头来说是不错的。 for code in img.find_qrcodes(): img.draw_rectangle(code.rect(), color = (255, 0, 0)) print(code) output_str="%d,%d,%d,%d" % (code.x(), code.y(),code.w(),code.h()) #output_str1=json.dumps(code.payload()) uart.write(output_str+'\r\n') 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): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) output_str="[%d,%d,%d]" % (c.x(),c.y(),c.r()) print(output_str) uart.write(output_str+'\r\n') statistics=img.get_statistics(roi = (c.r(), c.r(), 2 * c.r(), 2 * c.r())) blobs = img.find_blobs([red_threshold,green_threshold,black_threshold],roi=(c.r(), c.r(), 2 * c.r(), 2 * c.r())) if blobs: max_blob = find_max(blobs) img.draw_rectangle(max_blob[0:4]) # rect img.draw_cross(max_blob[5], max_blob[6]) # cx, cy else: pass for r in img.find_rects(threshold = 10000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) output_str="[%d,%d,%d,%d]" % (r.x(),r.y(),r.w(),r.h()) print(output_str) uart.write(output_str+'\r\n') area = r.rect() blobs = img.find_blobs([red_threshold,green_threshold,black_threshold],roi=area) if blobs: max_blob = find_max(blobs) img.draw_rectangle(max_blob[0:4]) # rect img.draw_cross(max_blob[5], max_blob[6]) # cx, cy else: pass
-
https://singtown.com/learn/50029/
看这个视频了吗?
-
您帮忙看看我的程序有没有问题,程序进行循环后就只识别形状和颜色,不识别二维码了怎么解决这个问题,求指导
-
我运行你的代码,是可以找到二维码的。
-
@kidswong999 意思是我的程序没问题?我识别二维码就不出二维码的网站
-
@kidswong999 如何识别矩形圆形面积,我识别圆形有时候会打印矩形,怎么更改一下。
-
-
-
@kidswong999 我只是把注释了
-
@na3m 所以没有打印payload,只打印了位置。预期和我的测试结果一致。