Refactored code to use cv::Rects