Issue
I am working on a python program that reads license plates from trucks. An image that gets processed by this program and filters the characters as output. Here is the input of the image in the program:
img = cv2.imread('image.jpg') #variable 'img' gets processed later using ocr
Now, is there a way I can make a webcam for instance: take an image, store it somewhere, and run the program with the taken image?
Using Python 3.7.2
Solution
You can capture a single frame by using the VideoCapture method of OpenCV.
import cv2
pic = cv2.VideoCapture(0) # video capture source camera (Here webcam of laptop)
ret,frame = pic.read() # return a single frame in variable `frame`
while(True):
cv2.imshow('img1',frame) #display the captured image
if cv2.waitKey(1) & 0xFF == ord('y'): #save on pressing 'y'
cv2.imwrite('images/c1.png',frame)
cv2.destroyAllWindows()
break
pic.release()
Answered By - anirudh