Please explain the code , the video in the course didnt explain anything at all
import cv2
cap= cv2.VideoCapture(0)
while True:
ret,frame= cap.read()
if ret==False:
continue
cv2.imshow("VideoFrame", frame)
key_pressed=cv2.waitKey(1) & 0xFF
if key_pressed == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
what are ret and frame? are they both variables and have the same value? or is like the videocapture() function returns 2 values and ret takes the value True or False meaning that the VideoCapture() function was able to use the webcam or not and frame takes all the images streamed
how does the program stop working please explain briefly what is happening there?
key pressed takes some 8 bit value from the waitkey() function and if that value matches a certain keyword it would stop but the program works for every letter that we use in place of q due to which i am unable to understand its working
what are cap.release() and destroyallwindows()? this program works without them aswell so whats their use?
`https://online.codingblocks.com/app/player/209779/content/201831/1380/lecture`
Video stream from webcam using open cv code
correct on this.
your code is working based on the input that it is getting from the camera, so say if camera is not working it will not work.
then next is , to stop it. You can always stop its running from the cmd by directly closing it and it will work. but here what we do is , whenever you press q button on keyboard it stops. It actually gets an hex value , and we convert that to ascii to match it , and hence when matched it stops.
if we explicitly close our code , there is a chance that your camera get stucked and doesn’t work next time , just to handle we work in this way.
I hope this helps.
Thank you, it was helpful all my doubts have been cleared
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.