logo

为什么比较复杂的二维码无法识别成功,不是特别方正的二维码也无法识别成功,而且有时候扫描二维码是一片空白

2023-10-03 20:59
A
_2giq

先判断是二维码还是人物,是人的话则判断是否带口罩,是二维码的话输出二维码的内容

import sensor, image, time,image, os, tf, uos, gc
from pyb import UART
uart = UART(3, 9600)
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_auto_whitebal(True)
sensor.set_auto_gain(False)  # 必须关闭此功能,以防止图像冲洗…
sensor.set_windowing((240, 240))       # Set 240x240 window.
sensor.skip_frames(time=2000)          # Let the camera adjust.
net = None
labels = None
try:
    # load the model, alloc the model file on the heap if we have at least 64K free after loading
    net = tf.load("trained.tflite", load_to_fb=uos.stat('trained.tflite')[6] > (gc.mem_free() - (64*1024)))
except Exception as e:
    print(e)
    raise Exception('Failed to load "trained.tflite", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')')

try:
    labels = [line.rstrip('\n') for line in open("labels.txt")]
except Exception as e:
    raise Exception('Failed to load "labels.txt", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')')
# 加载Haar算子
# 默认情况下,这将使用所有阶段,更低的satges更快,但不太准确。
face_cascade = image.HaarCascade("frontalface", stages=25)
#image.HaarCascade(path, stages=Auto)加载一个haar模型。haar模型是二进制文件,
#这个模型如果是自定义的,则引号内为模型文件的路径;也可以使用内置的haar模型,
#比如“frontalface” 人脸模型或者“eye”人眼模型。
#stages值未传入时使用默认的stages。stages值设置的小一些可以加速匹配,但会降低准确率。
# FPS clock
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    img.lens_corr(1.8) # 1.8的强度参数对于2.8mm镜头来说是不错的。
    objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)
    QR_Code=img.find_qrcodes()
    if objects:
        for r in objects:
            img.draw_rectangle(r)
        for obj in net.classify(img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
            img.draw_rectangle(obj.rect())
            predictions_list = list(zip(labels, obj.output()))
            radio=predictions_list[1][1]*100
            print("%s = %.2f%%" % (predictions_list[1][0],radio ))
            radio=str(radio)
            uart.write('@'+radio+'\r\n')
    elif QR_Code:
        for code in QR_Code:
            img.draw_rectangle(code.rect(), color = (255, 0, 0))
            print(code.payload())
            uart.write('@'+code.payload()+'\r\n')
    #else:
        #print("-----------error------------")
bda08d46-0c6d-41c3-b3a6-7f0dd2fe1234.png
c9cdf390-2701-4eec-b3a6-3c256d3b0353.png
2023-10-03 21:38
A
_2giq

并且转换角度之后不能及时调整亮度,先照人的话再照平板就会很亮,这该怎么解决

2023-10-11 20:21
I
网红小智智 星瞳科技

先测试hello world能不能看清。

2023-10-11 20:51
A
_2giq

@kidswong999 用hello程序可以看清,也没有一片白的情况

2023-10-11 20:59
I
网红小智智 星瞳科技

那就把

sensor.set_contrast(3)

sensor.set_gainceiling(16)

sensor.set_auto_whitebal(True)

sensor.set_auto_gain(False)

这几行删掉。

2023-10-12 19:39
A
_2giq

@kidswong999 删除后人脸识别就有一点问题,有时候能识别到,有时候不能,但能识别到的次数很少,一片白的情况解决了,二维码识别很慢,这些问题怎么解决

2023-10-13 19:57
A
_2giq

@2giq 在 [为什么比较复杂的二维码无法识别成功,不是特别方正的二维码也无法识别成功,而且有时候扫描二维码是一片空白,这个该怎么解决](/post/30427) 中说:

> @kidswong999 删除后人脸识别就有一点问题,有时候能识别到,有时候不能,但能识别到的次数很少,一片白的情况解决了,二维码识别很慢,这些问题怎么解决

@kidswong999

2023-10-14 22:45
A
_2giq

@kidswong999 删除后人脸识别就有一点问题,有时候能识别到,有时候不能,但能识别到的次数很少,一片白的情况解决了,二维码识别很慢,这些问题怎么解决