Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 47e9406

Browse files
committed
picamera2
1 parent 0c3de1b commit 47e9406

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

Diff for: README.md

+23-9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Camera4Kivy
3232
- [mirrored](#mirrored)
3333
- [filepath_callback](#filepath_callback)
3434
- [sensor_resolution](#sensor_resolution)
35+
- [sensor_rotation](#sensor_rotation)
3536
- [default_zoom](#default_zoom)
3637
- [analyze_pixels_resolution](#analyze_pixels_resolution)
3738
- [enable_analyze_pixels](#enable_analyze_pixels)
@@ -46,6 +47,7 @@ Camera4Kivy
4647
- [name](#name)
4748
+ [Select Camera](#select-camera)
4849
+ [Zoom](#zoom)
50+
+ [Pan/scroll](#panscroll)
4951
+ [Flash](#flash)
5052
+ [Torch](#torch)
5153
+ [Focus](#focus)
@@ -231,11 +233,12 @@ Object classification. Illustrates using a large Tensorflow Lite model, and writ
231233
| MLKit | | | | :heavy_check_mark: | | |
232234
| TFLite | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: |
233235

234-
- Windows : Windows 11, i7-10 @ 1.1GHz, Python 3.8.2 Kivy==2.1.0.dev0
236+
- Windows : Windows 11, i7-10 @ 1.1GHz, Python 3.11.1 Kivy==2.2.0.dev0
235237
- Windows : Windows 10, i3-7 @ 2.4GHz, Python 3.9.7 Kivy==2.0.0
236238
- Macos : Big Sur, i5-10 @ @ 1.1GHz, Python 3.9.9 Kivy==2.0.0
237239
- Linux : Raspberry Buster, Cortex-A72 @ 1.5GHz Python3.7.3 Kivy==2.0.0
238-
- Android : build : arm64-v8a device: Android 12, Pixel 5
240+
- Linux : Raspberry Bullseye, Cortex-A72 @ 1.5GHz Python3.9.2 Kivy==2.1.0
241+
- Android : build : arm64-v8a device: Android 12, Pixel 5 3.10.6 Kivy==2.2.0.dev0
239242
- Android : build : armeabi-v7a device: Android 6, Nexus 5 Start is somewhat slow.
240243
- iOS : iPhone SE (second generation)
241244
- Coral : [Accelerator](https://coral.ai/products/accelerator) tested with Windows 11 , gave very approximately an order of magnitude speed up.
@@ -291,8 +294,11 @@ The filepath_callback can also be used to reset any 'video recording' indicator
291294
##### sensor_resolution
292295
Overrides the default sensor resolution, which is the highest resolution available, except Raspberry Pi where it is (1024, 768). Tuple of two integers, for example `sensor_resolution = (640, 480)`. The resulting capture resolution obtained depends on the behavior of the camera provider (for example it is ignored by GStreamer). The capture resolution also depends on the relative orientation and aspect ratio of the Preview. Treat the value specified as a request that may not be exactly honored.
293296

297+
##### sensor_rotation
298+
On Picamera2 sensor_rotation can be sepecifed in `[0, 90, 180, 270]`, where `0` is the default landscape orientation.
299+
294300
##### default_zoom
295-
Set the default zoom when the camera is connected, `0.5` is the default value.
301+
Set the default zoom when the camera is connected. On Android `0.5` is the default value.
296302

297303
##### analyze_pixels_resolution
298304
Sets the pixels resolution passed by `analyze_pixels_callback()`. A scalar, representing the number of pixels on the long edge, the short edge is determined using the aspect ratio. For example `analyze_pixels_resolution = 720`. The default is the minimum of cropped sensor resolution and 1024.
@@ -336,7 +342,7 @@ However on Android a disconnect immediately after a capture has be initiated may
336342
def stop_capture_video(self): # Android only
337343
```
338344

339-
Video capture is only available on Android or with the OpenCV camera provider. Capturing audio with video is only available on Android.
345+
Video capture is only available on Android, Picamera2, or OpenCV camera providers. Capturing audio with video is available on Android and Picamera2. OpenCV video quality is poor.
340346

341347
Captures are never mirrored, except a screenshot capture if the Preview is mirrored. Capture resolution is discussed [here](https://github.com/Android-for-Python/Camera4Kivy#capture-resolution).
342348

@@ -384,13 +390,19 @@ Change the currently connected camera, camera_id must specify a physically conne
384390
```
385391

386392
#### Zoom
387-
On Android only, zoom_delta() is called by pinch/spread gesture unless disabled.
393+
On Android and Picamera2, zoom_delta() is called by pinch/spread gesture unless disabled.
388394
On iOS only, zoom_abs() is called by pinch/spread gesture unless disabled.
389395
```python
390396
def zoom_delta(self, delta_scale):
391397
def zoom_abs(self, scale):
392398
```
393399

400+
#### Pan/scroll
401+
On Picamera2 pan/scroll a zoom'd image with a drag gesture.
402+
```python
403+
def drag(self, delta_x, delta_y):
404+
```
405+
394406
#### Flash
395407
Android only, and for capture photo only, the value is ignored for video and data. The `state` argument must be in `['on', 'auto', 'off']`, alternatively if `state=None` sequential calls sequence through that list. Note that 'on' always turns on the flash around the time a photo is captured, 'auto' only does this if the light level is low enough.
396408

@@ -657,9 +669,9 @@ Camera4Kivy depends on a 'camera provider' to access the OS camera api. On most
657669
| Linux | [Gstreamer](https://github.com/Android-for-Python/camera4kivy#gstreamer) |
658670
| | [OpenCV](https://github.com/Android-for-Python/camera4kivy#opencv) |
659671
| Rasberry | [Picamera](https://github.com/Android-for-Python/camera4kivy#picamera) | <= Buster |
660-
| | [Gstreamer](https://github.com/Android-for-Python/camera4kivy#gstreamer) | <= Buster |
661-
| |[OpenCV](https://github.com/Android-for-Python/camera4kivy#opencv) | <= Buster |
662672
| | [Picamera2](https://github.com/Android-for-Python/camera4kivy#picamera2) | >= Bullseye |
673+
| | [Gstreamer](https://github.com/Android-for-Python/camera4kivy#gstreamer) | |
674+
| |[OpenCV](https://github.com/Android-for-Python/camera4kivy#opencv) | |
663675
| Android | [CameraX](https://github.com/Android-for-Python/camera4kivy#android-camera-provider) | Android >= 5.0 |
664676
| iOS | [AVFoundation](https://github.com/Android-for-Python/camera4kivy#avfoundation) |
665677

@@ -698,6 +710,8 @@ Set `p4a.hook` to enable the app's use of the camera provider.
698710

699711
`pip3 install opencv-python`
700712

713+
Video recording (no audio) is available, but uncompressed, and may be low quality.
714+
701715
### GStreamer
702716

703717
Depends on the Linux flavor, but commonly:
@@ -707,10 +721,10 @@ Depends on the Linux flavor, but commonly:
707721
`sudo apt-get install gstreamer1.0-dev`
708722

709723
### Picamera
710-
Pre-installed
724+
Pre-installed on Buster.
711725

712726
### Picamera2
713-
Raspberry PI Bullseye support currently not available.
727+
May be pre-instaled on Bullseye. Additional features for native Pi cameras: higher resolution photos, video optionally with audio, zoom, pan when zoom'd, sensor rotation. USB cameras are not currently supported.
714728

715729
### AVFoundation
716730
Pre-installed

Diff for: index.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Camera4Kivy
3232
- [mirrored](https://github.com/Android-for-Python/Camera4Kivy#mirrored)
3333
- [filepath_callback](https://github.com/Android-for-Python/Camera4Kivy#filepath_callback)
3434
- [sensor_resolution](https://github.com/Android-for-Python/Camera4Kivy#sensor_resolution)
35+
- [sensor_rotation](https://github.com/Android-for-Python/Camera4Kivy#sensor_rotation)
3536
- [default_zoom](https://github.com/Android-for-Python/Camera4Kivy#default_zoom)
3637
- [analyze_pixels_resolution](https://github.com/Android-for-Python/Camera4Kivy#analyze_pixels_resolution)
3738
- [enable_analyze_pixels](https://github.com/Android-for-Python/Camera4Kivy#enable_analyze_pixels)
@@ -46,6 +47,7 @@ Camera4Kivy
4647
- [name](https://github.com/Android-for-Python/Camera4Kivy#name)
4748
+ [Select Camera](https://github.com/Android-for-Python/Camera4Kivy#select-camera)
4849
+ [Zoom](https://github.com/Android-for-Python/Camera4Kivy#zoom)
50+
+ [Pan/scroll](https://github.com/Android-for-Python/Camera4Kivy#panscroll)
4951
+ [Flash](https://github.com/Android-for-Python/Camera4Kivy#flash)
5052
+ [Torch](https://github.com/Android-for-Python/Camera4Kivy#torch)
5153
+ [Focus](https://github.com/Android-for-Python/Camera4Kivy#focus)

Diff for: src/camera4kivy/preview_kivycamera.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def cgb_zoom(self, touch0, touch1, x, y, scale):
191191
self.cg_zoom_level[self.index] = level
192192
self.zoom_abs(level)
193193
elif self.provider in ['picamera2']:
194-
self._camera.zoom(scale) ###### TODO zoom_level
194+
self._camera.zoom(scale)
195195

196196
# drag
197197
def cgb_drag(self, touch, x, y, dx, dy):
@@ -211,6 +211,20 @@ def zoom_abs(self, level):
211211
if platform == 'ios' and self._camera:
212212
self._camera.zoom_level(level)
213213

214+
#############################################
215+
# Picamera2 only User Events
216+
#############################################
217+
218+
def zoom_delta(self, delta_scale):
219+
if self._camera and self.provider in ['picamera2']:
220+
self._camera.zoom(delta_scale)
221+
222+
def drag(self, delta_x, delta_y):
223+
if self._camera and self.provider in ['picamera2']:
224+
crop = self.screenshot_crop()
225+
dx = delta_x / crop[2]
226+
dy = delta_y / crop[3]
227+
self._camera.drag(dx, dy)
214228

215229
#############################################
216230
# Ignored User Events
@@ -301,6 +315,7 @@ def start_camera(self):
301315
self._camera.bind(on_load=self.configure_texture_crop)
302316
self._camera.bind(on_texture=self.on_tex)
303317
self._camera.start()
318+
self.zoom_delta(self.default_zoom)
304319
if self.abort_camera_start:
305320
self.stop_camera()
306321
self._camera = None

0 commit comments

Comments
 (0)