Webcam capture does not show when the data is read
I tried video_capture= cv2.VideoCapture()
method for both, 0 and 700 as argument, because of suggestions and this happened:
video_capture = cv2.VideoCapture(700)
works only when I debug and breakpoint at cv2.imshow("Capturing", gray). Screen shows a snapshot of a webcam video, however runtime shows the following image;=======
import cv2
# Create an object. 700 for my external camera
video_capture = cv2.VideoCapture(700)
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH,640)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
while True:
ret, frame = video_capture.read()
#Check if the video is being read
if ret == False:
print("Connection Failed!")
else:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(gray, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
cv2.imshow('Video', gray)
if cv2.waitKey(1)==ord('e'):
break
video_capture.release()
cv2.destroyAllWindows()
Kaspersky seemed to block my live webcam capture on terminal running code so on pycharm I have enabled, Run with Python Console. Everything is working fine now. Pycharm Console Config