我用OpenCV编写一个机器视觉小程序,在pycharm中可以运行,但用Pyinstaller 打包成EXE后,不能正常运行。
请教如何打包这样的程序!
我的环境是: PyInstaller: 4.5.1
Python: 3.7.2
windows-10-10.0.18362-SP0
OpenCv 4.2.0
用命令 pyinstaller -F mian.py 打包后,EXE运行,闪现错误代码后,黑窗口关闭。
我的代码如下:
import cv2
from cvzone.HandTrackingModule import HandDetector
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
detector = HandDetector(maxHands=1, detectionCon=0.8)
while True:
success, img = cap.read()
img = cv2.flip(img, 1)
hands, img = detector.findHands(img, flipType=False)
print(hands)
if hands:
hand = hands[0]
lmList = hand['lmList']
pointIndex = lmList[8][0:2]
cv2.circle(img, tuple(pointIndex), 15, (255, 0, 0), cv2.FILLED)
cv2.imshow('img', img)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()
一下是运行后的信息:
Traceback (most recent call last):
File "main.py", line 7, in
File "cvzone\HandTrackingModule.py", line 35, in init
File "mediapipe\python\solutions\hands.py", line 129, in init
File "mediapipe\python\solution_base.py", line 265, in init
FileNotFoundError: The path does not exist.
[5496] Failed to execute script 'main' due to unhandled exception!
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback
出现以上信息后黑窗口闪退
程序在pycharm中运行正常
曾也想用Nuitka打包,但未成功。希望有能够指点一下,不胜感谢!本人刚刚涉足机器视觉领域,不是很熟练,见笑了!