Skip to content

Instantly share code, notes, and snippets.

@llimllib
Created July 15, 2011 19:38
Show Gist options
  • Save llimllib/1085390 to your computer and use it in GitHub Desktop.
Save llimllib/1085390 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# recreate the Sobel edge video demo from http://morepypy.blogspot.com/2011/07/realtime-image-processing-in-python.html
# in regular python, using openCV's python bindings.
#
# here's a screenshot: https://skitch.com/llimllib/fkry5/test.py-vim1
#
# this is not meant to say anything about performance! I just think it's neat to run, and
# opencv makes it nice and simple to write. (It does run perfectly in real time, though. I
# didn't bother to count the FPS.)
from os.path import join
#On mac: brew install cv (and add to PYTHONPATH as prompted in "brew info cv")
import cv
capture = cv.CaptureFromCAM(0)
while (cv.WaitKey(15) == -1):
frame = cv.QueryFrame(capture)
i = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_16S, frame.nChannels)
cv.Sobel(frame, i, 1, 1, apertureSize=3)
#convert i to the same depth as frame?
out = cv.CreateImage(cv.GetSize(frame), frame.depth, frame.nChannels)
cv.ConvertScale(i, out)
cv.ShowImage("Sobel Test", out)
cv.ReleaseCapture(capture)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment