/* * tests removeRedundantContours() function */ void testRemoveRedundantContours(){ //test removing redundant contours with an image that should not have any contours after processing cv::Mat img = cv::imread("images/horizontal-lines.jpg", CV_LOAD_IMAGE_COLOR); assert(!img.empty()); //process for lines and contours cv::vector<cv::Vec4i> lines = imageProcessor.lineDetection(img); assert(!lines.empty()); cv::vector< cv::vector<cv::Point> > contours; cv::vector<cv::Vec4i> hierarchy; imageProcessor.contourDetection(img, contours, hierarchy); cv::vector< cv::vector<cv::Point> > valid_contours = imageProcessor.removeRedundantContours(contours, lines); assert((int)valid_contours.size() == 0); //empty vectors for 2nd test lines.clear(); contours.clear(); hierarchy.clear(); valid_contours.clear(); //test removing redundant contours with an image that will have valid contours after processing the image img = cv::imread("images/two2.png", CV_LOAD_IMAGE_COLOR); assert(!img.empty()); //process for lines and contours lines = imageProcessor.lineDetection(img); assert(!lines.empty()); imageProcessor.contourDetection(img, contours, hierarchy); valid_contours = imageProcessor.removeRedundantContours(contours, lines); assert((int)valid_contours.size() == 48); printf("removeRedundantContours() test passed.\n"); }
/* * tests the contourDetection() function */ void testContourDetection(){ cv::Mat img = cv::imread("images/two2.png", CV_LOAD_IMAGE_COLOR); assert(!img.empty()); cv::vector<cv::Vec4i> lines = imageProcessor.lineDetection(img); cv::vector< cv::vector<cv::Point> > contours; cv::vector<cv::Vec4i> hierarchy; imageProcessor.contourDetection(img, contours, hierarchy); assert(!contours.empty()); assert(!hierarchy.empty()); assert((int)contours.size() == 53); printf("contourDetection() test passed.\n"); }