python - Need more faster image capturing and processing method -


im using command thats opencv image capturing , using pil processing. take 2 second capture , completing processing. need more simple command , fastest processing work robots. have suggestion please advice.

import cv2 cv2 import * pil import image  import rpi.gpio 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         x in xrange(0, width, rez):             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 micro-controller , using webcam capture image. info command image capture , processing. there have robot motion command not included here.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -