From 9fdd4ebbb1afada6190c9e8a717495fc42abed7b Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 12 Jan 2017 16:25:29 +0100 Subject: [PATCH] memory fixes --- cvutils.cpp | 4 ++-- cvutils.h | 2 +- lines.cpp | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cvutils.cpp b/cvutils.cpp index c305c45..3c26fec 100644 --- a/cvutils.cpp +++ b/cvutils.cpp @@ -15,7 +15,7 @@ // takes the two points that are more distant from the next, ie: // i st distance(hull[i], hull[i+1]) is maximum and 2nd maximum -int* max2_distance(std::vector hull) +unsigned* max2_distance(std::vector hull) { #ifdef _DEBUG std::cout << "Hull = "; @@ -24,7 +24,7 @@ int* max2_distance(std::vector hull) } #endif std::cout << std::endl; - int *idx = (int*) calloc(2, sizeof(int)); + unsigned *idx = (unsigned*) calloc(2, sizeof(int)); double distance[2] = {0}; for( unsigned i=0; hull.size()>i; i++ ) { diff --git a/cvutils.h b/cvutils.h index 7f626dd..de44b26 100644 --- a/cvutils.h +++ b/cvutils.h @@ -4,7 +4,7 @@ #include //Any Opencv2 code #endif -int* max2_distance(std::vector hull); +unsigned* max2_distance(std::vector hull); bool similar_fit(cv::Point a, cv::Point b, cv::Point newpoint); diff --git a/lines.cpp b/lines.cpp index fb4d973..d2954e7 100644 --- a/lines.cpp +++ b/lines.cpp @@ -21,8 +21,6 @@ auto MAGENTA = cv::Scalar(110,10,200); auto BROWN = cv::Scalar(90,100,60); - - int main(int argc, char *argv[]) { char const *fname = "files/masckera.png"; @@ -66,7 +64,7 @@ int main(int argc, char *argv[]) cv::convexHull(cv::Mat(contour),hull,false); //these are the "horizontal" lines - int *maxdistances = max2_distance(hull); + unsigned *maxdistances = max2_distance(hull); cv::Point corn_1, corn_2, corn_3, corn_4; corn_1 = hull[maxdistances[0]]; corn_2 = hull[(maxdistances[0]+1)%hull.size()]; @@ -88,7 +86,11 @@ int main(int argc, char *argv[]) std::vector> verticals; verticals.push_back(find_longest_line(hull, (maxdistances[0]+1)%hull.size(), maxdistances[1])); + std::cout << maxdistances[1] << std::endl; + std::cout << maxdistances[1]+1 << std::endl; + std::cout << (maxdistances[1]+1)%hull.size() << std::endl; verticals.push_back(find_longest_line(hull, (maxdistances[1]+1)%hull.size(), maxdistances[0])); + free(maxdistances); #ifdef _DEBUG //img = cv::imread(fname,CV_LOAD_IMAGE_COLOR); // uncomment to this to display image with colors @@ -111,6 +113,7 @@ int main(int argc, char *argv[]) if( cv::waitKey(0) == 113 ) break; } + img.release(); #endif // theta is the angle of the line connecting point 1 and 2; it will be the