Discussion Board

Results 1 to 3 of 3
  1. #1
    Super Contributor
    Join Date
    Mar 2003

    Direct screen access

    Can I access directly screen memory to detect pixel colors?
    Can I do it while CAMERA application is running?

    Camera module is not good for me, I need exposure tuning...

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Deva, Romania

    Re: Direct screen access

    I strongly doubt you can do that in Python. I'm not sure I know how you plan to work with the image, so I apologise if what I'm about to say isn't at all what you want.

    I would suggest that you take a screenshot when the camera application is running (I assume it's possible) and use the Image.getPixel() method to check its colors and luminance or whatever you need. See this thread and this site for more information.

    Again, sorry if this doesn't help

  3. #3
    Super Contributor
    Join Date
    Mar 2003

    Re: Direct screen access

    Thanks, but looks like it's easier than I thought!

    I can easily get a snapshot of camera application by using graphics.screenshot() , and I can easily set each pixel on the screen using fgimage.FGImage().set(x,y,graphics.Image_bitmapapi())

    BTW, what I'm trying to do is a weird project: using an old S60 phone as an LCD logger.
    I put the phone in front of any LCD, the phone recognizes the numbers and turn them into bytes which can easily processed for statistics.

    I have a couple of devices this program could be useful for: an internal/external thermometer, and a cheap (20$) energy meter.
    A professional energy meter with logging capabilities costs around 300$; mine will cost the price of a second hand s60 (50$ 40$ )

    If anybody is interested on the code, this is the first attempt: it makes use of the standard camera, but it is unusable unless your LCD is backlighted or enlighted in some manner.
    Please note that currently the script does NOT yet store values, but it's just a matter of adding a statement to store segm[] list.

    Please note you'll need miso module, used to keep light on.

    # Arrows change distances among segments;
    # SELECT saves settings to file;
    # 5: load settings from file;
    # 1-3: change distance among figures;
    # 2-8, 4-6: change segments size;
    from appuifw import *
    from graphics import *
    import camera
    import e32
    from key_codes import *
    import appuifw
    from camera import *
    import miso # Needed for backlight refresh
    PixThreshold = 66
    TopLeftX = [ 30, 65, 65,  30,  20, 20, 30]
    TopLeftY = [ 20, 35, 80,110, 80, 35, 65]
    # the keys as usual
    class Keyboard(object):
        def __init__(self,onevent=lambda:None):
        def handle_event(self,event):
            if event['type'] == appuifw.EEventKeyDown:
                if not self.is_down(cod):
            elif event['type'] == appuifw.EEventKeyUp:
        def is_down(self,scancode):
            return self._keyboard_state.get(scancode,0)
        def pressed(self,scancode):
            if self._downs.get(scancode,0):
                return True
            return False
    def InitVars():
      global offset, threshold, XWidth, YWidth, XHeight, YHeight, num
      offset = 70
      XWidth = 25
      XHeight = 10   
      YWidth = XHeight
      YHeight = XWidth
    def Reader():
       global canvas, PixThreshold, XWidth, YWidth, XHeight, YHeight
       canvas.blit(img, (0,0,150,150))
       TotColorR = 0
       TotColorG = 0
       TotColorB = 0
       x = 0
       y = 0
       n = 0
       for n in range(2): # Loop through various figures
        miso.reset_inactivity_time() # Keep light on
        idx = 0
        segm=[9,9,9,9,9,9,9] # Initialize segments to "8" (1=on=black, 2=off=transparent)
        for idx in range(7): # Loop through segments.
            #print "idx=",idx,":",              
            TotColorR = 0 # Per each segment calculate a separate sum.
            TotColorG = 0
            TotColorB = 0        
    #        x=TopLeftX[idx]-10
     #       y=TopLeftY[idx]-10
            # Examine a box inside the segment; values of each pixel are summed up into
            # a single value,which is the compared to a threshold to determine if
            # the segment is on (=black=under threshold) or off (=white=over threshold).
            if (idx == 0) or (idx == 6) or (idx == 3): # Horizontal segments
              Xstart = num[n]+TopLeftX[idx]
              Xend = num[n]+TopLeftX[idx]+XWidth
              Ystart = TopLeftY[idx]
              Yend = TopLeftY[idx]+XHeight
              Xstart = num[n]+TopLeftX[idx]
              Xend = num[n]+TopLeftX[idx]+YWidth
              Ystart = TopLeftY[idx]
              Yend = TopLeftY[idx]+YHeight
            for x in range(Xstart, Xend):
              for y in range(Ystart, Yend):
                tempR, tempG, tempB =  img.getpixel((x,y))[0]
                TotColorR = TotColorR + tempR
                TotColorG = TotColorG + tempG
                TotColorB = TotColorB + tempB 
                if tempR+tempG+tempB > PixThreshold:
            #print TotColorR + TotColorG + TotColorB
            if TotColorR+TotColorG+TotColorB > threshold:
        print "result=",segm
        #stringa = repr(segm[0])+repr(segm[1])
       canvas.blit(img, (0,0,150,120))
    def Overdraw():
      global num, XWidth, YWidth, XHeight, YHeight
      for n in range(2):
        for idx in range(7):
          for x in range(num[n]+TopLeftX[idx], num[n]+TopLeftX[idx]+XSize):
            for y in range(TopLeftY[idx],TopLeftY[idx]+YSize):
    def Adjust():
      global offset, XWidth, YWidth, XHeight, YHeight, num,PixThreshold
      switch = 1  
      XINC = 1
      XINC2 = 2
      YINC = 1
      YINC2 = 2
      YINC3 =4
      YINC4 = 4
      OFFSETINC = 10
      THRESHINC = 10
    # create a loop to get stuff handled that needs to be done again and again
      while running:
          # activate the camera again taking in pictures again and again (till key 2 is pressed)
          if switch == 1:
              screen_picture = camera.take_photo(size = (160,120))
          # draw the new picture on the canvas in the upper part -> numbers are coordinates of the location of the picture on the canvas
          # redraw the canvas
          # scan for left softkey to switch on the camera again
          if keyboard.pressed(EScancodeRightArrow):
              #TopLeftX[0] = TopLeftX[0]+ XINC
              TopLeftX[1] = TopLeftX[1]+ XINC2
              TopLeftX[2] = TopLeftX[2]+ XINC2
              #TopLeftX[3] = TopLeftX[3]+ XINC
              #TopLeftX[6] = TopLeftX[6]+ XINC
          if keyboard.pressed(EScancodeLeftArrow):
              #TopLeftX[0] = TopLeftX[0]- XINC
              TopLeftX[1] = TopLeftX[1]- XINC2
              TopLeftX[2] = TopLeftX[2]- XINC2
              #TopLeftX[3] = TopLeftX[3]- XINC
              #TopLeftX[6] = TopLeftX[6]- XINC
          if keyboard.pressed(EScancodeUpArrow):
              TopLeftY[1] = TopLeftY[1]- YINC
              TopLeftY[5] = TopLeftY[5]- YINC
              TopLeftY[6] = TopLeftY[6]- YINC2
              TopLeftY[2] = TopLeftY[2]- YINC3
              TopLeftY[4] = TopLeftY[4]- YINC3
              TopLeftY[3] = TopLeftY[3]- YINC4
          if keyboard.pressed(EScancodeDownArrow):
              TopLeftY[1] = TopLeftY[1]+ YINC
              TopLeftY[5] = TopLeftY[5]+ YINC
              TopLeftY[6] = TopLeftY[6]+ YINC2
              TopLeftY[2] = TopLeftY[2]+ YINC3
              TopLeftY[4] = TopLeftY[4]+ YINC3
              TopLeftY[3] = TopLeftY[3]+ YINC4
          if keyboard.pressed(EScancode1):
              offset = offset - OFFSETINC
          if keyboard.pressed(EScancode3):
              offset = offset + OFFSETINC
          if keyboard.pressed(EScancode4):
              YWidth = YWidth - 1
              XWidth = XWidth - 2
          if keyboard.pressed(EScancode6):
              YWidth = YWidth + 1
              XWidth = XWidth + 2
          if keyboard.pressed(EScancode2):
              YHeight = YHeight - 2
              XHeight = XHeight - 1
          if keyboard.pressed(EScancode8):
              YHeight = YHeight + 2
              XHeight = XHeight + 1
          if keyboard.pressed(EScancode5): # Test capture
              switch = 1
          if keyboard.pressed(EScancode7):
              PixThreshold = PixThreshold - THRESHINC
          if keyboard.pressed(EScancode9):
              PixThreshold = PixThreshold + THRESHINC
        # scann for left softkey to switch on the camera again
          if keyboard.pressed(EScancodeLeftSoftkey):
              switch = 1
          # scan for the Select key (navigaiton key pressed)
          # if pressed the go out of the previous loop of getting in pictures again and again
          if keyboard.pressed(EScancodeSelect):
              switch = 2
              out_file = open(filename,"w")
              out_file.write("Offset=" + repr(offset) + "\n")
              out_file.write("BoxWidth=" + repr(XSize) + "\n")
              out_file.write("BoxHeight=" + repr(YSize) + "\n")   
              for i in range(7):
                out_file.write("TopLeftX[" + repr(i) + "]=" + repr(TopLeftX[i])+"\n")     
                out_file.write("TopLeftY[" + repr(i) + "]=" + repr(TopLeftY[i])+"\n")     
          if keyboard.pressed(EScancode5):
    def quit():
        global running
    # define the redraw function (redraws the screen)
    def handle_redraw(rect):
    # create an empty image
    canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=handle_redraw)
    screen_picture = camera.take_photo(size = (160,120))
    NOTE: looks like a bug in forum engine prevents codes from containing "[code]" string!

Similar Threads

  1. Direct screen access & display mode
    By girish_n in forum Symbian
    Replies: 1
    Last Post: 2008-02-12, 08:33
  2. Direct Screen Access Example
    By jackylb in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2005-10-07, 09:28
  3. Problem with Direct Screen Access
    By huwell in forum Symbian
    Replies: 0
    Last Post: 2003-11-30, 12:42
  4. How to use direct screen access in release 6.2
    By cl_max1mum in forum Symbian User Interface
    Replies: 1
    Last Post: 2001-12-05, 20:22
  5. Direct screen access question?
    By in forum Symbian
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

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