Z
zbyf 发布的帖子
-
我在一个圆环形零件上画了几个黑斑,零件中间有个孔,拍起来是个圆形黑色色块,怎么让他只检测圆环上的黑色色块并框起来?
import time, sensor, image,math,pyb thresholds = (65, 9) thresholdss = (0, 80) from image import SEARCH_EX, SEARCH_DS sensor.reset() sensor.set_contrast(1) sensor.set_gainceiling(16) sensor.set_framesize(sensor.QQVGA) sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) sensor.skip_frames(time = 2000) template = image.Image("/fhy1.pgm") clock = time.clock() while (True): #for i in range(100): clock.tick() img = sensor.snapshot().lens_corr(1.8) #畸变矫正 #img.binary([thresholdss], invert = 1) #二值化 零件 = img.find_template(template, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60)) for r in img.find_blobs([thresholds], roi=[40,20,70,70],pixels_threshold=15, area_threshold=15, merge=False): #if r.pixels() >100 and r.pixels() <300: img.draw_rectangle(r.rect()) if 零件: img.draw_rectangle(零件) print("检测到零件") if r: print("不合格") else: print("合格")![0_1683039656447_零件.png](https://fcdn.singtown.com/0f1cf444-87a0-4b03-a642-a490a84e7983.png)