哦哦哦哦 发现了 十分感谢
1
18046170571 发布的帖子
-
数据类型有点不懂要怎么
就中间的那段取方差的最大值这一块,数据类型有点不知道要怎么转,好像是做运算要变成float,然后阈值又要是int,但是我强制类型转换了也还是不行,有点懵
import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.VGA) sensor.set_windowing((240, 240)) # look at center 240x240 pixels of the VGA resolution. sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must turn this off to prevent image washout... clock = time.clock() sum = 0 max = 0 while(True): clock.tick() img = sensor.snapshot() #得到图像 for i in range(40, 180, 3): for x in range(0, 640, 10): for y in range(0, 480, 10): color = img.get_pixel(x, y) #获取图像二值化的像素值 value = abs(color - i) square = pow (value ,2) sum += square #计算取到什么阈值时方差值相差最大 if(sum > max): max = sum #保留最大方差 j = i #保留阈值 img.median(1, percentile=0.5) #中值滤波 img.laplacian(1, sharpen=True) #锐化图像 high_threshold = (j, 255) #二维码阈值 img.binary([high_threshold]) #二值化 print(j) #打印阈值 for code in img.find_qrcodes(): #识别二维码 img.draw_rectangle(code.rect(), color = 127) print(code) #打印数据 print(clock.fps())