Discussion Board

Results 1 to 9 of 9

Thread: Camera preview

  1. #1
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    158

    Camera preview

    It would be nice to see the picture you are going to take onscreen. A preview, some kind of viewfinder.

  2. #2
    Regular Contributor
    Join Date
    Sep 2003
    Location
    Finland
    Posts
    209

    Re: Camera preview

    Originally posted by bercobeute
    It would be nice to see the picture you are going to take onscreen. A preview, some kind of viewfinder.
    Try this:

    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())

  3. #3
    Regular Contributor
    Join Date
    Sep 2003
    Location
    Finland
    Posts
    209

    Re: Re: Camera preview

    And you might want to resize the "Image" object returned by "camera".

    E.g. in 6600 (default size taken by "camera" is (640, 480)):

    Code:
    canvas.blit(camera.take_photo(size=(160, 120)))
    Resizing the "Image" is also an option but this is slower:

    Code:
    canvas.blit(camera.take_photo().resize((100,100)))

  4. #4
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643

    Re: Re: Re: Camera preview

    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)):

    Code:
    canvas.blit(camera.take_photo(size=(160, 120)))
    Resizing the "Image" is also an option but this is slower:

    Code:
    canvas.blit(camera.take_photo().resize((100,100)))
    You can also scale directly with blit. This is much faster than .resize:

    canvas.blit(camera.take_photo(),target=(0,0,176,117),scale=1)

  5. #5
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    158
    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()

  6. #6
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    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.

  7. #7
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    158

    Crash

    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

  8. #8
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    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(...)

  9. #9
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    Filed as bug #210.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×