logo

我在一个圆环形零件上画了几个黑斑,零件中间有个孔,拍起来是个圆形黑色色块,怎么让他只检测圆环上的黑色色块并框起来?

2023-05-02 23:01
9
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)
2023-05-02 23:08
9
zbyf
1deefcb5-ae49-4131-a3fd-9df617f9a835.png
2023-05-04 20:00
I
网红小智智 星瞳科技

我没有看懂你的目的,这个是在工厂使用的吗?光源固定吗?摄像头的位置固定吗?零件的位置固定吗?黑斑的形状固定吗?

2023-05-05 07:14
4
山东

@zbyf 中间是镂空的吧,在中间下方放一个白色板