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 OpenCV Package
Capture Video from a Webcam. Use VideoCapture(0) to access the webcam and start capturing video.
Read the Video or Image. Utilize 'imread' to read a video frame or image from the webcam
Save Image to File. Employ 'imwrite' to save the captured image to a file.
Display Video or Image. Use 'imshow' to display the captured video frame or image
End the Program with 'q'. Allow the program to be terminated by pressing the 'q' key
### Developed By: Jeswanth
### Register No:212221230042
import cv2
videoCaptureObject = cv2.VideoCapture(0)
while (True):
ret,frame = videoCaptureObject.read()
cv2.imwrite("Frame.jpeg",frame)
result = False
videoCaptureObject.release()
cv2.destroyAllWindows()
import cv2
videoCaptureObject = cv2.VideoCapture(0)
while(True):
ret,frame = videoCaptureObject.read()
cv2.imshow('video',frame)
if cv2.waitKey(1) == ord('q'):
break
videoCaptureObject.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
width = int(cap.get(3))
height = int(cap.get(4))
image = np.zeros(frame.shape, np.uint8)
smaller_frame = cv2.resize(frame, (0,0), fx = 0.5, fy=0.5)
image[:height//2, :width//2] = smaller_frame
image[height//2:, :width//2] = smaller_frame
image[:height//2, width//2:] = smaller_frame
image [height//2:, width//2:] = smaller_frame
cv2.imshow('resize', image)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
width = int(cap.get(3))
height = int(cap.get(4))
image = np.zeros(frame.shape, np.uint8)
smaller_frame = cv2.resize(frame, (0,0), fx = 0.5, fy=0.5)
image[:height//2, :width//2] = cv2.rotate(smaller_frame,cv2.ROTATE_180)
image[height//2:, :width//2] = cv2.rotate(smaller_frame,cv2.ROTATE_180)
image[:height//2, width//2:] = smaller_frame
image [height//2:, width//2:] = smaller_frame
cv2.imshow('rotate', image)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
![image](https://private-user-images.githubusercontent.com/94155480/264281919-d8f8228d-7f24-4b85-9ae0-1f82287b3d82.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwODE5MjIsIm5iZiI6MTcyNTA4MTYyMiwicGF0aCI6Ii85NDE1NTQ4MC8yNjQyODE5MTktZDhmODIyOGQtN2YyNC00Yjg1LTlhZTAtMWY4MjI4N2IzZDgyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDA1MjAyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBlYmMyMzc0N2UwZjE2MzEwYTZhOTM0NzhkYWY1NjAzMjdiOGEyM2IxMzgyYjk3MzViZjc0MDE3MjA1ZGZkOGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rcUVRRddpS12r08JV4_Q5PdsVv1D5z4Ftzi8GKJmmdk)
![image](https://private-user-images.githubusercontent.com/94155480/264282114-d973dadd-3276-46d9-bd9e-e1e91df5d8cc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwODE5MjIsIm5iZiI6MTcyNTA4MTYyMiwicGF0aCI6Ii85NDE1NTQ4MC8yNjQyODIxMTQtZDk3M2RhZGQtMzI3Ni00NmQ5LWJkOWUtZTFlOTFkZjVkOGNjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDA1MjAyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWIzZDVjNTFiMDhjZjUyMTJkZDE0YTE3OWZhNDE3MTY3YzBjYmI0OWJjYjgzN2U0OWZkMTMxZGY3YjMxNDRhODcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.SNMRnpN9d505zpUVDdsrIIPZ5yTYJZUrb_5jrUy2SCs)
![image](https://private-user-images.githubusercontent.com/94155480/264282236-c3845d4d-29ed-4bc5-ba13-9a580dd21722.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwODE5MjIsIm5iZiI6MTcyNTA4MTYyMiwicGF0aCI6Ii85NDE1NTQ4MC8yNjQyODIyMzYtYzM4NDVkNGQtMjllZC00YmM1LWJhMTMtOWE1ODBkZDIxNzIyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDA1MjAyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI2MDU3NDlkZjU4YzM1Nzk5OGZhNjIzNDVmYTQ1YjRkY2M1OTUzNDhmODJkYTM4NDMzNTdiNjQ2Yzg5NTVhZDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.4utoAJGDsfppWPl18IA1rfYXW9j2d8v0F6_15NxkQIk)
![image](https://private-user-images.githubusercontent.com/94155480/264282342-2ee3f451-9c23-4d14-b71e-49ac76358c3c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwODE5MjIsIm5iZiI6MTcyNTA4MTYyMiwicGF0aCI6Ii85NDE1NTQ4MC8yNjQyODIzNDItMmVlM2Y0NTEtOWMyMy00ZDE0LWI3MWUtNDlhYzc2MzU4YzNjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDA1MjAyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkYzNhZDcyMDE1MmFiZThlN2RjYzdjMWIyNWFmZTg4YTk2ZTBiZmFlZjEwMzRhYWU0MmQwMmE5MWI4N2RhZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.OVF4cjzlh7S7YwGdoMqOrcc2xXJi-R78TKiVxTyClS4)
Thus the image is accessed from webcamera and displayed using openCV.