You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2023. It is now read-only.
This document has these sections [Overview](https://github.com/Android-for-Python/camera4kivy#overview), [Install](https://github.com/Android-for-Python/camera4kivy#install), [Examples](https://github.com/Android-for-Python/camera4kivy#examples), [Preview Widget](https://github.com/Android-for-Python/camera4kivy#preview-widget), [Image Analysis](https://github.com/Android-for-Python/camera4kivy#image-analysis), [Camera Behavior](https://github.com/Android-for-Python/camera4kivy#camera-behavior), [Camera Provider](https://github.com/Android-for-Python/camera4kivy#camera-provider), and [Known Behavior](https://github.com/Android-for-Python/camera4kivy#known-behavior).
7
-
8
-
On Android only:
9
-
- Do not [install an arm7 build on an arm8 device](#behavior-android-armeabi-v7a-build-installed-on-an-arm64-v8a-device).
6
+
7
+
8
+
-[Overview](#overview)
9
+
-[Install](#install)
10
+
*[Install Camera4Kivy on Desktop](#install-camera4kivy-on-desktop)
11
+
*[Install Camera4Kivy on Android](#install-camera4kivy-on-android)
12
+
+[buildozer.spec:](#buildozerspec-)
13
+
+[Run Time Permissions](#run-time-permissions)
14
+
*[Install Camera4Kivy on iOS](#install-camera4kivy-on-ios)
*[Behavior: Android armeabi-v7a build installed on an arm64-v8a device](#behavior--android-armeabi-v7a-build-installed-on-an-arm64-v8a-device)
79
+
*[Behavior: Android "No supported surface combination"](#behavior--android--no-supported-surface-combination-)
10
80
11
81
## Overview
12
82
@@ -52,7 +122,7 @@ The captured file location may be specified and is also reported in a callback.
52
122
53
123
On Android a pinch/spread gesture controls zoom, and a tap overrides any automatic focus and metering (if available). Some `connect_camera()` options are platform specific.
54
124
55
-
Be aware Preview operation depends on the performance of the graphics hardware. In general Preview uses the highest available resolution. On devices with low performance graphics hardware sush as low end laptops or Raspberry, you will probably have to explicitly set a lower image resolution inorder to increase the frame rate.
125
+
Be aware Preview operation depends on the performance of the graphics hardware. In general Preview uses the highest available resolution for 30fps performance. On devices with low performance graphics hardware sush as low end laptops or Raspberry, you will probably have to explicitly set a lower image resolution inorder to increase the frame rate.
56
126
57
127
## Install
58
128
@@ -66,11 +136,9 @@ A [camera provider](https://github.com/Android-for-Python/camera4kivy#camera-pro
66
136
67
137
Camera4Kivy depends on Buildozer 1.3.0 or later
68
138
69
-
`pip3 install buildozer`
70
-
71
139
#### buildozer.spec:
72
140
73
-
`android.api = 30` (or higher, min 29)
141
+
`android.api = 33` (Constrained by Android packages imported by camerax_provider)
@@ -127,12 +195,30 @@ To enable viewing images saved to app local storage with the File Manager:
127
195
128
196
A prerequisite is that a working camera is installed. Test this with the platform's camera app before proceeding. All examples use the platform specific camera provider, and assume the typical default camera_id of '0'. If you find the example does not connect to a camera review the available camera ids and your camera provider choice.
129
197
130
-
### Tested Examples and Platforms
198
+
### Tested Examples
131
199
132
200
The Photo example illustrates basic camera usage, try this first. The remaining examples illustrate image analysis using various packages.
133
201
134
202
On Android and iOS the app can rotate when the device rotates, on the desktop you can change the window size to simulate orientation, and thus rotating a mobile device.
Illustrates basic layout using screens. Basic camera functionality including photo capture, screenshot capture, and on Android capture of video with audio.
206
+
On Raspberry PI a mouse must be used, a touch pad does not work correctly.
Everything you need to read a restaurant menu. Long press or double click on a highlighted QR code to open a web browser. Illustrates basic analysis, screen annotation, and user interaction.
Illustrates basic layout using screens. Basic camera functionality including photo capture, screenshot capture, and on Android capture of video with audio.
155
-
On Raspberry PI a mouse must be used, a touch pad does not work correctly.
Everything you need to read a restaurant menu. Long press or double click on a highlighted QR code to open a web browser. Illustrates basic analysis, screen annotation, and user interaction.
Object classification. Illustrates using a large Tensorflow Lite model, and writing text to the Preview image.
168
-
169
239
## Preview Widget
170
240
171
241
An app can have multiple `Preview` widgets, but only one can be connected to the physical camera unit at a time. A natural way to implement this is to add a preview widget to a screen's contents, then connect to the camera unit `on_enter` and disconnect `on_pre_leave`. Or if using a ModalView, Popup, or MDDialog use `on_open` and `on_pre_dismiss`. The C4K-Photo-Example illustrates this, the other examples simply connect the camera after `on_start()` and disconnect `on_stop()`.
@@ -259,7 +329,7 @@ However on Android a disconnect immediately after a capture has be initiated may
259
329
defstop_capture_video(self): # Android only
260
330
```
261
331
262
-
Video capture is only available on Android.
332
+
Video capture is only available on Android or with the OpenCV camera provider. Capturing audio with video is only available on Android.
263
333
264
334
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).
265
335
@@ -315,10 +385,17 @@ On iOS only, zoom_abs() is called by pinch/spread gesture unless disabled.
315
385
```
316
386
317
387
#### Flash
318
-
Android only. For capture photo only, ignored for video and data.
319
-
Sequence flash : off, on, auto (default),
388
+
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.
389
+
320
390
```python
321
-
defflash(self)
391
+
defflash(self, state=None)
392
+
```
393
+
394
+
#### Torch
395
+
Android only, immediately turns the flash on in any use case. The `state` argument must be in `['on', 'off']`
396
+
397
+
```python
398
+
defflash(self, state)
322
399
```
323
400
324
401
#### Focus
@@ -327,6 +404,10 @@ Android only, if available on device. Called by a tap gesture unless disabled
327
404
deffocus(x, y):
328
405
```
329
406
407
+
#### camera_connected
408
+
409
+
This is a boolean variable describing the camera state. It is `True` immediatedal *after* the camera is connected, and `False` immediately *before* the camera is disconnected.
410
+
330
411
## Image analysis
331
412
332
413
### Overview and Examples
@@ -390,10 +471,14 @@ Analysis and canvas annotation callbacks occur on different threads. The result
390
471
```python
391
472
@mainthread
392
473
defmake_thread_safe(self, found):
393
-
self.annotations = found
474
+
ifself.camera_connected:
475
+
self.annotations = found
476
+
else:
477
+
self.annotations = []
394
478
```
479
+
Note that we null the application state when the camera is not connected. This prevents saved annotations from being shown when a camera is re-connected, due to the multi-threaded implementation.
395
480
396
-
And add the thread safe annotations to the canvas.
481
+
Then add the thread safe annotations to the canvas.
### Behavior: Preview has no aspect_ratio = 'fill'
622
-
623
-
There is no way to specify inverted letterboxing. Where the Preview exactly fills the space available, resulting in one axis of the captured or analyzed image being partially hidden in the Preview.
624
-
625
-
### Behavior: Raspberry PI Bullseye not available
626
-
627
-
The RaspberryPI video stack changed with Bullseye. In Bullseye currently the only working camera source is `libcamera`. Picamera is not availible, [apparently](https://www.raspberrypi.com/news/bullseye-camera-system/) a RPI Picamera2 Python interface is in development. And `libcamera` is not compatible with OpenCV or Kivy's GStreamer implementation.
628
-
629
-
### Behavior: Android Rotation
630
-
631
-
Rotating the physical device through 'inverted portrait' may result in an 'inverted landscape' display. An additional rotation to 'portrait' and back to 'landscape' corrects the display.
632
-
633
706
### Behavior: Android .mp4 Orientation
634
707
635
708
Video file orientation is incorrect if the preview orientation is not the same as the device orientation. Do not use this layout configuration when recording video. [Google issue tracker](https://issuetracker.google.com/issues/201085351).
@@ -638,18 +711,9 @@ Video file orientation is incorrect if the preview orientation is not the same a
638
711
639
712
Some image viewers (including Kivy Image widget) will incorrectly display a .jpg as rotated by 90 degrees. This occurs if the capture preview orientation is not the same as the device orientation, and the third party viewer does not use the Exif metadata.
640
713
641
-
### Behavior: Android connect_camera during on_start()
642
-
643
-
On Android, a `connect_camera()` called during `on_start()` will result in intermittent crashes during app start. The unfiltered logcat will contain: 'library "libdexfile.so" not found'.
644
-
Use Kivy clock to schedule the `connect_camera()` one time step later.
645
-
646
-
### Behavior: Android switching cameras, short duration inverted image.
647
-
648
-
When switching cameras there may be a short duration inverted image, this is more likely on older Android devices.
649
-
650
714
### Behavior: Android armeabi-v7a build installed on an arm64-v8a device
651
715
652
-
The implementation of Google's camerax gradle dependencies is architecture specific, an app built for armeabi-v7a will crash on an arm64-v8a device. To rin on an arm64-v8a device you **must** build for arm64-v8a.
716
+
The implementation of Google's camerax gradle dependencies appears to be architecture specific, an app built for armeabi-v7a will crash on an arm64-v8a device. To run on an arm64-v8a device you **must** build for arm64-v8a.
653
717
654
718
### Behavior: Android "No supported surface combination"
0 commit comments