Switch to picamerax
This commit is contained in:
parent
0bff4bdb62
commit
54c342bbbb
10 changed files with 122 additions and 99 deletions
|
|
@ -204,4 +204,4 @@ if __name__ == "__main__":
|
|||
from labthings import Server
|
||||
logging.info("Starting OpenFlexure Microscope Server...")
|
||||
server = Server(app)
|
||||
server.run(host="::", port=5000, debug=False, zeroconf=True)
|
||||
server.run(host="0.0.0.0", port=5000, debug=False, zeroconf=True)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import numpy as np
|
|||
import time
|
||||
import logging
|
||||
|
||||
from picamera import PiCamera
|
||||
from picamera.array import PiRGBArray, PiBayerArray
|
||||
from picamerax import PiCamera
|
||||
from picamerax.array import PiRGBArray, PiBayerArray
|
||||
|
||||
|
||||
def rgb_image(camera, resize=None, **kwargs):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "openflexure-microscope-jsclient",
|
||||
"version": "2.3.0",
|
||||
"version": "2.4.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
|||
from labthings import Schema, fields, find_component
|
||||
from labthings.views import View, PropertyView
|
||||
from labthings.utilities import description_from_view
|
||||
from labthings.views.marshalling import marshal_with
|
||||
from labthings.marshalling import marshal_with
|
||||
|
||||
from marshmallow import pre_dump
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ import os
|
|||
import logging
|
||||
|
||||
# Pi camera
|
||||
import picamera
|
||||
import picamera.array
|
||||
import picamerax
|
||||
import picamerax.array
|
||||
|
||||
# Type hinting
|
||||
from typing import Tuple
|
||||
|
|
@ -87,8 +87,8 @@ class PiCameraStreamer(BaseCamera):
|
|||
BaseCamera.__init__(self)
|
||||
# Attach to Pi camera
|
||||
self.camera = (
|
||||
picamera.PiCamera()
|
||||
) #: :py:class:`picamera.PiCamera`: Picamera object
|
||||
picamerax.PiCamera()
|
||||
) #: :py:class:`picamerax.PiCamera`: Picamera object
|
||||
|
||||
# Store state of PiCameraStreamer
|
||||
self.preview_active = False
|
||||
|
|
@ -247,7 +247,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
"""
|
||||
|
||||
Args:
|
||||
settings_dict (dict): Dictionary of properties to apply to the :py:class:`picamera.PiCamera`: object
|
||||
settings_dict (dict): Dictionary of properties to apply to the :py:class:`picamerax.PiCamera`: object
|
||||
pause_for_effect (bool): Pause tactically to reduce risk of timing issues
|
||||
"""
|
||||
# Set exposure mode
|
||||
|
|
@ -339,11 +339,11 @@ class PiCameraStreamer(BaseCamera):
|
|||
if fullscreen:
|
||||
self.camera.preview.fullscreen = fullscreen
|
||||
self.preview_active = True
|
||||
except picamera.exc.PiCameraMMALError as e:
|
||||
except picamerax.exc.PiCameraMMALError as e:
|
||||
logging.error(
|
||||
"Suppressed a MMALError in start_preview. Exception: {}".format(e)
|
||||
)
|
||||
except picamera.exc.PiCameraValueError as e:
|
||||
except picamerax.exc.PiCameraValueError as e:
|
||||
logging.error(
|
||||
"Suppressed a ValueError exception in start_preview. Exception: {}".format(
|
||||
e
|
||||
|
|
@ -427,7 +427,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
# Stop the camera video recording on port 1
|
||||
try:
|
||||
self.camera.stop_recording(splitter_port=splitter_port)
|
||||
except picamera.exc.PiCameraNotRecording:
|
||||
except picamerax.exc.PiCameraNotRecording:
|
||||
logging.info("Not recording on splitter_port {}".format(splitter_port))
|
||||
else:
|
||||
logging.info(
|
||||
|
|
@ -467,7 +467,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
# Reduce the resolution for video streaming
|
||||
try:
|
||||
self.camera._check_recording_stopped()
|
||||
except picamera.exc.PiCameraRuntimeError:
|
||||
except picamerax.exc.PiCameraRuntimeError:
|
||||
logging.info(
|
||||
"Error while changing resolution: Recording already running."
|
||||
)
|
||||
|
|
@ -487,7 +487,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
# metric)
|
||||
splitter_port=splitter_port,
|
||||
)
|
||||
except picamera.exc.PiCameraAlreadyRecording:
|
||||
except picamerax.exc.PiCameraAlreadyRecording:
|
||||
logging.info(
|
||||
"Error while starting preview: Recording already running."
|
||||
)
|
||||
|
|
@ -573,7 +573,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
self.stop_stream_recording(resolution=resolution)
|
||||
|
||||
logging.debug("Creating PiYUVArray")
|
||||
with picamera.array.PiYUVArray(self.camera, size=size) as output:
|
||||
with picamerax.array.PiYUVArray(self.camera, size=size) as output:
|
||||
|
||||
logging.info("Capturing to {}".format(output))
|
||||
|
||||
|
|
@ -613,7 +613,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
self.stop_stream_recording(resolution=resolution)
|
||||
|
||||
logging.debug("Creating PiRGBArray")
|
||||
with picamera.array.PiRGBArray(self.camera, size=size) as output:
|
||||
with picamerax.array.PiRGBArray(self.camera, size=size) as output:
|
||||
|
||||
logging.info("Capturing to {}".format(output))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import picamera
|
||||
from picamera import mmal, mmalobj, exc
|
||||
from picamera.mmalobj import to_rational
|
||||
import picamerax
|
||||
from picamerax import mmal, mmalobj, exc
|
||||
from picamerax.mmalobj import to_rational
|
||||
import time
|
||||
import logging
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ MMAL_PARAMETER_DIGITAL_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x5A
|
|||
def set_gain(camera, gain, value):
|
||||
"""Set the analog gain of a PiCamera.
|
||||
|
||||
camera: the picamera.PiCamera() instance you are configuring
|
||||
camera: the picamerax.PiCamera() instance you are configuring
|
||||
gain: either MMAL_PARAMETER_ANALOG_GAIN or MMAL_PARAMETER_DIGITAL_GAIN
|
||||
value: a numeric value that can be converted to a rational number.
|
||||
"""
|
||||
|
|
@ -42,7 +42,7 @@ def set_digital_gain(camera, value):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with picamera.PiCamera() as cam:
|
||||
with picamerax.PiCamera() as cam:
|
||||
cam.start_preview(fullscreen=False, window=(0, 50, 640, 480))
|
||||
time.sleep(2)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue