Aim:
To write a python program using OpenCV to capture the image from the web camera and do the following image manipulations. i) Write the frame as JPG ii) Display the video iii) Display the video by resizing the window iv) 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(frame, (0,0), fx = 0.5, fy=0.5).
Display the image until the loop gets over.
Rotate the image using cv2.rotate(smaller_frame,cv2.cv2.ROTATE_180).
import cv2
img = cv2.VideoCapture(0)
while(True):
imagee,frame = img.read()
cv2.imshow('myimage',frame)
if cv2.waitKey(1) == ord('c'):
break
img.release()
cv2.destroyAllWindows(
import cv2
video = cv2.VideoCapture(0)
while (True):
cap,frame=video.read()
cv2.imshow('Capturing Video',frame)
if cv2.waitKey(1) == ord('q'):
break
video.release()
import cv2
import numpy as np
img = cv2.VideoCapture(0)
while True:
pic,frame = img.read()
width = int(img.get(3))
height = int(img.get(4))
image = np.zeros(frame.shape, np.uint8)
small_frame = cv2.resize(frame,(0,0),fx =0.5, fy = 0.5)
image[:height//2, :width//2]=small_frame
image[height//2:, :width//2]=small_frame
image[:height//2, width//2:]=small_frame
image[height//2:, width//2:]=small_frame
cv2.imshow('myimage',image)
if cv2.waitKey(1) == ord('c'):
break
img.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
img = cv2.VideoCapture(0)
while True:
pic,frame = img.read()
width = int(img.get(3))
height = int(img.get(4))
image = np.zeros(frame.shape, np.uint8)
small_frame = cv2.resize(frame,(0,0),fx =0.5, fy = 0.5)
image[:height//2, :width//2]=cv2.rotate(small_frame,cv2.ROTATE_180)
image[height//2:, :width//2]=small_frame
image[:height//2, width//2:]=small_frame
image[height//2:, width//2:]=cv2.rotate(small_frame,cv2.ROTATE_180)
cv2.imshow('myimage',image)
if cv2.waitKey(1) == ord('c'):
break
img.release()
cv2.destroyAllWindows()
Thus the image is accessed from webcamera and displayed using openCV.