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 "cv2.cv" 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)

http://stackoverflow.com/questions/9172170/python-opencv-cv-waitkey-spits-back-weird-output-on-ubuntu-modulo-256-maps-corre

  • Cannot capture from your camera?

http://stackoverflow.com/questions/4749498/cant-access-webcam-with-opencv

  • 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).»

http://stackoverflow.com/questions/2601194/displaying-webcam-feed-using-opencv-and-python

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

http://stackoverflow.com/questions/5426637/writing-video-with-opencv-python-mac

  • 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