I wrote a simple Python program for Maemo to check the color of each pixel every time my function is called. But this function works very slowly (3-5 seconds of each call). Is there a 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
source share