微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我正在使用PyQt5创建接口,但脚本会以退出代码-10737407910xC0000409停止

如何解决我正在使用PyQt5创建接口,但脚本会以退出代码-10737407910xC0000409停止

我的项目是识别打印在打印处方中的单词,并找出商店中可用的药丸并将其显示用户。我为此使用PyQt5,脚本结束且没有错误-“进程以退出代码-1073740791(0xC0000409)完成” 。我不知道是什么问题。请帮助我。

import cv2
import sys
import time
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication,QMainWindow,QMessageBox
from PyQt5.QtGui import QImage,Qpixmap
from PyQt5.uic import loadUi
import os
from PIL import Image
import PyTesseract
import pandas as pd


class dispensercode(QMainWindow):
    def __init__(self):
        self.name = 'delila'
        super(dispensercode,self).__init__()

        loadUi('gui1.ui',self)
        self.logic = 0
        self.capdone = 0
        self.count = 1
        self.x = 'm'
        self.Confirm.clicked.connect(self.Confirmed)
        self.Camon.clicked.connect(self.Camturn)
        self.Capture.clicked.connect(self.captureClicked)
       



    @pyqtSlot()

    def Confirmed(self):
        name = self.NameInput.toPlainText()
        self.new_name = name
        self.label2.setText('Patient name is ' + name)
        return self.new_name

    def Camturn(self):
        cap = cv2.VideoCapture(0)

        while (cap.isOpened()):

            ret,frame = cap.read()
            if ret == True:  # ret is if cam is working
                print('here')
                self.displayimage(frame,1)  # frame is the image
                cv2.waitKey()

                if (self.logic == 2):

                    cv2.imwrite('%s.png' % (self.new_name),frame)  # %s will be substituted by %(self.value)


                    self.capdone = 1
                    print('cap done is ',self.capdone)
                    # self.textbrowser1.setText('image saved pres cap for another image')
                    cap.release()
                    cv2.destroyAllWindows()

                    if (self.capdone == 1):
                        self.loadClicked()
                        self.ocr()
                        self.capdone = 0
