Skip to main content

Posts

Showing posts with the label pygame

Bring your hat!

So thought I would make a really simple example of how pygame can be used with a webcam. This example uses opencv to detect a face, then pygame to draw a "hat". #!/usr/bin/python from pycam import VideoCapturePlayer from pycam import pygameFaceDetect import pygame from pygame.locals import * def process(surf): faces = pygameFaceDetect.getFaces(surf) if faces: s = pygameFaceDetect.faceDetect.image_scale for face in faces: pointsInHat = [ (face.x*s, face.y*s), (face.x*s + face.width*s, face.y*s), (face.x*s + face.width*s/2, face.y*s - face.height*s/2 ) ] pygame.draw.polygon(surf, Color("red"), pointsInHat) pygame.draw.polygon(surf, Color("black"), pointsInHat, 10) return surf if __name__ == "__main__": vcp = VideoCapturePlayer(processFunction=process) vcp.main() pygame.quit() And the obligatory screen shot: ...

Windows + Pygame + VidCap

So I thought I would try out the pycam module on windows. First of all it seems windows comes with nothing, not even python. So after installing python I still needed this: http://videocapture.sourceforge.net/ and this: http://pygame.org/ftp/pygame-1.9.1.win32-py2.5.msi Vid cap itself is so easy: from VideoCapture import Device cam = Device() cam.saveSnapshot('image.jpg') To get just the most basic stuff going, for some reason the VidCap module wouldn't let me open a camera unless the size was set at (160, 120) and the Camera class seemed to change going to windows... anyhow if you want to play with this grab it from the repo here . This is using the pygame edge detect, just tried the scipy one - appears to be a problem mapping surface to numpy array... from memory there was a hack to get around something so maybe thats no longer required. The "greenscreen" example and the simple threshold. Couldn't immediatly see how to get the python wrappings for swig going...

Eye Locating

Image capturing is happening with the pygame.camera module. Object Detection is using an ObjectDetect class I wrote that wraps the cvHaarDetectObject from the opencv library. Just for fun the green box is drawn with pygame, the Red boxes are drawn with opencv. And the whole thing is rendered with pygame.

Project makes it to the intertubes...

Well I have finally put my code into a repository. It's all open source. I listed it on pygame.org and it went to the front page automatically which was cool! You can find my project at http://www.pycam.googlecode.com The pygame project page is: http://pygame.org/project/1111/

Face Detection with python using opencv

So I have been continuing on with the live edge detection I looked out a few weeks ago... I have made that code alot more object oriented and hopefully re-useable. I am now using both pygame and opencv built from svn instead of the ubuntu repositories. I wanted independence in the image rendering, the webcam capturing and the image processing. So I needed to convert between a numpy array (which pygame and any scipy processing uses) and cvMat which is opencv's data type. This was not immediately obvious as the opencv.adaptors module was full of routines for converting via the Python Image Library (PIL). These images were annoyingly being rotated by the functions when going from numpy to cvMat, then rotated back to the correct way going back from cvMat to numpy. First up is the VideoCapturePlayer class, it can be used to simply display a video feed. It uses pygame camera, stores the images as a pygame.surface and shows the video with pygame. The latest pygame has an option to force ...