国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Python用opencv實(shí)現(xiàn)動態(tài)識別二維碼,以及加強(qiáng)版Python GUI(圖像用戶界面編程)

這篇具有很好參考價值的文章主要介紹了Python用opencv實(shí)現(xiàn)動態(tài)識別二維碼,以及加強(qiáng)版Python GUI(圖像用戶界面編程)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

?前言

? ? ? ? 關(guān)于動態(tài)識別二維碼信息,利用電腦攝像頭動態(tài)掃描二維碼,掃描視頻中的二維碼。


簡易程序

import cv2  pip install opencv-python


def start():
    capture = cv2.VideoCapture(0)
    while True:

        fet, frame = capture.read()
        qrCodeDetector = cv2.QRCodeDetector()
        data, bbox, straight_qrcode = qrCodeDetector.detectAndDecode(frame)
        
        print(data) # data即讀取到的數(shù)據(jù)

        cv2.namedWindow('read-QR', 0)
        cv2.imshow("read-QR", frame)
        k = cv2.waitKey(1)  # 保持畫面的持續(xù)。
        if k == 27:  # 通過esc鍵退出攝像
            break

start()

加強(qiáng)版Python GUI(圖像用戶界面編程)

????????由于我在項(xiàng)目中設(shè)計(jì)了一個PC端執(zhí)行軟件,所以用到了GUI編程,即圖像用戶界面編程,所以把關(guān)于這部分的GUI編程取了出來寫在了下面。實(shí)際上用上面這個程序已經(jīng)可以識別二維碼了,下面這個程序是將程序由基于控制臺來控制執(zhí)行變成了圖形用戶界面來控制。將這個程序打包成軟件可以用pip install auto-py-to-exe,這個庫就是一個圖像用戶界面的程序,相比別的方式用起來比較友好,具體可以網(wǎng)上搜索學(xué)習(xí)。

import cv2
import tkinter
from tkinter import *
from PIL import Image, ImageTk
from tkinter import messagebox
import numpy as np

capture = cv2.VideoCapture(0)

root = tkinter.Tk()
root.title("read-QR")
root.geometry('900x600')
img_width = 800
img_height = 600 - 20
canvas = Canvas(root, bg='white', width=img_width, height=img_height)
canvas.place(x=0, y=0)


def on_closing():
    if messagebox.askokcancel("Quit", "Do you want to quit?"):
        root.destroy()
        capture.release()


def start():
    while True:

        fet, frame = capture.read()
        qrCodeDetector = cv2.QRCodeDetector()
        data, points, straight_qrcode = qrCodeDetector.detectAndDecode(frame)
        if data:
            cv2.drawContours(frame, [np.int32(points)], 0, (0, 255, 0), 2)  # 框出二維碼位置

            print(data)

            tkinter.Label(root, text="姓名:" + data).place(x=900 - 100, y=0, width=100, height=20)

        tk_img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        tk_img = Image.fromarray(tk_img)
        tk_img = tk_img.resize((img_width, img_height), Image.ANTIALIAS)
        tk_img = ImageTk.PhotoImage(image=tk_img)
        canvas.create_image(0, 0, anchor='nw', image=tk_img)
        root.update()
        root.after(1)


btnStart = tkinter.Button(root, text='開始', command=start)
btnStart.place(x=0, y=600 - 20, width=70, height=20)

root.protocol('WM_DELETE_WINDOW', on_closing)
root.mainloop()

關(guān)于如何制作二維碼可看我同專欄的另一邊篇文章,鏈接如下。

Python用qrcode和PIL制作二維碼并添加漢字(用Python在圖片上添加漢字)_"殤影的博客-CSDN博客python制作二維碼,python批量制作二維碼,python批量制作帶漢字的二維碼,在圖片上添加漢字,用Python在圖片上添加漢字https://blog.csdn.net/weixin_45694843/article/details/128046585?spm=1001.2014.3001.5502文章來源地址http://www.zghlxwxcb.cn/news/detail-550945.html

到了這里,關(guān)于Python用opencv實(shí)現(xiàn)動態(tài)識別二維碼,以及加強(qiáng)版Python GUI(圖像用戶界面編程)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包