Here https://gist.github.com/3505250 you can find a simple snippet by me.
Using OpenCV libraries this code allow to detect the edge of an image or frame with Canny filter ( http://en.wikipedia.org/wiki/Canny_edge_detector )
This is a screenshot of result.
You can compile it with:
g++ 'pkg-config --cflags --libs opencv' source.c -o binary