Webcam crashes with opencv and exit code is -1073740791
every time I run the program it the webcam crashes and stops working, it works for maybe 2 seconds and then crashes with exit code -1073740791
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
cap.set(3, 640)
cap.set(4, 480)
classNames = []
classFile = 'coco.names'
with open(classFile, 'rt') as f:
classNames = f.read().rstrip('\n').split('\n')
configPath = 'ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightPath = 'frozen_inference_graph.pb'
net = cv2.dnn_DetectionModel(weightPath, configPath)
net.setInputSize(320, 320)
net.setInputScale(1.0 / 127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
while True:
success, img = cap.read()
classIds, conf, bbox = net.detect(img, confThreshold=0.60)
if len(classIds) != 0:
for classId, conf, box in zip(classIds.flatten(), conf.flatten(), bbox.flatten()):
cv2.rectangle(img, bbox, (0, 255, 0), 3)
print(classId)
cv2.putText(img, classNames[classId - 1].upper(), (bbox[0][0] + 10, bbox[0][1] + 30),
cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
cv2.imshow("Result", img)
cv2.waitKey(1)
Please sign in to leave a comment.
Hi, does the issue reproduce if you run it from the terminal outside of IDE?
I don't know how to run it from the terminal, but I ran it on another laptop from Pycharm and got the same problem. But when I run the simple program to read the webcam and show it there is no error, the error comes only when I'm using object detection code. really don't know why
It would help if we could determine if this is IDE-related bug or not. To do this, please try running your code from the terminal outside of IDE using the same interpreter, and check if you get the same issue.
One way to do that is to copy the first line of the console output from PyCharm to the terminal.
For more information on how to run code from the terminal, please see:
https://docs.python.org/3/using/cmdline.html#command-line
If you're using virtualenv interpreter in PyCharm, you may need to activate it in the command line as well:
https://virtualenv.pypa.io/en/latest/user_guide.html#activators