switch to cv2 API and remove some unused code