a sample code from OpenCV official site