×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    1

    fullscreen camera viewfinder pyS60

    hi below ihs viewfinder.py which is a python script to record videos or take photos in fullscreen..that is camera is displayed in full screen and all options of the native camera application of a series60 phone are also present...but the code needs to be modified...i have tested it on NOKIA N70 and it displays the camera in full screen but is not able to capture photos or record video and secondly fps is very slow....i suppose there must be some error in the code...since i didnt write this code nor i am familiar with python programming...i thought i would post the code here so that python geniuses here could edit and test it and make it work....heres the code

    viewfinder.py


    Code:
    #=================================================
    #=====      FULL SCRREN CAMERA VIEWFINDER    =====
    #=================================================
    from appuifw import *
    from graphics import *
    from key_codes import *
    import camera, e32
    
    class Keyboard(object):
        def __init__(self,onevent=lambda:None):
            self._keyboard_state={}
            self._downs={}
            self._onevent=onevent
        def handle_event(self,event):
            if event['type'] == appuifw.EEventKeyDown:
                code=event['scancode']
                if not self.is_down(code):
                    self._downs(code)=self._downs.get(code,0)+1
                self._keyboard_state(code)=1
            elif event['type'] == appuifw.EEventKeyUp:
                self._keyboard_state[event['scancode']]=0
            self._onevent()
        def is_down(self,scancode):
            return self._keyboard_state.get(scancode,0)
        def pressed(self,scancode):
            if self._downs.get(scancode,0):
                self._downs[scancode]-=1
                return True
            return False
    key = Keyboard()
    app.body = canv = Canvas(event_callback=key.handle_event)
    appuifw.app.screen = 'large' # only softkeys visible
    string = ''
    #--------------- flash modes ------------
    flash_mode = 'auto'
    def flash_auto():
        global flash_mode
        flash_mode = 'auto'
    def flash_on():
        global flash_mode
        flash_mode = 'forced'
    def flash_off():
        global flash_mode
        flash_mode = 'none'
    #--------------- white balance ----------
    white_bal = 'auto'
    def whbal_auto():
        global white_bal
        white_bal = 'auto'
    def whbal_daylight():
        global white_bal
        white_bal = 'daylight'
    def whbal_cloudy():
        global white_bal
        white_bal = 'cloudy'
    def whbal_fluorescent():
        global white_bal
        white_bal = 'fluorescent'
    def whbal_tungsten():
        global white_bal
        white_bal = 'tungsten'
    #------------ picture size --------------
    pic_size = (1600,1200)
    def set_2mpx():
        global pic_size
        pic_size = (1600,1200)
    def set_svga():
        global pic_size
        pic_size = (1024,768)
    def set_vga():
        global pic_size
        pic_size = (640,480)
    #------------- exposure -----------------
    exp_mode = 'auto'
    def exp_auto():
        global exp_mode
        exp_mode = 'auto'
    def exp_center():
        global exp_mode
        exp_mode = 'center'
    def exp_night():
        global exp_mode
        exp_mode = 'night'
    #--------- test if file exists ----------
    def file_exists(f):
        try:
            file = open(f)
        except IOError:
            exists = 0
        else:
            exists = 1
        return exists
    #------------ read counter --------------
    counter = 0
    def read_counter():
        global counter
        # try to open ini file in which counter is stored
        if file_exists('E:\\System\\Apps\\Python\\my\\counter.ini') == 0:
            # file does not exist, so create it
            file = open('E:\\System\\Apps\\Python\\my\\counter.ini','w')
            # write initial value of the counter
            file.write('000')
            # close the file
            file.close()
        # now open the file again to read it
        file = open('E:\\System\\Apps\\Python\\my\\counter.ini','r')
        # read counter from inside
        string = file.readline()
        # convert string to integer
        counter = int(string)
        # close the file
        file.close()
    #------------ write counter -------------
    def write_counter():
        #open ini file in which counter is stored
        file = open('E:\\System\\Apps\\Python\\my\\counter.ini','w')
        # convert counter to string
        string = str(counter)
        # write counter in file
        file.write(string)
        # close the file
        file.close()
    #------------ image saving --------------
    def capture():
        global counter
        if save_pic == 1:
            # read counter from settings file
            read_counter()
            # convert the couter into string to save the file
            string = str(counter)
            #full path to file
            path = 'E:\\Images\\IMG' + string + '.jpg'
            # take picture at selected resolution
            img = camera.take_photo('RGB',pic_size,0,flash_mode,exp_mode,white_bal,0)
            # save the picture
            img.save(path, bpp=24, quality=100, compression='fast')
            # increase image counter
            counter += 1
            # store the counter in settings file
            write_counter()
        else:
            # take a fast picture to display on screen
            img = camera.take_photo('RGB16',(640,480),0,'none',exp_mode,white_bal,0)
        # display aiming area
        img.line([(310,240),(330,240)], 0x00FF00)           # horizontal aiming line
        img.line([(320,230),(320,250)], 0x00FF00)           # vertical aiming line
        img.line([(280,220),(280,210),(290,210)], 0x00FF00) # upper left corner
        img.line([(280,260),(280,270),(290,270)], 0x00FF00) # lower left corner
        img.line([(350,210),(360,210),(360,220)], 0x00FF00) # upper right corner
        img.line([(350,270),(360,270),(360,260)], 0x00FF00) # lower right corner
        # outline for statuses
        img.rectangle([(233,139),(267,152)],0x0000FF);
        img.rectangle([(267,139),(300,152)],0x0000FF);
        img.rectangle([(300,139),(345,152)],0x0000FF);
        img.rectangle([(345,139),(407,152)],0x0000FF);
        # picture size status
        if pic_size == (1600,1200):
            img.text((235,150),u'2MPx',0x50FFFF,u'LatinPlain19')
        elif pic_size == (1024,768):
            img.text((235,150),u'SVGA',0x50FFFF,u'LatinPlain19')
        elif pic_size == (640,480):
            img.text((235,150),u' VGA',0x50FFFF,u'LatinPlain19')
        # flash mode status
        if flash_mode == 'auto':
            img.text((271,150),u'Auto',0x50FFFF,u'LatinPlain19')
        elif flash_mode == 'forced':
            img.text((269,150),u' ON',0x50FFFF,u'LatinPlain19')
        elif flash_mode == 'none':
            img.text((269,150),u' OFF',0x50FFFF,u'LatinPlain19')
        # exposure status
        if exp_mode == 'auto':
            img.text((302,150),u' Auto',0x50FFFF,u'LatinPlain19')
        elif exp_mode == 'center':
            img.text((302,150),u'Center',0x50FFFF,u'LatinPlain19')
        elif exp_mode == 'night':
            img.text((302,150),u' Night',0x50FFFF,u'LatinPlain19')
        # white balance status
        if white_bal == 'auto':
            img.text((347,150),u'   Auto',0x50FFFF,u'LatinPlain19')
        elif white_bal == 'cloudy':
            img.text((347,150),u'  Cloudy',0x50FFFF,u'LatinPlain19')
        elif white_bal == 'daylight':
            img.text((347,150),u'  Sunny',0x50FFFF,u'LatinPlain19')
        elif white_bal == 'fluorescent':
            img.text((347,150),u'   Neon',0x50FFFF,u'LatinPlain19')
        elif white_bal == 'tungsten':
            img.text((347,150),u'Tungsten',0x50FFFF,u'LatinPlain19')
        canv.blit(img, (232,136,408,344)) # cut 176x208 from picture and display it on screen
        aim = Image.new((20,20), 'RGB16') # draw aiming lines in another image
        aim.blit(img, (78,104,89,114))    # show the aim box in center of the screen
    #----------- activate saving ------------
    save_pic = 0
    def activate_save():
        global save_pic
        save_pic = 1
    #--------- deactivate saving ------------
    def deactivate_save():
        global save_pic
        save_pic = 0
    #---------- quit application ------------
    running=1
    def quit():
        global running
        running = 0
        app.exit_key_handler=quit
    
    # menu for image size, flash mode, white balance and exposure
    appuifw.app.menu = [(u"Image size",((u"2MPx 1600 x 1200",set_2mpx),
                                        (u"SVGA  1024 x 768",set_svga),
                                        (u"VGA    640 x 480",set_vga)
                                       ) 
                        ),
                        (u"Flash mode",((u"Auto",flash_auto),
                                        (u"On",  flash_on),
                                        (u"Off", flash_off)
                                       )
                        ),
                        (u"Exposure",((u"Auto",  exp_auto),
                                      (u"Center",exp_center),
                                      (u"Night", exp_night)
                                     )
                        ),
                        (u"White balance",((u"Auto",       whbal_auto),
                                           (u"Daylight",   whbal_daylight),
                                           (u"Cloudy",     whbal_cloudy),
                                           (u"Fluorescent",whbal_fluorescent),
                                           (u"Tungsten",   whbal_tungsten)
                                          )
                        ),
                        (u"Back to Python",quit)
                       ]
    #=============== MAIN CODE ===============
    while running:
        # save picture if joystick was pressed otherwise just take the picture
        if key.is_down(EScancodeSelect):
            activate_save()
            # capture with saving
            capture()
        else:
            # reset saving
            deactivate_save()
            # capture without saving
            capture()
    Last edited by amerkhan; 2007-08-09 at 15:01.

  2. #2
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: fullscreen camera viewfinder pyS60

    Please, instead of QUOTE, use CODE-tags! You can edit your post: select all source code and press '#'-button. It should add [ CODE ] [ /CODE ] -tags around the selection.

  3. #3
    Super Contributor
    Join Date
    May 2006
    Location
    Oulu, Finland
    Posts
    622

    Re: fullscreen camera viewfinder pyS60

    Hi and welcome to the forum

    Please repost the source PLEASE! Can't read anything...

    First look your code needs to be optimized!

    Keyboard class can be dropped and use binding on the canvas object instead:
    Code:
    canv.bind( key_code, action )
    That loop consume a lot of resources since it checks again and again even if no key events happen. This is solved using the bindings.
    Code:
    while running:
        # save picture if joystick was pressed otherwise just take the picture
        if key.is_down(EScancodeSelect):
            activate_save()
            # capture with saving
            capture()
        else:
            # reset saving
            deactivate_save()
            # capture without saving
            capture()
    In stead use an active object lock:
    Code:
    APP_LOCK = e32.Ao_lock()
    appuifw.app.exit_key_handler = lambda: APP_LOCK.signal()
    APP_LOCK.wait()
    Let see for the rest when we can read the source

    LFD
    Devices:
    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:
    http://www.lfdm.net/thesis

Similar Threads

  1. Python for S60 1.4.0 released
    By jplauril in forum Symbian
    Replies: 43
    Last Post: 2009-05-24, 09:22
  2. Nokia N-Series Complete Model Line-Up
    By Dopod in forum General Development Questions
    Replies: 6
    Last Post: 2008-07-22, 20:16
  3. Camera Viewfinder problem...
    By profoundwhispers in forum Symbian
    Replies: 0
    Last Post: 2004-08-01, 17:21
  4. Replies: 1
    Last Post: 2003-05-28, 03:32
  5. use the viewfinder option without using the camera applciation
    By smallfish_ntu in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-05-28, 02:10

Posting Permissions

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