Skip to content

Instantly share code, notes, and snippets.

@mdengler
Created May 28, 2012 05:01
Show Gist options
  • Save mdengler/2817318 to your computer and use it in GitHub Desktop.
Save mdengler/2817318 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# See https://github.com/Elleo/gst-opencv/blob/master/examples/python/facedetect.py
# See also http://blog.mikeasoft.com/2010/06/17/gstreamer-opencv-plugins-on-the-nokia-n900/
import pygst
pygst.require("0.10")
import gst
import gtk
class FaceDetect:
def __init__(self):
pipe = """autovideosrc ! decodebin ! ffmpegcolorspace ! facedetect profile=/usr/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml ! fakesink"""
self.pipeline = gst.parse_launch(pipe)
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect("message::element", self.bus_message)
self.pipeline.set_state(gst.STATE_PLAYING)
def bus_message(self, bus, message):
st = message.structure
if st.get_name() == "face":
print "Face found at %d,%d with dimensions %dx%d" % (st["x"], st["y"], st["width"], st["height"])
if __name__ == "__main__":
f = FaceDetect()
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment