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



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

我学会了用vdo链接将python代码编译为exe文件https://www.youtube.com/watch?v=ZtBTrARHJps&list=WL&index=3&t=156秒。

我有问题后使用auto-py-exe编译python代码到exe文件,并在程序完成后弹出错误。

Fatal error detected
Failed to execute script BoxDetection

图片链接出现弹出错误-https://i.stack.imgur.com/eNRma.jpg询问如何编码以修复弹出错误到无法执行脚本BoxDetection问题。

示例代码

  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<622 :
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(1) & 0xFF==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
  1. boxdetectionerrorlog.txt,带有下载链接

https://doanga2007.github.io/boxdetectionerrorlog.txt

  1. 带链接的VDObox2.mp4样本https://doanga2007.github.io/box2.mp4

  2. BoxDetection.exe64位使用auto-py-exe将python代码编译为带有下载链接的exe文件。

https://drive.google.com/file/d/1tnnnDWRrg1NbPZ3hr9mhY-t_4zry21rB/view?usp=sharing

如果打开BoxDetection.exe并选择示例VDO box2.mp4,则在程序完成图片链接后出现弹出错误。

https://i.stack.imgur.com/ZYR69.jpg

  1. boxdetectionerrorlog+debug.txt,带有下载链接

https://doanga2007.github.io/boxdetectionerrorlog+debug.txt

  1. Python Shell描述运行模块后的错误日志
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:UserstumDesktopโปรแกรม BoxDetection แบบ EXEBoxDetection.py ==
Traceback (most recent call last):
File "C:UserstumDesktopโปรแกรม BoxDetection แบบ EXEBoxDetection.py", line 13, in <module>
roi=frame[:1080,0:1920]
TypeError: 'NoneType' object is not subscriptable
>>>

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

我有链接1、链接2、链接3和链接4的答案信用。

  1. 使用以下命令将pyinstaller/auto-py安装到exe/win32com:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
pip install auto-py-to-exe
pip install pywin32
  1. 使用示例进行编码

2.1BoxDetection.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()

和VDObox2.mp4示例文件,链接-https://doanga2007.github.io/box2.mp4

  1. 打开cmd并使用auto-py-to-exe命令打开auto-py-to-exe程序,打开python文件并按下编译按钮即可立即将python文件编译为exe文件。

  2. 具有带链接的BoxDetection.exehttps://drive.google.com/file/d/1tnnnDWRrg1NbPZ3hr9mhY-t_4zry21rB/view?usp=sharing

最新更新