This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from apollo-1845/main
Update the release version
- Loading branch information
Showing
1 changed file
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
from project_types import Sensor | ||
from sensors.camera.base_camera import CameraData | ||
|
||
from settings import PREFERRED_RESOLUTION, PREFERRED_RES_NP | ||
|
||
from picamera import PiCamera | ||
import numpy as np | ||
|
||
OUTPUT_RES_NP = PREFERRED_RES_NP + (3,) # With 3-byte colour depth | ||
|
||
class Camera(Sensor): | ||
"""A physical camera using the Raspberry Pi's PiCamera API.""" | ||
|
||
def __init__(self): | ||
"""Initialize camera.""" | ||
self.camera = PiCamera() | ||
self.camera.resolution = (640, 480) | ||
self.camera.resolution = PREFERRED_RESOLUTION | ||
self.camera.start_preview() | ||
|
||
def capture_data(self): | ||
"""Capture frames from self.camera.""" | ||
output = np.empty((480, 640, 3), dtype=np.uint8) | ||
self.camera.capture(output, 'rgb') | ||
output = np.empty(OUTPUT_RES_NP, dtype=np.uint8) | ||
self.camera.capture(output, 'bgr') | ||
|
||
return CameraData.from_color_image(output) |