OpenCV exercise from OpenCV book