From 229afbc68a5bcb28d04406a645cd06a48cf6e3a2 Mon Sep 17 00:00:00 2001 From: g-spacewhale <17550607+g-spacewhale@users.noreply.github.com> Date: Fri, 19 Jan 2018 16:12:45 +0100 Subject: [PATCH] added better visualization --- Source/functions/solve/puzzleExtension.cpp | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index af6082d..84de8d3 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -6,9 +6,9 @@ typedef std::vector> Contour_t; typedef std::vector Hierarchy_t; //hierarchy object is needed for drawContours apparently - Mat crop2ContourInv(const Mat & img); Contour_t getLongestContour(Mat bw); +int getLongestContourIndex(Contour_t contours); void Puzzle::printPuzzle() { @@ -131,7 +131,7 @@ Mat Puzzle::readImage(int fileIndex, const char* inputDir){ Mat source = imread(inputstr,1); return source; } -Mat Puzzle::resultImage_for_merging( vector& log){ +Mat Puzzle::resultImage( vector& log){ int Y_size = 1200; // chose this to fit your monitor! int separator = 1; int partHeight = 90; @@ -189,7 +189,7 @@ Mat Puzzle::resultImage_for_merging( vector& log){ center.x = img.cols/2; center.y = img.rows/2; Mat RotMatrix = getRotationMatrix2D(center,angle,1); - warpAffine(img,img,RotMatrix, img.size()); + warpAffine(invert,invert,RotMatrix, invert.size()); bitwise_not(invert,img); Mat cropped = crop2ContourInv(img); auto ROI_X = int(round(it.myCoor.col*partWidth)); @@ -220,12 +220,7 @@ Mat crop2ContourInv(const Mat & img){ // for white background images return cropped; } -Contour_t getLongestContour(Mat bw){ - - Mat mask = Mat::zeros(bw.size(), CV_8UC1); - Hierarchy_t hierarchy; - Contour_t contours; - findContours(bw, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); +int getLongestContourIndex(Contour_t contours){ double area = 0; double largestArea = 0; size_t largestIndex = 0; @@ -238,12 +233,5 @@ Contour_t getLongestContour(Mat bw){ largestIndex = i; // i is type size_t, should be converted to int. } } - - Contour_t largestContour; - largestContour.resize(contours.size()); //Otherwise it is just a null pointer and the program crashes! - size_t index = 0; - int strength = 2; // distance between the original contour and the approximated contour - approxPolyDP(Mat(contours[largestIndex]), largestContour[index], strength, true); - return(largestContour); -} - + return(largestIndex); +} \ No newline at end of file