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("合格")
我没有看懂你的目的,这个是在工厂使用的吗?光源固定吗?摄像头的位置固定吗?零件的位置固定吗?黑斑的形状固定吗?
@zbyf 中间是镂空的吧,在中间下方放一个白色板