Use maemo camera with python

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 
+6
source share
2 answers

Invoking an external program through os.system is likely to take time.

Try instead of GStreamer Python Bindings to save the video object between calls. Docs for Videomixer can help.

+2
source

As George says, you may have overhead on a system call, but I suspect the getpixel() call. PIL getpixel() is notoriously slow. Instead of load() image, and then the loop - it should be faster.

+1
source

Source: https://habr.com/ru/post/900067/


All Articles