ajout des branches et historiques
This commit is contained in:
61
ia2
Normal file
61
ia2
Normal file
@@ -0,0 +1,61 @@
|
||||
from picamera2.encoders import H264Encoder
|
||||
from picamera2 import Picamera2, Preview, H264Encoder
|
||||
import cv2 as cv
|
||||
from imutils.video.pivideostream import PiVideoStream
|
||||
import imutils
|
||||
import time
|
||||
from datetime import datetime
|
||||
import numpy as np
|
||||
|
||||
|
||||
class VideoCamera(object):
|
||||
def __init__(self, flip=False, file_type=".jpg", photo_string="stream_photo"):
|
||||
self.pcam = Picamera2()
|
||||
self.video_config = self.pcam.create_video_configuration(main={"size": (1920, 1080)}, lores={"size": (640, 480)})
|
||||
self.encoder = H264Encoder(bitrate=10000000)
|
||||
self.output = "test.h264"
|
||||
self.flip = flip
|
||||
self.file_type = file_type
|
||||
self.photo_string = photo_string
|
||||
|
||||
def start_preview(self):
|
||||
self.pcam.start_preview(Preview.QTGL)
|
||||
|
||||
def stop_preview(self):
|
||||
self.pcam.stop_preview()
|
||||
|
||||
def start_recording(self):
|
||||
self.pcam.start_recording(self.encoder, self.output)
|
||||
|
||||
def stop_recording(self):
|
||||
self.pcam.stop_recording()
|
||||
|
||||
def capture(self):
|
||||
frame = self.pcam.capture()
|
||||
ret, jpeg = cv.imencode(self.file_type, frame)
|
||||
return jpeg.tobytes()
|
||||
|
||||
def take_picture(self):
|
||||
frame = self.pcam.capture()
|
||||
ret, image = cv.imencode(self.file_type, frame)
|
||||
today_date = time.strftime("%m%d%Y-%H%M%S")
|
||||
cv.imwrite(str(self.photo_string + "_" + today_date + self.file_type), frame)
|
||||
|
||||
def __del__(self):
|
||||
self.stop_preview()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
picam2 = Picamera2()
|
||||
video_config = picam2.create_video_configuration(main={"size": (1920, 1080)}, lores={"size": (640, 480)}, display="lores")
|
||||
picam2.configure(video_config)
|
||||
encoder = H264Encoder(bitrate=10000000)
|
||||
output = "test.h264"
|
||||
picam2.start_preview(Preview.QTGL)
|
||||
picam2.start_recording(encoder, output)
|
||||
time.sleep(10)
|
||||
picam2.stop_recording()
|
||||
picam2.stop_preview()
|
||||
Reference in New Issue
Block a user