Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2007

    How to access pixel array of image captured by viewfinder

    Hello, currently I am capturing an image using the viewfinder, and having the frames be processed by a callback function, so my code starts out with:

    camera.start_finder( vfCallback, backlight_on=1, size=(320, 240) )

    In vfCallback, I want to be able to access the array of pixels for the image that is passed to the callback. This is so I can do things like thresholding, conversion to grayscale, etc. vfCallback looks like this:

    def vfCallback( aIm ):
    global IMG
    appuifw.app.body.blit( aIm )
    IMG = aIm

    So I have two questions. First, how would I convert this to grayscale, are there any built-in functions to do so or will I need to program my own (slow) version? Secondly, how do I get access to the array of pixels, so that I may iterate over them performing various computations.

    Thanks for the help!

  2. #2
    Super Contributor
    Join Date
    May 2006
    Oulu, Finland

    Re: How to access pixel array of image captured by viewfinder

    Hi yqmtooblue,

    Here is a piece of source that calculates the transparency for icons. That should help you figuring out how to access the pixels:
        ## @brief Calculate the mask for the list icon.
        #  All white point are transformed to transparent.
        #  @param self The object pointer.
        #  @param aImg An image object.
        #  @return Image mask object.
        def _autoMask( self, aImg ):
            width, height = aImg.size
            mask = Image.new( aImg.size, '1' )
            tran = (255,255,255)
            for y in range( height ):
                line = aImg.getpixel( [( x, y ) for x in range( width )] )
            for x in range( width ):
                if line[x] == tran:
                    mask.point( ( x, y ), 0 )
            ## Icon mask for dealing with transparency
            self._iDefaultIconMask = mask
    To get the gray scale image you just save the image to .png formay with a 8 bits bpp (bit per pixels). Here is an extract from the documentation

    save(filename[,callback=None, format=None, quality=75, bpp=24, compression=’default’ ])

    Note: Not supported in S60 1st Edition!

    Saves the image into the given file. The supported formats are JPEG and PNG. If format is not
    given or is set to None, the format is determined based on the file name extension: ’.jpg’ or
    ’.jpeg’ are interpreted to be in JPEG format and ’.png’ to be in PNG format. filename should
    be a full path name.

    When saving in JPEG format, the quality argument specifies the quality to be used and can range
    from 1 to 100.

    When saving in PNG format, the bpp argument specifies how many bits per pixel the resulting file
    should have, and compression specifies the compression level to be used.

    Valid values for bpp are:
    • 1: Black and white, 1 bit per pixel
    • 8: 256 gray shades, 8 bits per pixel
    • 24: 16.7 million colors, 24 bits per pixel

    Valid values for compression are:
    • ’best’: The highest possible compression ratio, the slowest speed
    • ’fast’: The fastest possible saving, moderate compression
    • ’no’: No compression, very large file size
    • ’default’: Default compression, a compromise between file size and speed

    If callback is given, the operation is asynchronous. When the saving is complete, the callback is
    called with the result code.
    Saving the image takes some time and will deteriorate the viewfinder performances. The only thing you can do to speedup lightly is to save the image in the RAM disk (ex: D:\\tmp.png)

    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:

Similar Threads

  1. fast pixel access to frame buffer ?
    By rs_chikin in forum Symbian
    Replies: 1
    Last Post: 2003-10-22, 15:42
  2. Access text inside of a resource array
    By jmorato in forum Symbian
    Replies: 2
    Last Post: 2003-07-18, 17:04
  3. 7250 image files access
    By catale in forum Mobile Java General
    Replies: 2
    Last Post: 2003-03-24, 08:36
  4. Direct access to single pixel.
    By hardwik in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2003-02-27, 16:08
  5. Get pixel data from an image object on Nokia phones?
    By inopia in forum Mobile Java General
    Replies: 1
    Last Post: 2002-05-15, 09:27

Posting Permissions

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