I hate it when a posted python example will not compile and I have no idea how to fix the problem. I have captured an example posted below. It works normally, compiles, but then will not run without errors. Any help here?
The example merely puts a webcam on my screen. This works when I use "python webcam.py" but it takes a while to start. It will compile but when run I get the errors below.
I used " pyinstaller --onefile webcam.py" to compile
Example:
import cv2
cap = cv2.VideoCapture(1)
# change 1 to 0 for the other we cam above
# Check if the webcam is opened correctly
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=1.5, fy=1.5, interpolation=cv2.INTER_AREA)
cv2.imshow('Input', frame)
c = cv2.waitKey(1)
if c == 27:
#27 is the esc key
break
cap.release()
ccv2.destroyAllWindows()
Errors when run:
C:\Users\hamil\dist>webcam.exe
Traceback (most recent call last):
File "webcam.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "cv2\__init__.py", line 188, in <module>
File "cv2\__init__.py", line 118, in bootstrap
File "cv2\__init__.py", line 116, in load_first_config
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
[8488] Failed to execute script 'webcam' due to unhandled exception!
The example merely puts a webcam on my screen. This works when I use "python webcam.py" but it takes a while to start. It will compile but when run I get the errors below.
I used " pyinstaller --onefile webcam.py" to compile
Example:
import cv2
cap = cv2.VideoCapture(1)
# change 1 to 0 for the other we cam above
# Check if the webcam is opened correctly
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=1.5, fy=1.5, interpolation=cv2.INTER_AREA)
cv2.imshow('Input', frame)
c = cv2.waitKey(1)
if c == 27:
#27 is the esc key
break
cap.release()
ccv2.destroyAllWindows()
Errors when run:
C:\Users\hamil\dist>webcam.exe
Traceback (most recent call last):
File "webcam.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "cv2\__init__.py", line 188, in <module>
File "cv2\__init__.py", line 118, in bootstrap
File "cv2\__init__.py", line 116, in load_first_config
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
[8488] Failed to execute script 'webcam' due to unhandled exception!