Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 创建一个GUI,用Tkinter和OpenCV扫描二维码?_Python_Opencv_Tkinter_Qr Code - Fatal编程技术网

Python 创建一个GUI,用Tkinter和OpenCV扫描二维码?

Python 创建一个GUI,用Tkinter和OpenCV扫描二维码?,python,opencv,tkinter,qr-code,Python,Opencv,Tkinter,Qr Code,我想构建一个GUI,用Tkinter python扫描二维码,用一些按钮和列表框录制视频提要。我已经完成了OpenCV与Tkinter的合并。但是,我无法扫描任何二维码。我想我的问题来自于行barcodes=pyzbar.decode(frame),但我不知道它的错误是什么,因为程序仍然运行平稳。这是我的密码: from imutils.video import VideoStream from pyzbar import pyzbar from PIL import Image, ImageT

我想构建一个GUI,用Tkinter python扫描二维码,用一些按钮和列表框录制视频提要。我已经完成了OpenCV与Tkinter的合并。但是,我无法扫描任何二维码。我想我的问题来自于行
barcodes=pyzbar.decode(frame)
,但我不知道它的错误是什么,因为程序仍然运行平稳。这是我的密码:

from imutils.video import VideoStream
from pyzbar import pyzbar
from PIL import Image, ImageTk
from firebase_admin import credentials, firestore

import Tkinter as tki
import firebase_admin
import threading
import argparse
import datetime
import imutils
import time
import cv2
import RPi.GPIO as GPIO
import customer
from customer import Customerlist

    window = tki.Tk()  #Makes main window

    #Graphics window
    imageFrame = tki.Frame(window, width=600, height=500)
    imageFrame.grid(row=0, column=0, padx=10, pady=2)

    #Capture video frames
    lmain = tki.Label(imageFrame)
    lmain.grid(row=0, column=0)
    #gst = "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=6 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"
    cap = cv2.VideoCapture(0)

    def show_frame():
        ret, frame = cap.read()
        frame = cv2.flip(frame, 1)
        frame = imutils.resize(frame, width=400)
        cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        img = Image.fromarray(cv2image)
        imgtk = ImageTk.PhotoImage(image=img)
        lmain.imgtk = imgtk
        lmain.configure(image=imgtk)
        lmain.after(10, show_frame) 



    while True : 
                    show_frame()
                    barcodes = pyzbar.decode(frame) 
                    window.mainloop()  #Starts GUI

                    for barcode in barcodes:
                        (x, y, w, h) = barcode.rect
                        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
                        # the barcode data is a bytes object so if we want to draw it
                        # on our output image we need to convert it to a string first
                        barcodeData = barcode.data.decode("utf-8")
                        barcodeType = barcode.type  

                        # draw the barcode data and barcode type on the image
                        text = "{} ({})".format(barcodeData, barcodeType)
                        cv2.putText(frame, text, (x, y - 10),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)  
                cv2.imshow("Thesis", frame)
                key = cv2.waitKey(1) & 0xFF      

csv.close()
cap.release()
cv2.destroyAllWindows()
有人能帮我吗?我非常欣赏window.mainloop()是一个阻塞调用-它启动一个无限循环。因此,它下面处理帧的代码永远不会执行。
解决方案是将条形码处理代码放在一个单独的函数中,该函数从
show\u frame()
调用


大家好,欢迎来到stack overflow。请尝试修剪您的代码,并创建一个问题的解决方案