New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS camera provider enhancements #7857
Conversation
Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines. |
Not required with kivy-ios master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM at a first glance!
I will test it on runtime (and will try to write a demo App, unless you already have one to share) during the upcoming weekend 😃
Super-minor: How about adding some logging when functionalities are not expected to be available but are called on macOS or vice-versa? Comments are super-fine, but users tend to not read them immediately. 😆
This example uses the new features https://github.com/Android-for-Python/INDEX-of-Examples#c4k_photo_example It depends on the Preview widget not the Camera widget. For iOS only, the master version of Preview is required https://github.com/Android-for-Python/Camera4Kivy . Release waits on this PR and a kivy-ios that points to the new Kivy master. The readme has not been updated for ios. Example shows switch between cameras, capture photo or screenshot, pinch-spread for zoom (on my SE only the back camera), device rotation behavior, mirrored front camera. To enable use of the Camera
To enable save to Photos App
To make contents of local storage visible to File Manager
Image saves default to Photos App. The Preview widget storage selection is the same as for Android, so to save to app storage in place of Photos App [I started this because I wanted to try to port the tflite recipe, but my test example used a camera, so ...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it on my iPhone 12 Pro, and generally works good!
Unfortunately, after some minor edits to your example and Camera4Kivy
, I wasn't able to attach the ultra-wide or telephoto (back) lenses due to how camera selection is handled.
I've added some comments explaining what could be done to improve it.
NSArray *devices; | ||
AVCaptureDevice *device; | ||
|
||
devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
devicesWithMediaType
has been deprecated in iOS 10.0, iPadOS 10.0, macOS 10.15, Mac Catalyst 13.1 and it doesn't provide access to ultra-wide or telephoto camera lenses.
Instead,AVCaptureDeviceDiscoverySession should be used.
if (_cameraNum >= 0) { | ||
int camNum = _cameraNum % [devices count]; | ||
if (camNum != _cameraNum) { | ||
NSLog(@"Warning: Max Camera Num is %lu; Using camera %d\n", | ||
(unsigned long)([devices count] - 1), camNum); | ||
} | ||
device = [devices objectAtIndex:camNum]; | ||
cameraNum = _cameraNum; | ||
} else { | ||
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] ; | ||
cameraNum = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new discoverySessionWithDeviceTypes:mediaType:position: allows a fairly more granular selection of the camera.
The devices
array may be not consistent of returning the "correct" order of the cameras, so could be nice to create an enumerator on Kivy side, and pass the configuration requested from the user to discoverySessionWithDeviceTypes:mediaType:position:
|
|
Updated the comments at the top. |
@misl6 Can you approve this, please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
I will open a couple of issues targeting what we discussed during the review.
Congrats on merging your first pull request! 🎉🎉🎉 |
@misl6 You open to a kivy-ios PR that bumps the kivy version to include this change? https://github.com/RobertFlatt/kivy-ios/blob/master/kivy_ios/recipes/kivy/__init__.py#L10 |
See: |
iOS camera provider enhancements, these are iOS only but implemented in the camera provider shared by iOS and MacOS.
The additional apis implement basic mobile camera functionality, this is not currently implemented.
To provide basic camera services on iOS, this PR adds
The fork also builds and runs on MacOS, indicating it is unlikely the changes have broken the MacOS camera provider.
TODO, but not part of this PR:
1)kivy-ios
does not load the camera provider, the Camera widget fails. Assuming this PR is accepted in a timely fashion, I will implementkivy-ios
PR that fixes the load and references this enhanced camera provider.