本文整理汇总了Python中picamera.PiCamera方法的典型用法代码示例。如果您正苦于以下问题:Python picamera.PiCamera方法的具体用法?Python picamera.PiCamera怎么用?Python picamera.PiCamera使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类picamera
的用法示例。
在下文中一共展示了picamera.PiCamera方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, resolution=(320, 240), framerate=32, **kwargs):
# initialize the camera
self.camera = PiCamera()
# set camera parameters
self.camera.resolution = resolution
self.camera.framerate = framerate
# set optional camera parameters (refer to PiCamera docs)
for (arg, value) in kwargs.items():
setattr(self.camera, arg, value)
# initialize the stream
self.rawCapture = PiRGBArray(self.camera, size=resolution)
self.stream = self.camera.capture_continuous(self.rawCapture,
format="bgr", use_video_port=True)
# initialize the frame and the variable used to indicate
# if the thread should be stopped
self.frame = None
self.stopped = False
示例2: frames
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def frames():
with PiCamera() as camera:
camera.rotation = int(str(os.environ['CAMERA_ROTATION']))
stream = io.BytesIO()
for _ in camera.capture_continuous(stream, 'jpeg',
use_video_port=True):
# return current frame
stream.seek(0)
_stream = stream.getvalue()
data = np.fromstring(_stream, dtype=np.uint8)
img = cv2.imdecode(data, 1)
yield img
# reset stream for next frame
stream.seek(0)
stream.truncate()
示例3: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, resolution=(CAMERA_WIDTH, CAMERA_HEIGHT),
framerate=CAMERA_FRAMERATE,
rotation=0,
hflip=False, vflip=False):
# initialize the camera and stream
try:
self.camera = PiCamera()
except:
logging.error("PiCamera Already in Use by Another Process")
logging.error("Exiting %s Due to Error", progName)
exit(1)
self.camera.resolution = resolution
self.camera.framerate = framerate
self.camera.hflip = hflip
self.camera.vflip = vflip
self.camera.rotation = rotation
self.rawCapture = PiRGBArray(self.camera, size=resolution)
self.stream = self.camera.capture_continuous(self.rawCapture,
format="bgr",
use_video_port=True)
# initialize the frame and the variable used to indicate
# if the thread should be stopped
self.thread = None # Initialize thread
self.frame = None
self.stopped = False
示例4: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, resolution=(CAMERA_WIDTH, CAMERA_HEIGHT), framerate=CAMERA_FRAMERATE, rotation=0, hflip=False, vflip=False):
# initialize the camera and stream
try:
self.camera = PiCamera()
except:
print("ERROR - PiCamera Already in Use by Another Process")
print("INFO - Exit %s" % progName)
quit()
self.camera.resolution = resolution
self.camera.framerate = framerate
self.camera.hflip = hflip
self.camera.vflip = vflip
self.camera.rotation = rotation
self.rawCapture = PiRGBArray(self.camera, size=resolution)
self.stream = self.camera.capture_continuous(self.rawCapture,
format="bgr", use_video_port=True)
# initialize the frame and the variable used to indicate
# if the thread should be stopped
self.frame = None
self.stopped = False
示例5: takeDayImage
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def takeDayImage(filename, cam_sleep_time):
# Take a Day image using exp=auto and awb=auto
with picamera.PiCamera() as camera:
camera.resolution = (imageWidth, imageHeight)
camera.framerate = 80
camera.vflip = imageVFlip
camera.hflip = imageHFlip
camera.rotation = imageRotation # Valid values 0, 90, 180, 270
# Day Automatic Mode
camera.exposure_mode = 'auto'
camera.awb_mode = 'auto'
time.sleep(cam_sleep_time) # use motion or TL camera sleep to get AWB
if imagePreview:
camera.start_preview()
if imageFormat == ".jpg" :
camera.capture(filename, use_video_port=useVideoPort, format='jpeg',quality=imageJpegQuality)
else:
camera.capture(filename, use_video_port=useVideoPort)
camera.close()
logging.info("camSleepSec=%.2f exp=auto awb=auto Size=%ix%i "
% ( cam_sleep_time, imageWidth, imageHeight ))
if not showDateOnImage: # showDateOnImage displays FilePath so avoid showing twice
logging.info("FilePath %s" % (filename))
#-----------------------------------------------------------------------------------------------
示例6: getStreamImage
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def getStreamImage(isDay):
# Capture an image stream to memory based on daymode
with picamera.PiCamera() as camera:
camera.resolution = (testWidth, testHeight)
with picamera.array.PiRGBArray(camera) as stream:
if isDay:
camera.exposure_mode = 'auto'
camera.awb_mode = 'auto'
time.sleep(motionCamSleep) # sleep so camera can get AWB
else:
# use variable framerate_range for Low Light motion image stream
camera.framerate_range = (Fraction(1, 6), Fraction(30, 1))
time.sleep(2) # Give camera time to measure AWB
camera.iso = nightMaxISO
camera.capture(stream, format='rgb', use_video_port=useVideoPort)
camera.close()
return stream.array
#-----------------------------------------------------------------------------------------------
示例7: start
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def start(self):
with picamera.PiCamera() as camera:
camera.resolution = (1280, 960)
camera.framerate = 10
handler = CaptureHandler(camera, self.post_capture_callback)
self.__print('Waiting 2 seconds for the camera to warm up')
time.sleep(2)
try:
self.__print('Started recording')
camera.start_recording(
'/dev/null', format='h264',
motion_output=MyMotionDetector(camera, handler)
)
while True:
handler.tick()
time.sleep(1)
finally:
camera.stop_recording()
self.__print('Stopped recording')
示例8: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, resolution=(640, 480), framerate=32, save_image_interval=1):
'''
@param save_image_interval, interval in sec to save imave
'''
# initialize the camera and stream
self.camera = PiCamera()
self.camera.resolution = resolution
self.camera.framerate = framerate
self.rawCapture = PiRGBArray(self.camera, size=resolution)
self.stream = self.camera.capture_continuous(self.rawCapture,
format="bgr", use_video_port=True)
# initialize the frame and the variable used to indicate
# if the thread should be stopped
self.frame = None
self.rects = [] # list of matching faces
self.stopped = False
示例9: create_capture_device
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def create_capture_device(self):
if self.data.settings['capture']['TYPE']['value'] != 'usb':
if self.use_capture:
if self.piCapture_with_no_source():
return False
self.update_capture_settings()
try:
self.device = picamera.PiCamera(resolution=self.resolution, framerate=self.framerate, sensor_mode = self.sensor_mode)
return True
except picamera.exc.PiCameraError as e:
self.use_capture = False
self.data.settings['capture']['DEVICE']['value'] = 'disabled'
print('camera exception is {}'.format(e))
self.message_handler.set_message('INFO', 'no capture device attached')
return False
示例10: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, photo_size, gif_size, motion_size, camera_vflip,
camera_hflip, camera_capture_length, motion_detection_threshold,
camera_mode):
self.photo_size = photo_size
self.gif_size = gif_size
self.camera_vflip = camera_vflip
self.camera_hflip = camera_hflip
self.lock = Lock()
self.queue = Queue()
self.motion_framerate = 5
self.motion_size = motion_size
self.motion_detection_threshold = motion_detection_threshold
self.temp_directory = '/var/tmp'
self.camera_save_path = '/var/tmp'
self.camera_capture_length = camera_capture_length
self.camera_mode = camera_mode
self.motion_detection_running = False
self.too_dark_message_printed = False
try:
self.camera = PiCamera()
self.camera.vflip = self.camera_vflip
self.camera.hflip = self.camera_hflip
except Exception as e:
exit_error('Camera module failed to intialise with error {0}'.format(repr(e)))
示例11: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, res_width=96, res_height=96):
self.camera = picamera.PiCamera(resolution=(res_width, res_height))
# TODO propagate configurable resolution through '96' logic below
self.camera.hflip = True
self.camera.vflip = True
self.res_width = res_width
self.res_height = res_height
self.stream = picamera.array.PiYUVArray(self.camera)
self.pixelObjList = []
self.object_id_center = 0
self.pixelObjList.append(PixelObject(self.next_obj_id()))
self.max_pixel_count = 0
self.largest_object_id = 0
self.largest_X = 0
self.largest_Y = 0
self.filename = ''
示例12: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, cam_type):
self.cam_width = res_width
self.cam_height = res_height
self.camera_type = cam_type
self.camera = None
self.rawCapture = None
if cam_type == "camerapi":
log.info("Loading Camera Pi")
self.camera = PiCamera()
self.camera.resolution = (self.cam_width, self.cam_height)
elif cam_type == "usb":
camera_id = 0
log.info("Loading USB Camera id {}".format(camera_id))
self.camera = cv2.VideoCapture(camera_id)
self.camera.set(cv2.CAP_PROP_FPS, 30)
self.camera.set(cv2.CAP_PROP_FRAME_WIDTH, self.cam_width)
self.camera.set(cv2.CAP_PROP_FRAME_HEIGHT, self.cam_height)
log.info("Camera size {}x{}".format(self.cam_width, self.cam_height))
示例13: serve_forever
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def serve_forever(self):
# seed the random number generator from the system clock
random.seed()
logging.info('Initializing camera')
self.server.seqno = 0
self.server.client_address = None
self.server.client_timestamp = None
self.server.responders = {}
self.server.files = []
self.server.camera = picamera.PiCamera()
try:
logging.info('Starting server thread')
thread = threading.Thread(target=self.server.serve_forever)
thread.start()
while thread.is_alive():
thread.join(1)
logging.info('Server thread ended')
finally:
logging.info('Closing camera')
self.server.camera.close()
示例14: __init__
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def __init__(self, resolution=(320, 240), framerate=24, vflip=True, hflip=True):
self.camera = PiCamera()
self.camera.resolution = resolution
self.camera.framerate = framerate
self.camera.vflip = vflip
self.camera.hflip = hflip
self.camera.rotation = 270
self.data_container = PiRGBArray(self.camera, size=resolution)
self.stream = self.camera.capture_continuous(
self.data_container, format="bgr", use_video_port=True
)
self.frame = None
self.stopped = False
print('starting camera preview')
self.camera.start_preview()
示例15: setupRpiCam
# 需要导入模块: import picamera [as 别名]
# 或者: from picamera import PiCamera [as 别名]
def setupRpiCam(self):
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (self.width, self.height)
camera.framerate = self.fps
camera.crop = (0.0, 0.0, 1.0, 1.0)
self.camera = camera
self.rawCapture = PiRGBArray(camera, size=(self.width, self.height))
self.rgb = bytearray(self.width * self.height * 3)
self.yuv = bytearray(self.width * self.height * 3 / 2)
# wait for camera to warm up
time.sleep(0.1)