Im using this command thats is OpenCV image capturing and using PIL for processing. It take almost 2 second to capture and completing the processing. I need more simple command and fastest processing to work for my robots. Anyone have suggestion please be advice.
import cv2
from cv2 import *
from PIL import Image 
import RPi.GPIO as GPIO
import time
im = 0
.
.
.
.
.
def imgCrop(im):
        box = (0, 190, 640, 200)
        region = im.crop(box)
        region.save('crop.jpg')
    return region
def imgThres(im):
        gray = im.convert('L')
        bw = gray.point(lambda x: 0 if x<150 else 255, '1')
        bw.save("bw.jpg")
    return bw
def find_centroid(im, rez):
        width, height = im.size
        XX, YY, count = 0, 0, 0
        for x in xrange(0, width, rez):
            for y in xrange(0, height, rez):
                    if im.getpixel((x, y)) == 255:
                        XX += x
                        YY += y
                        count += 1
        return XX/count, YY/count
def camera ():
    cam = VideoCapture(0)   # 0 -> index of camera
    s, img = cam.read()
    if s:    
            imwrite("img.jpg",img) #save image
    imageFile = "img.jpg"
    Img = Image.open(imageFile)
    cImg = imgCrop(Img)
    tImg = imgThres(cImg)
    print find_centroid(tImg, 1)
        cen = find_centroid(tImg, 1)
        diff = cen[0] - 320
        if diff > 10:
        right()
            print 'right'
        if diff < -10:
        left()
            print 'left'
        else:
        forward()
            print 'straight'
while True:
    camera ()
Im using raspberry pi B as my micro-controller and using webcam to capture image. For info this command only for image capture and processing. There also have robot motion command but I not included here.
