-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcamera.py
More file actions
51 lines (45 loc) · 1.44 KB
/
camera.py
File metadata and controls
51 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import random
import pygame.camera
import os
import io
import time
from PIL import Image
class Camera():
def __init__(self,resolution,display):
pygame.camera.init()
self.resolution=resolution
camlist = pygame.camera.list_cameras()
if not camlist:
import picamera
self.is_picamera=True
self.camera=picamera.PiCamera()
self.camera.rotation = 270
self.camera.exposure_compensation=10
self.camera.exposure_mode="auto"
self.resolution=(1920,1080)
time.sleep(2)
self.camera.exposure_mode="off"
else:
self.camera = pygame.camera.Camera(camlist[0],self.resolution)
self.camera.start()
self.is_picamera=False
self.frame=pygame.surface.Surface(self.resolution, 0, display)
def ruota(self):
self.camera.rotation+=90
if self.camera.rotation>=360:
self.camera.rotation=0
def save_frame(self,frame_manager):
filename=os.path.join(frame_manager.get_current_session_path(),"frame_"+"0"*(5-len(str(len(frame_manager.images))))+str(len(frame_manager.images))+".jpeg")
if self.is_picamera:
self.camera.capture(filename, use_video_port=True)
'''stream = io.BytesIO()
self.camera.capture(
stream, use_video_port=True, format='jpeg')
frame = Image.open(stream)
frame.save(filename, "JPEG")'''
else:
if self.camera.query_image():
self.frame = self.camera.get_image(self.frame)
pygame.image.save(self.frame,filename)
image=pygame.image.load(filename)
frame_manager.images.append(image)