Computer Vision Simplified

When I was working on AndRo.bot last year, I had to do lots of vision-related processing on Android. Three of the several tasks it was expected to carry out using vision were – Live Streaming, Line Following and Face Detection. Using Java and openCV, the three tasks required over 3000 lines of codes. I was satisfied, I guess. This was still better than not doing anything at all.

But now that I am recreating the same features for a Raspberry Pi, I can see how much time and effort I wasted on putting curly brackets and stuffs. So, what is it this time that I didn’t have the last time? Well… short answer… Python and SimpleCV.

The Java codes are available in my Github repository here. Below I give you the ‘vision’ part of the codes for the same tasks, but using Python and SimpleCV.

1. IMAGE CAPTURE (for LIVE STREAMING)

from SimpleCV import *
cam = Camera()
while True:
       img = cam.getImage()
       img.show()
       if cv.WaitKey(10) == 27:
              break

2. BLOB DETECTION (for LINE FOLLOWER)

from SimpleCV import *
cam = Camera()
while True:
       img = cam.getImage()
       blue_distance = img.hueDistance(Color.BLUE).invert()
       blobs = blue_distance.findBlobs()
       blobs.draw(color=Color.PUCE, width=3)
       img.addDrawingLayer(blue_distance.dl())
       img.show()
       if cv.WaitKey(10) == 27:
              break

3. FACE DETECTION

from SimpleCV import Camera, Display
def main():
cam = Camera()
disp = Display()
while disp.isNotDone():
       img = cam.getImage()
       img = img.scale(0.5)
       faces = img.findHaarFeatures("face.xml")
       if faces:
              for face in faces:
                     face.draw()
                     img.show()
if __name__ == "__main__":
main()

Advertisements