Sunday, 3 February 2019

Capturing image using camera in Raspberry Pi


Capturing image using usb camera or webcam in Raspberry Pi

Code:
import pygame
import pygame.camera
import requests
import os
import sys
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,"image.jpg")

Capturing and save image with current date and time using webcam or usb camera in raspberry pi:

Code:
import pygame
import pygame.camera
import requests
import os
import sys
import datetime
import time
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,"image.jpg")
date = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
newname = 'newimagename'+date+'.jpg'
os.rename('image.jpg', newname)











0 comments:

Post a Comment

if you have any doubt please let me know