refactoring cv2.cpp