There are many scripting methods to use the system camera in python.but majorly there are some mehtods like pygame, opencv etc.we can use picamera also but it’s use in rasberry pi projects,so you want rasberry pi processors or circuits.
but the main thing is your logic ,how and where you use your program is important.
Now, iam going to explain these methods and iam going to tell you how you could build a script to use your system camera by python.
Now, Iam going to explain the main methods which mostely used to use camera of the system:-

(1). Pygame:- pygame requires python,it’s important.the best way to install it is -
pip install pygame
pygame is basically design for video games.you can design your’s.it have graphics and sound libraries to create one. Now, it’s upon your creation or imagination to how to build your game.
To create program:-
import pygame.camera
import pygame.image
import sys
pygame.camera.init()
camera = pygame.camera.list_camera()
print(‘show camera name %s’ %camera[0])
webcam = pygame.camera.Camera(camera[0])
image = webcam.get_image()
width ,height=500,500
display_1=pygame.display_set_mode((width,hieght))
pygame.display.set_caption(‘your caption on screen’)
while True:
for i in pygame.event.get():
if i.type==pygame.QUIT :
sys.exit()
display_1.blit(image,(0,0))
pygame.display.flip()
image=webcam.get_image()

To install opencv in your system:-
sudo apt install python-opencv
To capture a video, we need to create a capture object. capture have the device index or the name of a video file. Device index is just the number to specify which camera. If we pass 0 then it is for our camera, 1 for other camera and so on. We capture the video frame by frame.
Now create our program:-
import cv2
import numpy as np
capture = cv2.VideoCapture('myvideo.mp4')
if (capture.isOpened()== False):
print("error can’t open video file")
while(capture.isOpened()):
r, frame = capture.read()
if r == True:
cv2.imshow('Frame', frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
capture.release()
cv2.destroyAllWindows()
We use opencv to object detection to create a AI(Artificial Intelligence).

0 Comments