maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   use maemo (N900) camera by python (https://talk.maemo.org/showthread.php?t=79470)

sinal 2011-10-29 09:15

use maemo (N900) camera by python
 
I wrote a simple program for Maemo by Python to check some pixels color every time that my function is called.
But this program is working so slow (3-5 seconds each call).
Is there any faster way for doing this?

Code:

import Image
import os
import sys

#sen_pos = (pixel_x,pixel_y)
def sen(sen_pos):

    os.system("gst-launch v4l2src device=/dev/video0 num-buffers=1 ! ffmpegcolorspace ! jpegenc ! filesink location=cam.jpg")
    frame = Image.open("cam.jpg")
    col = frame.getpixel((sen_pos[0],sen_pos[1]))
    avecol = sum(col)/len(col)
    if avecol>127:
        return "white"
    elif avecol<127:
        return "black"
    return None


maacruz 2011-10-29 12:02

Re: use maemo (N900) camera by python
 
Quote:

Originally Posted by sinal (Post 1115471)
I wrote a simple program for Maemo by Python to check some pixels color every time that my function is called.
But this program is working so slow (3-5 seconds each call).
Is there any faster way for doing this?

Code:

import Image
import os
import sys

#sen_pos = (pixel_x,pixel_y)
def sen(sen_pos):

    os.system("gst-launch v4l2src device=/dev/video0 num-buffers=1 ! ffmpegcolorspace ! jpegenc ! filesink location=cam.jpg")
    frame = Image.open("cam.jpg")
    col = frame.getpixel((sen_pos[0],sen_pos[1]))
    avecol = sum(col)/len(col)
    if avecol>127:
        return "white"
    elif avecol<127:
        return "black"
    return None


Probably it takes that time to build the gstreamer stream, activate the camera, take the image, and deactivate the camera
mplayer allows to save a screenshot in slave mode, see mplayer's man page.
You could have mplayer running and send it the screenshot command whenever you need to take the image.


All times are GMT. The time now is 16:30.

vBulletin® Version 3.8.8