0

How to coding to fix Fatal error detected : Failed to execute script BoxDetection after use auto-py-to-exe compile python code to exe file?

I learn to compile python code to exe file with vdo link https://www.youtube.com/watch?v=ZtBTrARHJps&list=WL&index=3&t=156s .

I have problem to after use auto-py-to-exe compile python code to exe file and have popup error after program finished working.

Fatal error detected
Failed to execute script BoxDetection

Have popup error with picture link - https://i.stack.imgur.com/eNRma.jpg to ask how to coding to fix popup error to Failed to execute script BoxDetection problem.

Sample Code.

  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 with download link.

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

  1. Sample VDO box2.mp4 with link - https://doanga2007.github.io/box2.mp4

  2. BoxDetection.exe 64 bit use auto-py-to-exe compile python code to exe file with download link.

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

If open BoxDetection.exe and select sample VDO box2.mp4 , Have popup error after program finished working with picture link.

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

  1. boxdetectionerrorlog+debug.txt with download link.

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

  1. Python Shell to describe error log after Run Module.
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
>>>
  • 1
    The error is because, something does not exist? something related to `frame` maybe? i guess its the problem with video file? are you sure the path to it is correct? Try saying `print(filename)` and verify that too. Pretty sure `askopenfilename()` takes some arguements onn` – Delrius Euphoria Aug 15 '20 at 12:45
  • @CoolCloud Thanks you to introduce , I found answer to fix Fatal error detected : Failed to execute script BoxDetection after use auto-py-to-exe compile python code to exe file. – Sumate Mephokkij Aug 15 '20 at 14:05
  • thne you can actually add it here and mark it as the answer – Delrius Euphoria Aug 15 '20 at 14:28
  • @CoolCloud I answer to fix Fatal Error tomorrow. – Sumate Mephokkij Aug 15 '20 at 14:47
  • @CoolCloud I answer to fix Fatal Error complete at link - https://stackoverflow.com/a/63433819/10863080 ( Key answer to fix Fatal Error of `cv2.waitKey(300000)` ) – Sumate Mephokkij Aug 16 '20 at 06:33

1 Answers1

1

Good news : I have answer to fix Fatal error detected : Failed to execute script BoxDetection after use auto-py-to-exe compile python code to exe file with my full source code.

I have answer credit with link1 , link2 , link3 and link4.

  1. Install pyinstaller / auto-py-to-exe / win32com with command :
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
pip install auto-py-to-exe
pip install pywin32
  1. Coding with sample.

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()

and VDO box2.mp4 example file with link - https://doanga2007.github.io/box2.mp4

  1. Open cmd and use auto-py-to-exe command to open auto-py-to-exe program , Open python file and press compile button to compile python file to exe file instantly.

  2. Have BoxDetection.exe with link - https://drive.google.com/file/d/1tnnnDWRrg1NbPZ3hr9mhY-t_4zry21rB/view?usp=sharing