#-------------------create verification pop up window-----------------------------------#
                        msg = QMessageBox()
                        msg.setwindowTitle('please verify whether the ocr is correct')
                        msg.setText(' Click "Accept" if true "Reject" if false')
                        msg.setIcon(QMessageBox.Question)
                        msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
                        msg.setinformativeText(self.text)
                        msg.buttonClicked.connect(self.popup_button)
                        x = msg.exec_()

                        print('this is before while is running')
                        if self.ver() == False:
                            print('this while is running')
                            if self.count <= 3:
                                self.count = self.count + 1
                                cap = cv2.VideoCapture(0)

                                while (cap.isOpened()):

                                    ret,frame = cap.read()
                                    if ret == True:  # ret is if cam is working
                                        print('here')
                                        self.displayimage(frame,1)  # frame is the image
                                        cv2.waitKey()

                                        if (self.logic == 2):

                                            cv2.imwrite('%s.png' % (self.new_name),frame)  # %s will be substituted by %(self.value)

                                            self.capdone = 1
                                            print('cap done is ',self.capdone)
                                            # self.textbrowser1.setText('image saved pres cap for another image')
                                            cap.release()
                                            cv2.destroyAllWindows()

                                            if (self.capdone == 1):
                                                self.loadClicked()
                                                self.ocr()
                                                self.capdone = 0
                                                # -------------------create verification pop up window-----------------------------------#
                                                msg = QMessageBox()
                                                msg.setwindowTitle('please verify whether the ocr is correct')
                                                msg.setText(' Click "Accept" if true "Reject" if false')
                                                msg.setIcon(QMessageBox.Question)
                                                msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
                                                msg.setinformativeText(self.text)
                                                msg.buttonClicked.connect(self.popup_button)
                                                x = msg.exec_()



                            elif self.count > 3:
                                self.label4.setText(
                                    'please type the correct words and save the file and close the txt file and press spacebar')

                                os.startfile('{}.txt'.format(self.new_name))
                                break
                        else :
                            print('readlist is running')
                            self.readlist()

                    self.logic = 1
                else:
                    print('return not found')


    def captureClicked(self):
        self.logic = 2

    def displayimage(self,img,window=1):
        qformat = QImage.Format_Indexed8

        if len(img.shape) == 3:
            if (img.shape[2]) == 4:
                qformat = QImage.Format_RGBA8888

            else:
                qformat = QImage.Format_RGB888
        img = QImage(img,img.shape[1],img.shape[0],qformat)  # Qimage is used to load the image
        img = img.rgbSwapped()
        self.label1.setpixmap(Qpixmap.fromImage(img))  # Qpixmap is used to show the image
        self.label1.setScaledContents(True)  # scale the image according th the frame
        self.label1.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)

    def loadClicked(self):
        img1 = cv2.imread("{}.png".format(self.new_name))
        self.displayimagef(img1,1)
        cv2.destroyAllWindows()

    def displayimagef(self,img1,window=1):
        qformat = QImage.Format_Indexed8

        if len(img1.shape) == 3:
            if (img1.shape[2]) == 4:
                qformat = QImage.Format_RGBA8888

            else:
                qformat = QImage.Format_RGB888
        img1 = QImage(img1,img1.shape[1],img1.shape[0],qformat)  # Qimage is used to load the image
        img1 = img1.rgbSwapped()
        self.label1.setpixmap(Qpixmap.fromImage(img1))  # Qpixmap is used to show the image
        self.label1.setScaledContents(True)  # scale the image according th the frame
        self.label1.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)

    def ocr(self):
        # load the example image and convert it to grayscale
        image = cv2.imread("{}.png".format(self.new_name))
        gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

        # write the grayscale image to disk as a temporary file so we can
        # apply OCR to it
        filename = "{}.png".format(os.getpid())
        cv2.imwrite(filename,gray)

        # load the image as a PIL/Pillow image,apply OCR,and then delete
        # the temporary file
        self.text = PyTesseract.image_to_string(Image.open(filename))
        os.remove(filename)
        self.label3.setText(self.text)
        print('converted to text')

        # export to .txt file
        # stdoutOrigin = sys.stdout
        with open("{}.txt".format(self.new_name),"w") as f:
            f.write(self.text)

    def popup_button(self,i):
        print(i.text())

        if i.text() == '&Yes':
            self.ver = True
            print(self.ver)
            return self.ver

        else:
            self.ver = False
            print(self.ver)
            return self.ver



    def readlist(self):
        with open("{}.txt".format(self.new_name)) as f1:
            os.startfile('{}.txt'.format(self.new_name))
            flat_list = [word for line in f1 for word in line.split()]
            print(flat_list)

        # ---------read the csv file of pills-------------------------------------------#
        df = pd.read_excel('items.xlsx',sheet_name=0)  # can also index sheet by name or fetch all sheets
        bin_no = df['BIN no'].tolist()
        Name = df['Name'].tolist()
        content = df['content'].tolist()

        print(bin_no)
        print(Name)
        print(content)

        # iterating through the list
        final_list = []
        i = 0
        for i in range(len(flat_list)):
            for j in range(len(Name)):
                if Name[j] == flat_list[i]:
                    if content[j] == flat_list[i + 1]:
                        final_list.append(bin_no[j])
                        final_list.append(Name[j])
                        final_list.append(content[j])
                        x = i
                        for k in range(x,len(flat_list)):
                            if 'Supply' == flat_list[k]:
                                print(flat_list[k + 1])
                                final_list.append(flat_list[k + 1])

                            else:
                                continue

                    else:
                        continue
                else:
                    continue

app =QApplication(sys.argv)
window = dispensercode()
window.show()
try:
    sys.exit(app.exec_())
except:
    print('exiting')

在这里显示的主要错误是“处理完成,退出代码-1073740791(0xC0000409)”

whatever i click on the pop up window the error shown below appears

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。