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.
Using Camera within the scene?
-
@ omz, thanx for the very nice update but as i checked the photo module, i realized that accessing camera may not be available when a scene is running (for me it equals to when my app is running). is there any trick to use camera in a running app? like just to take a photo when a scene is running, and then back to scene and use photos.get_image to load it . Or pausing the scene and then resuming it again? for me, i guess, accessing camera within the apps is an important issue.
-
I'm having the same issue. If there is any way to dismiss the scene with a function like <code>stop()</code>, that would be very helpful. Thanks!
-
Before defining main scene class (the class containing the
draw()
,setup()
, and other functions), call thecapture_image()
method. Store the result as a variable. Within thesetup()
function, make the image variable a global. Convert the image to RGBA using the.convert()
method, save the result ofload_pil_image(image)
asself.img
, and useself.img
to access the image during the scene. Here is an example:from scene import * import Image import photos global imgs imgs = photos.capture_image() class MyScene (Scene): def setup(self): global imgs imgs.convert('RGBA') self.img = load_pil_image(imgs) def draw(self): image(self.img, 0, 0, self.size.w, self.size.h) run(MyScene(), frame_interval=1)
-
@Coder 123 you can format your code using the tag {pre}{pre}, replace curly braces with angled brackets <>
-
Thanks @Coder123, but is there a way to get multiple images i.e. take a photo with capture_image(), load it into a scene and do some processing on it, then take another photo and repeat, kind of what would be required for a camera application or similar.
-
I tried breaking out of a scene by raising an exception, but I was unable to catch it. Instead of being handled by the try/except clause I put around run(), it took me back to the interpreter and highlighted the line where the exception was raised.
-
@Achorrath I tried this as well as other evil things (deleting references, unloading vital modules, etc) It seems that the scene is tied to the execution of the program, and when it gets created it gets loaded permanently into the main execution. Given that, can I put in a feature request for access to the camera while scenes are running. Even without the automatic camera interface would be reasonable; I don't know how iOS allows access to the camera but this approach seems unnecessarily clunky...
-
Resurrecting this old thread... I was just trying to open a capture_image interface from another simple UI view. The capture interface was called just fine with a button in a sheet view on the iPad, but when I tried to call the capture interface from a button in a fullscreen view, the whole program (script and Pythonista itself) froze. Has anybody else seen this?
-
Perhaps if you have a simple example that reproduces the code, we can find out the problem.
Often, this type of problem is caused when the ui thread is trying to do some animation, etc while the main thread is trying to show the dialog, camera, etc. The standard fix for such problems is to wrap the code in another function, and call ui.delay on it using a short delay, long enough to be sure the ui is finished doing whatever it was doing, maybe 0.5 second or something.Here is a simple ui button which captures an image, then shows it in an ImageView. This does not crash on my ipad2. When I added v.close() as the first line inside of the action, it does crash (in this case, drops back to home screen) Ui.delaying the subsequent code by 0.5 sec allowed it to work again. I was also able to get the camera "stuck" if I kicked off an ui.animate before showing the camera.
import ui, photos, io, console v=ui.View() v.bg_color='white' I=ui.ImageView(frame=(0,150,640,480)) I.content_mode=ui.CONTENT_SCALE_ASPECT_FIT v.add_subview(I) b=ui.Button(frame=(50,50,100,100)) b.bg_color='red' b.title='select image' v.add_subview(b) @ui.in_background def myaction(sender): img=photos.capture_image() console.show_activity() if not img: return with io.BytesIO() as bIO: img.save(bIO, 'PNG') imgOut = ui.Image.from_data(bIO.getvalue()) I.image=imgOut console.hide_activity() b.action=myaction v.present('fullscreen')
-
This example works fine on my ipad as well. It does bring up a question though about whether it is possible to write an app that can draw over the top of the capture_image display. Suppose I want to write an app that captures a selfie and needs the user to align their face with a template. I the example you provide, I would have to get the user to go back and forth between the capture interface and the app interface which would be klunky.
-
You cannot. But you could always crop and scale the image, or for instance have user drag a box over face
-
@JonB, thanks for the example. It does work fine on my iPad as well. The syntax is essentially what I have in my code, with a ui.Button activating a photo capture in the background. I haven't had a ton of time to look at the possible differences.
I'll say this, though. The one thing that made things work in my fullscreen view, was having hide_title_bar=True. This was independent of having the console show/hide activity. If this points to anything in particular, let me know. If/when I have time to dig a bit more into it, I'll add a new post.