To write a python program using OpenCV to capture the image from the web camera and do the following image manipulations.
- Write the frame as JPG
- Display the video
- Display the video by resizing the window
- Rotate and display the video
Anaconda - Python 3.7
Import cv2 and capture the video using cv2.VideoCapture(0)
Write the captured image using cv2.imwrite("NewPicture.jpg",frame)
Resize the image using cv2.resize() to get a four-split screen.
Rotate the image using cv2.rotate(smaller_frame,cv2.cv2.ROTATE_180)
Display the image until the key to close the window is pressed.
Developed By: Shafeeq Ahamed.S
Register No: 212221230092
obj = cv2.VideoCapture(0)
while(True):
cap,frame = obj.read()
cv2.imshow('video_image.jpg',frame)
cv2.imwrite("out.jpg",frame)
if cv2.waitKey(1) == ord('q'):
break
obj.release()
cv2.destroyAllWindows()
obj = cv2.VideoCapture(0)
while(True):
cap,frame = obj.read()
cv2.imshow('video_image',frame)
if cv2.waitKey(1) == ord('q'):
break
obj.release()
cv2.destroyAllWindows()
obj = cv2.VideoCapture(0)
while True:
cap, frame = obj.read()
h = int(obj.get(4))
w = int(obj.get(3))
sm_frame = cv2.resize(frame, (0,0), fx=0.5 , fy=0.5)
im = np.ones(frame.shape,np.uint8)*200
im[125:(h//2)+125,135:(w//2)+135] = sm_frame
cv2.imshow("Pic",im)
if cv2.waitKey(1) == ord('q'):
break
obj.release()
cv2.destroyAllWindows()
obj = cv2.VideoCapture(0)
while True:
cap, frame = obj.read()
h = int(obj.get(4))
w = int(obj.get(3))
im = np.ones(frame.shape,np.uint8)*185
sf = cv2.resize(frame, (0,0), fx=0.5 , fy=0.5)
- #+/- 80
im[75:(height//2)+155, 35:(width//2)-45] = cv2.rotate(sf,cv2.ROTATE_90_CLOCKWISE)
im[:height//2, width//2:] = sf
im[height//2:, width//2:] = cv2.rotate(sf,cv2.ROTATE_180)
cv2.imshow("Pic",im)
if cv2.waitKey(1) == ord('q'):
break
obj.release()
cv2.destroyAllWindows()
Thus the image is accessed from webcamera and displayed using openCV.