use maemo camera by python
Asked Answered
C

2

6

I wrote a simple program for Maemo by Python to check some pixel's color every time that my function is called. But this function runs very slowly (3-5 seconds each call). Is there any faster way to do this?

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
Calumniate answered 25/10, 2011 at 17:38 Comment(1)
Without being at all familiar with gstreamer, is the colorspace conversion really necessary? Also, tuning the quality parameter to jpegenc may help.Cupcake
G
2

Calling an external program via os.system is likely what's taking the time.

Try using GStreamer Python Bindings instead and keeping the video object around between calls. The docs for Videomixer may help.

Grateful answered 25/11, 2011 at 12:4 Comment(0)
D
1

As George says, you may be incurring overhead in a system call but I suspect the getpixel() call. PIL's getpixel() is notoriously slow. Instead load() the image and then loop through -- that should be faster.

Discontinuous answered 5/12, 2011 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.