About cmd Prompt in windows

While working with webcam using open CV after using cv2.destroyAllWindows(), all the windows are getting closed but cannot use cmd prompt after that! Has to close and reopen every time! Any idea why it’s happening or any solution to this?

It stays like this forever and have to close terminal and reopen and move to the folder again
PS : even the Ctrl + C doesn’t work

hey @chethan.vjc ,
can you please share your code once.
It shouldn’t be as such , i guess there is something still running in your script after you have destroyed all the windows also.
So i need to have a look on it , so would be needing your code.

Thank You and Happy Learning :slightly_smiling_face:.

import cv2

cap = cv2.VideoCapture(0)

face_cascade = cv2.CascadeClassifier(“haarcascade_frontalface_alt.xml”)

while True:
ret, frame = cap.read()
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

if ret==False:
	continue

faces = face_cascade.detectMultiScale(frame,1.3,5)

for (x,y,w,h) in faces:
	cv2.rectangle(frame, (x,y), (x+w,y+h),(255,0,0),2)

cv2.imshow("Video Frame", frame)

key_pressed = cv2.waitKey(1) & 0xFF
if key_pressed == ord('q'):
	break

cap.release()
cv2.destroyAllWindows()

Since the formatting looks messy as i copy pasted the code, here’s a image too

on what python and cv2 version are you working on ?

Python 3.9.0 and cv2 4.4.0

can you please try like this .

import sys
sys.exit()
cap.release()

in the end and comment the destroyallwindows command.

This works but the webcam freezes and have to force stop it every time!!

then just try like this ,

cap.release()
import sys
sys.exit()

I hope this works.

Nope : ( still the same tried both ways:

import sys
sys.exit()
cap.release()

and this:

cap.release()
import sys
sys.exit()

while your code is running , focus your cmd prompt and press ctrl + C multiple times.

Try this

Says keyboard interrupt but the script still running though!

kindly do it like 9-10 times , either it should show multiple keyBoard Interrupts , or should stop its funcitoning

did more than 30 times still the same

i am too receiving this
``anonymous-namespace’::SourceReaderCB::~SourceReaderCB terminating async callback`

But it does stops my code also.
Kindly try once again , with the actual code . Its working perfectly.

I am working on python 3.6.
this might be the problem with python 3.9 as it is the latest version , currently there might be many libraries that are not compatible with this version.

should I downgrade to python 3.6? coz it isn’t working in 3.9 however many times try!

Yeah please , It would be much better to work .
And python 3.6 is also very stable ,almost all libraries work well on it.

That didn’t work too! also I noticed when I just read the image and do imshow() it works fine, but when I use this line:
faces = face_cascade.detectMultiScale(frame,1.3,5)
there seems to be a problem

what problem ? can you please share me the screenshot
It shouldn’t be any problem . I am also working on the same configuration.