라즈베리파이 카메라 파이썬

페이지 정보

profile_image
작성자 test
댓글 1건 조회 101회 작성일 19-05-05 21:09

본문

https://blog.naver.com/gauya/220805265854

#! /usr/bin/python

import picamera
import time

outp="cctv/"  # forder

wakeup = 5
cam = picamera.PiCamera()

def capture1(fn):
        cam.resolution = (320, 240)
        cam.rotation = (180)
        cam.start_preview()
        if wakeup:
                time.sleep(wakeup) # wakeup time
        cam.capture(fn)
        print( fn + " captured")
        cam.stop_preview()

def rec1(fn):
        cam.resolution = (640, 480)
        cam.framerate = 24
        cam.annotate_text = 'Raspberry pi CAM Test\n' +fn
#      cam.annotate_text = time.strftime('%Y-%m-%d %H:%M:%S')

        cam.start_preview()
        if wakeup:
                time.sleep(wakeup) # wakeup time
        cam.start_recording(fn)
        cam.wait_recording(5)
        cam.stop_recording()
        print( fn + " recorded")
        cam.stop_preview()

#capture1(outp+'test.jpg')
#wakeup=None

for i in range(5):
        cfn = time.strftime(outp+"%Y%m%d-%H%M%S.jpg")
        vfn = time.strftime(outp+"%Y%m%d-%H%M%S.h264")

        capture1(cfn)
        #rec1(vfn)

댓글목록

profile_image

test님의 댓글

test 작성일

#! /usr/bin/python

import picamera
import time

outp="out/"

wakeup = 2
cam = picamera.PiCamera()

def capture1(fn):
        cam.resolution = (1920, 1080)

        cam.start_preview()
        if wakeup:
                time.sleep(wakeup) # wakeup time
        cam.capture(fn)
        print( fn + " captured")
        cam.stop_preview()

def rec1(fn):
        cam.resolution = (640, 480)
        cam.framerate = 24
        cam.annotate_text = 'Raspberry pi CAM Test\n' +fn
#      cam.annotate_text = time.strftime('%Y-%m-%d %H:%M:%S')

        cam.start_preview()
        if wakeup:
                time.sleep(wakeup) # wakeup time
        cam.start_recording(fn)
        cam.wait_recording(5)
        cam.stop_recording()
        print( fn + " recorded")
        cam.stop_preview()

capture1(outp+'test.jpg')
wakeup=None

for i in range(5):
        cfn = time.strftime(outp+"%Y%m%d-%H%M%S.jpg")
        vfn = time.strftime(outp+"%Y%m%d-%H%M%S.h264")

        capture1(cfn)
        rec1(vfn)


2. 하나의 비디오 스트림이 진행되는 도중 동시에 다른 포트를 통해 capture와 또 다른형식의 비디오 스트림을 저장
포트 1번과 2번으로 .h264와 .mpeg를 동시에 레코딩하고 포트 0번으로는 이미지캡쳐
def cam4(id, term,imgperiod=1.):
#      camera.resolution = (1920,1080)
#      camera.resolution = (2592,1944)
        camera.brightness = 50
        camera.contrast = 0
        camera.ISO = 0
        camera.saturation = 0
        camera.sharpness = 0
        camera.image_effect = 'none'
        camera.color_effects = None
        camera.rotation = 0
        camera.hflip = False
        camera.vflip = False
        camera.crop = (0.0, 0.0, 1.0, 1.0)
        camera.awb_mode = 'auto'
        camera.video_stabilization = False

        camera.annotate_text_size = 10
        camera.framerate = 30
        camera.start_preview()

        start = dt.datetime.now()

        vfn1 = start.strftime("out/%Y%m%d-%H%M%S.h264")
        vfn2 = start.strftime("out/%Y%m%d-%H%M%S.mjpeg")
        camera.start_recording(vfn1,resize=(640,480),splitter_port=1) #(320,240) (64,40))
        camera.start_recording(vfn2,resize=(640,480),splitter_port=2) #(320,240) (64,40))
        sleep(0.5)

        pt = 0
        while (dt.datetime.now() - start).seconds < term:
                camera.annotate_text = id + "\n" + dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                nt = time.time()
                if (nt - pt) > imgperiod:
                        ifn = dt.datetime.now().strftime('%Y%m%d-%H%M%S%f.jpg')
                        print ifn, ((dt.datetime.now() - start).seconds)
                        camera.capture('out/%s' % ifn, use_video_port=True,
                                resize=(2592,1944),splitter_port=0)
                        pt = nt
#              camera.wait_recording(1)

        camera.stop_recording(splitter_port=1)
        camera.stop_recording(splitter_port=2)
        camera.stop_preview()
[출처] picamera 테스트|작성자 서리