Revised the code according to the feedback of OpenCV community.