It would be nice to see the picture you are going to take onscreen. A preview, some kind of viewfinder.
It would be nice to see the picture you are going to take onscreen. A preview, some kind of viewfinder.
Try this:Originally posted by bercobeute
It would be nice to see the picture you are going to take onscreen. A preview, some kind of viewfinder.
Code:# # showimg.py - shows "viewfinder" on the screen # from appuifw import * from graphics import * import camera canvas=Canvas() app.body=canvas running=1 def quit(): global running running=0 app.exit_key_handler=quit while running: canvas.blit(camera.take_photo())
And you might want to resize the "Image" object returned by "camera".
E.g. in 6600 (default size taken by "camera" is (640, 480)):
Resizing the "Image" is also an option but this is slower:Code:canvas.blit(camera.take_photo(size=(160, 120)))
Code:canvas.blit(camera.take_photo().resize((100,100)))
You can also scale directly with blit. This is much faster than .resize:Originally posted by otsov
And you might want to resize the "Image" object returned by "camera".
E.g. in 6600 (default size taken by "camera" is (640, 480)):
Resizing the "Image" is also an option but this is slower:Code:canvas.blit(camera.take_photo(size=(160, 120)))
Code:canvas.blit(camera.take_photo().resize((100,100)))
canvas.blit(camera.take_photo(),target=(0,0,176,117),scale=1)
Thanks for the example. It runs fine as a standalone script, but not when I incorporate it in another application. I suspect that is has something to do with threading, but I'm not too familiar with that yet.
What I basically do in the app that I want to incorporate the given code in is:
Code:self.loop() def loop( self ): try: while not self.exit_flag: self.refresh() self.lock.wait() finally: self.abort()
That code seems fine to me, so the problem must be elsewhere.
People, if your script is not big, just post the whole thing with your question. It makes things easier to debug.
I found the problem.
What I want to do is use the viewfinder and then take a picture. It turns out that (in the code below) the maximum resolution for the viewfinder is 160x120. But I want to take the picture at the default resolution of the phone (640x480). This somehow crashes python ('app closed'). It seems that in the code below step 2a works fine, but step 2b crashes the phone. Apparently you can't use the camera twice in a row with different settings regarding the resolution. Am I right?
Code:self.startViewfinder() def startViewfinder(self): appuifw.app.menu = [(u"Click!", self.takePhoto)] canvas = appuifw.Canvas() self.viewFinderRunning = 1 while self.viewFinderRunning: # STEP 1 self.image = camera.take_photo(size = (160,120)) canvas.blit(self.image,target=(0,0,176,117),scale=1) def takePhoto(self): self.quitViewFinder() # STEP 2a self.image.save(self.imageFileName ) # STEP 2b # pic = camera.take_photo() # pic.save(self.imageFileName ) def quitViewFinder(self): self.viewFinderRunning = 0
Not really. That code snippet is still too small to see the problem, but I strongly suspect that you call the image taking function from a UI callback. take_photo is a call that takes a fair amount of time and so an Active Scheduler is started that processes UI events during that time. Thus UI callback code could be called during take_photo and the badness you saw probably occurs when take_photo is called _again_ while the wait for the previous take_photo completion is in progress.
The fact that the interpreter crashes on your code instead of raising a CameraBusyError or something is a bug. Thanks for letting us know, we'll try to fix it.
In the mean time you can make your code work by moving the full resolution take_photo call into the viewfinder function. In a UI callback just set a flag take_photo_now and in the viewfinder function simply do something like
Code:if self.take_photo_now: photo=camera.take_photo() photo.save(...) self.take_photo_now=0 else: self.image=camera.take_photo(size=(160,120)) canvas.blit(...)