Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Capturing photos without user interaction
-
Re: Capturing Photos without the iOS screen
@omz I just downloaded Pythonista in part because of the very functionality that was offered by the script in the linked post (i.e., capture an image from the camera without requiring user interaction).
However, the original script causes Pythonista to crash. My guess is that something is conflicting with the latest version of Python that comes installed on Pythonista.
Any thoughts on specifically why the code is crashing and/or how the code can be modified to work as it originally was intended?
Thanks for any help
-
@__self__ I've tried the script of the original post, I hear the click and the photo is taken and saved in Pythonista root as "sample.jpg". But, of course, in the general iOS settings, Pythonista has to be authorized to use the camera device. When you say that the script crashes, please explain.
-
@cvp By crashing, I mean literally that: the app will suddenly close in the middle of the script's execution.
Interestingly, the script will crash even if the entire code is placed within a try/except block, which fails to handle whatever error is causing the crash.
The script I am referring to is the one originally posted by @omz and which begins with
from objc_util import * import time import threading C = ObjCClass def take_photo_now(filename='photo.jpg'):
However, I have managed to modify the script you posted, which begins with
from objc_util import * import time AVCaptureSession = ObjCClass('AVCaptureSession') AVCaptureDevice = ObjCClass('AVCaptureDevice') AVCaptureDeviceInput = ObjCClass('AVCaptureDeviceInput') AVCapturePhotoOutput = ObjCClass('AVCapturePhotoOutput') def manualCapture(device, output, focusDistance, fileName):
So thanks for that.
However, I am stuck trying to figure out how to achieve better image focus for the outputs.
I need to capture images of documents being displayed on a laptop screen. If I set the focal distance in the script just right, I can get the some of the text to come out clearly in the image. However, the result is not as clear as when I take a photo manually (via the user interface) and select the focal point by tapping on the iPhone screen.
I am guessing there is a lot of additional stuff going on in an iPhone to adjust for white balance, exposure, focal distance, focus modes, etc. in order to optimize the clarity and quality of the resulting image.
If you have any quick thoughts about that, I'd be glad to hear.
But...
I've actually been stuck pretty badly on the next issue (arguably more important for my use case).
I was planning to post another question about this, but I cannot find a way to connect to Google Drive — which is where I need to upload the images captured by the Pythonista script.
I have checked every post in this forum relating to installing/authenticating via
pydrive
(following @JonB's instructions) orGoogle Drive API
(as @FarmerPaco) recommended.In the case of either library,
StaSh
has trouble downloading wheels for certain dependencies.Also, it appears that
oauth2client
is deprecated by Google going forward.I have a working version of a script (running from my laptop) that authenticates with my drive and uploads/downloads files correctly. So my bottleneck is really about getting it to work withing Pythonista.
I know this was once a pain point for you as well. Are you still able to upload files from Pythonista to your Google Drive?
-
@__self__ said
Are you still able to upload files from Pythonista to your Google Drive?
No more for a few months, unfortunately
-
@cvp That is really unfortunate.
Any ideas as to what in particular are the breaking changes?
Is it Pythonista, or Python 3.10, or the deprecation of oauth2client, or perhaps something else?
-
@__self__ some months ago, I received messages from Google with warnings about my user but I was fully busy with health problems thus I discard them...
-
To set the focus point like you would tapping on the screen:
device.lockForConfiguration_(None) device.focusPointOfInterest = CGPoint(0.5,0.5) #center of screen device.focusMode = 2 #For continuous autofocus device.unlockForConfiguration()
There are some other options, like setting a focus range if you know what the acceptable range is, etc. You can set single autofocus instead of continuous, which does it once then locks it. You could also choose a different point. There may be some options to let the phone choose a subject automatically, then set focus point based on that, but that's more complicated.
-
@__self__ said
I am guessing there is a lot of additional stuff going on in an iPhone to adjust for white balance, exposure, focal distance, focus modes, etc. in order to optimize the clarity and quality of the resulting image.
As @JonB said in previous post, there are a lot of options and you can find them here
-
Unlock endless possibilities and empower your curiosity with a simple click. Our website awaits, brimming with knowledge, inspiration, and solutions tailored just for you. Discover a world of captivating content, expert advice, and innovative ideas. Let us ignite your imagination, fuel your passions, and guide you towards the extraordinary. Don't wait another moment to embark on this transformative journey. Click now and unlock a realm of endless potential. Your adventure starts here.
link text
link text
link text
link text