Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use maemo camera by python

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
like image 284
LABOOOOX Avatar asked Oct 25 '11 17:10

LABOOOOX


People also ask

How to use a phone camera with Python?

The process of using a phone camera with Python: First, install the OpenCV library in Python; pip install opencv-python. Download and install the IP Webcam application on your smartphones. After installing the IP Webcam app, make sure your phone and PC are connected to the same network.

How to capture a single image from a cam in Pygame?

if camlist: # Initialize and start camera cam = pygame.camera.Camera (camlist [0], (640, 480)) cam.start () # capturing the single image image = cam.get_image () # saving the image pygame.image.save (image, "filename.jpg") else: if camera is not detected the moving to this part

How to use OpenCV in Python?

1 Make sure the following Python packages are installed: numpy, matplotlib, opencv-python, comtypes. 2 Run main.py. 3 Once the application is started, the dialog Select a video device is shown. Select a camera, then press Ok.

How to install Pygame camera initializer in Linux?

PyGame.camera () camera initializer supports only Linux operating system and Currently, It is not compatible with Windows. To install PyGame in Linux, Enter the below command on the Linux terminal. 1. Import pygame.camera module 2.


1 Answers

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.

like image 193
George Avatar answered Oct 19 '22 18:10

George