Modified to work with OpenCV 2.3