code reorganization, use OpenCV