简体   繁体   English

在 Python 中找到二维码时如何破解?

[英]How can I break when found QR Code in Python?

I'm trying to learning QR Code module in Python and I'm trying to make some codes so I want to break when I found QR Code how can I do that?我正在尝试学习 Python 中的 QR 码模块,并且我正在尝试制作一些代码,所以当我找到 QR 码时我想打破我该怎么做?

My code is:我的代码是:

while 1:

    success, img= cap.read()
    for x in decode(img):
        data1 = x.data.decode('utf-8')
        pts = np.array([x.polygon],np.int32)
        pts = pts.reshape((-1,1,2))
        cv2.polylines(img,[pts],True,(122,25,245),(3))
        print(data1)
        
    cv2.imshow('Result',img)
    cv2.waitKey(10)

Use an if statement in the range loop, if there is something there, print that it has been detected在范围循环中使用 if 语句,如果那里有东西,打印它已被检测到

   while 1:
    
        success, img= cap.read()
        for x in decode(img):
            data1 = x.data.decode('utf-8')
            pts = np.array([x.polygon],np.int32)
            pts = pts.reshape((-1,1,2))
            cv2.polylines(img,[pts],True,(122,25,245),(3))
            print(data1)
            if data1 is not None:
                print("QR code detected")
                break

     cv2.imshow('Result',img)
     cv2.waitKey(10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM