2488| 6
|
[问题求助] 想写一个寻找黑色矩形程序出现了如下问题(已解决) |
from board import board_info from fpioa_manager import fm from machine import UART import KPU as kpu import sensor import image import lcd #创建 Uart fm.register(22, fm.fpioa.UART1_TX, force=True) fm.register(21, fm.fpioa.UART1_RX, force=True) uart1 = UART(UART.UART2, 115200, 8, 1, 0, timeout=1000, read_buf_len=4096) #摄像头初始化 def camera_init(): sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.run(1) #寻找最大色块 def find_max(blobs): max_size=0 max_blob=0 for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] return max_blob #寻找最大圆 def find_maxcircle(circles): max_radius=0 for radius in circles: if radius[2] > max_radius: max_radius = radius[2] return max_radius #初始化 lcd.init(freq=15000000, color=65535) camera_init() sensor.set_vflip(0) sensor.set_hmirror(0) green = (25, 61, -49, -14, -6, 36) black = (0 , 44, -12, 5 ,-11 ,12) while True: img = sensor.snapshot().lens_corr(1.8) lcd.display(img) #寻找绿色色块 #blobs = img.find_blobs([green]) #Max_blob = find_max(blobs) #if Max_blob!=0:#找到绿色色块 #tmp=img.draw_rectangle(Max_blob.rect(),color= (0,0,255),size = 80) #寻找最大圆形 #circles = img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10, #r_min = 3, r_max = 100, r_step = 2) #c_max = find_maxcircle(circles) #if c_max != 0:#找到最大圆 #c_max = img.find_blobs([black],roi = (c_max.x(),c_max.y(),2*c_max.r(),2*c_max.r())) #img.draw_circle(c_max.x(), c_max.y(), c_max.r(), color = (255, 0, 0),size = 80) #寻找停机点 black_blobs = img.find_blobs([black])#寻找黑色区域 max_black = find_max(black_blobs)#寻找最大黑色区域 max_rects = img.find_rects(max_black.rect(),threshold=10000)#寻找区域中的矩形 if max_rects != 0:#找到停机点 img.draw_rectangle(max_rects.rect(),color= (0,255,0),size=80) |
2.15 KB, 下载次数: 4019
max_rects = img.find_rects(max_black.rect(),threshold=10000)#寻找区域中的矩形 把这里的函数和变量全部拿出来调试 tmp = max_black.rect() max_rects = img.find_rects(tmp,threshold=10000)#寻找区域中的矩形 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed