Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
如何编码以修复检测到的致命错误:在使用auto py to exe将python代码编译为exe文件后,无法执行脚本BoxDetection?_Python_Python 3.x_Opencv_Pyinstaller_Detection - Fatal编程技术网

如何编码以修复检测到的致命错误:在使用auto py to exe将python代码编译为exe文件后,无法执行脚本BoxDetection?

如何编码以修复检测到的致命错误:在使用auto py to exe将python代码编译为exe文件后,无法执行脚本BoxDetection?,python,python-3.x,opencv,pyinstaller,detection,Python,Python 3.x,Opencv,Pyinstaller,Detection,如何编码以修复检测到的致命错误:在使用auto py to exe将python代码编译为exe文件后,无法执行脚本BoxDetection 我学习用vdo链接将python代码编译成exe文件 我有问题后,使用自动py的exe编译python代码到exe文件,并有弹出错误后,程序完成工作 Fatal error detected Failed to execute script BoxDetection 图片链接出现弹出错误-询问如何编码以将弹出错误修复为无法执行脚本BoxDetection

如何编码以修复检测到的致命错误:在使用auto py to exe将python代码编译为exe文件后,无法执行脚本BoxDetection

我学习用vdo链接将python代码编译成exe文件

我有问题后,使用自动py的exe编译python代码到exe文件,并有弹出错误后,程序完成工作

Fatal error detected
Failed to execute script BoxDetection
图片链接出现弹出错误-询问如何编码以将弹出错误修复为无法执行脚本BoxDetection问题

示例代码。

  • BoxDetection.py

  • 好消息:我找到了修复检测到的致命错误的答案:在使用auto-py to-exe将python代码编译为带有完整源代码的exe文件后,无法执行script BoxDetection

    我的答案是、、和

  • 使用以下命令将pyinstaller/auto-py安装到exe/win32com:
  • 使用示例进行编码
  • 2.1
    BoxDetection.py

    import cv2
    import numpy as np
    
    from tkinter import Tk
    from tkinter.filedialog import askopenfilename
    
    Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
    filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
    cap=cv2.VideoCapture(filename) # Compatible with box2 mp4 video file
    
    while(cap.read()) :
         ref,frame = cap.read()
         roi=frame[:1080,0:1920]
    
         gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
         gray_blur=cv2.GaussianBlur(gray,(25,25),0)
         thresh=cv2.adaptiveThreshold(gray_blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,21,4)
         kernel=np.ones((3,3),np.uint8)
         closing=cv2.morphologyEx(thresh,cv2.MORPH_CLOSE,kernel,iterations=4)
    
         result_img=closing.copy()
         contours,hierachy=cv2.findContours(result_img,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
         counter=0
         for cnt in contours:
             area = cv2.contourArea(cnt)
             if area<800 :
                 continue
             # ellipse = cv2.fitEllipse(cnt)
             # cv2.ellipse(roi,ellipse,(0,255,0),2)
             counter+=1
    
         cv2.putText(roi,str(counter),(10,100),cv2.FONT_HERSHEY_SIMPLEX,4,(0,0,255),4,cv2.LINE_AA)
         cv2.imshow("Show",roi)
    
         if cv2.waitKey(300000) & 0xFF==ord('q'):
             break
    
    cap.release()
    cv2.destroyAllWindows()
    
    导入cv2
    将numpy作为np导入
    从tkinter导入Tk
    从tkinter.filedialog导入askopenfilename
    Tk().draw()#我们不想要一个完整的GUI,所以不要出现根窗口
    filename=askopenfilename()#显示“打开”对话框并返回所选文件的路径
    cap=cv2.VideoCapture(文件名)#与box2 mp4视频文件兼容
    while(cap.read()):
    ref,frame=cap.read()
    roi=帧[:1080,0:1920]
    灰色=cv2.CVT颜色(边框,cv2.COLOR\u BGR2GRAY)
    灰色模糊=cv2.高斯模糊(灰色,(25,25),0)
    thresh=cv2.自适应阈值(灰度模糊,255,cv2.自适应阈值高斯,cv2.阈值二进制,21,4)
    内核=np.ones((3,3),np.uint8)
    closing=cv2.morphologyEx(thresh,cv2.MORPH\u CLOSE,kernel,迭代次数=4)
    结果\u img=closing.copy()
    等高线,层次=cv2.查找到的等高线(结果\u img,cv2.翻新\u外部,cv2.链\u近似\u简单)
    计数器=0
    对于轮廓中的cnt:
    面积=cv2。轮廓面积(cnt)
    
    如果错误是因为某个东西不存在?可能是与框架相关的东西?我想这是视频文件的问题吧?您确定指向它的路径正确吗?试着说
    print(filename)
    ,并验证一下。非常肯定,
    askopenfilename()
    接受了关于n`@CoolCloud的一些讨论,谢谢你的介绍,我找到了修复检测到的致命错误的答案:在使用auto-py将python代码编译为exe文件后,无法执行脚本BoxDetection。thne您可以实际将其添加到此处并将其标记为answer@CoolCloud我回答明天修复致命错误。@CoolCloud我回答修复致命错误在链接处完成-(修复cv2.waitKey(300000)
    致命错误的关键答案)感谢您与SO:D分享您的发现
    Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license()" for more information.
    >>> 
    == RESTART: C:\Users\tum\Desktop\โปรแกรม BoxDetection แบบ EXE\BoxDetection.py ==
    Traceback (most recent call last):
      File "C:\Users\tum\Desktop\โปรแกรม BoxDetection แบบ EXE\BoxDetection.py", line 13, in <module>
        roi=frame[:1080,0:1920]
    TypeError: 'NoneType' object is not subscriptable
    >>>
    
    pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
    pip install auto-py-to-exe
    pip install pywin32
    
    import cv2
    import numpy as np
    
    from tkinter import Tk
    from tkinter.filedialog import askopenfilename
    
    Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
    filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
    cap=cv2.VideoCapture(filename) # Compatible with box2 mp4 video file
    
    while(cap.read()) :
         ref,frame = cap.read()
         roi=frame[:1080,0:1920]
    
         gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
         gray_blur=cv2.GaussianBlur(gray,(25,25),0)
         thresh=cv2.adaptiveThreshold(gray_blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,21,4)
         kernel=np.ones((3,3),np.uint8)
         closing=cv2.morphologyEx(thresh,cv2.MORPH_CLOSE,kernel,iterations=4)
    
         result_img=closing.copy()
         contours,hierachy=cv2.findContours(result_img,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
         counter=0
         for cnt in contours:
             area = cv2.contourArea(cnt)
             if area<800 :
                 continue
             # ellipse = cv2.fitEllipse(cnt)
             # cv2.ellipse(roi,ellipse,(0,255,0),2)
             counter+=1
    
         cv2.putText(roi,str(counter),(10,100),cv2.FONT_HERSHEY_SIMPLEX,4,(0,0,255),4,cv2.LINE_AA)
         cv2.imshow("Show",roi)
    
         if cv2.waitKey(300000) & 0xFF==ord('q'):
             break
    
    cap.release()
    cv2.destroyAllWindows()