OpenCV tips and tricks

  • Install:
  • sudo apt-get install libavformat-dev libavcodec-dev libavfilter-dev libswscale-dev
  • Download an compile OpenCV, it's better and it takes only a few minutes to compile.
  • OpenCV changed the API, all these examples that import "highgui" and "" and so are wrong! Now you have to use:
import cv
  • Problem capturing keys? waitKey() doesn't return strings or chars! instead it returns a that number you need to mask with 255:
 my_key = chr(cv.waitKey(10) & 255)

  • Cannot capture from your camera?

  • Install libv4l-dev before compiling in Ubuntu or your camera will not capture anything (empty window).
  • «if you only have one camera, or you don't care which camera is the correct one, then use "-1" as the index. Ie for your example capture = cv.CaptureFromCAM(-1).»

  • Use cv.CV_FOURCC() for getting the code for video codecs (en c++ it's a macro).

  • Load the classifiers (for face detection for example) using
classifier = cv.Load("/full/path/to/opencv/share/classifier.xml")
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply