memory fixes

This commit is contained in:
boyska 2017-01-12 16:25:29 +01:00
parent d1ba152d62
commit 9fdd4ebbb1
3 changed files with 9 additions and 6 deletions

View file

@ -15,7 +15,7 @@
// takes the two points that are more distant from the next, ie: // 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 // i st distance(hull[i], hull[i+1]) is maximum and 2nd maximum
int* max2_distance(std::vector<cv::Point> hull) unsigned* max2_distance(std::vector<cv::Point> hull)
{ {
#ifdef _DEBUG #ifdef _DEBUG
std::cout << "Hull = "; std::cout << "Hull = ";
@ -24,7 +24,7 @@ int* max2_distance(std::vector<cv::Point> hull)
} }
#endif #endif
std::cout << std::endl; std::cout << std::endl;
int *idx = (int*) calloc(2, sizeof(int)); unsigned *idx = (unsigned*) calloc(2, sizeof(int));
double distance[2] = {0}; double distance[2] = {0};
for( unsigned i=0; hull.size()>i; i++ ) for( unsigned i=0; hull.size()>i; i++ )
{ {

View file

@ -4,7 +4,7 @@
#include <opencv2/core/core.hpp> //Any Opencv2 code #include <opencv2/core/core.hpp> //Any Opencv2 code
#endif #endif
int* max2_distance(std::vector<cv::Point> hull); unsigned* max2_distance(std::vector<cv::Point> hull);
bool bool
similar_fit(cv::Point a, cv::Point b, cv::Point newpoint); similar_fit(cv::Point a, cv::Point b, cv::Point newpoint);

View file

@ -21,8 +21,6 @@ auto MAGENTA = cv::Scalar(110,10,200);
auto BROWN = cv::Scalar(90,100,60); auto BROWN = cv::Scalar(90,100,60);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char const *fname = "files/masckera.png"; char const *fname = "files/masckera.png";
@ -66,7 +64,7 @@ int main(int argc, char *argv[])
cv::convexHull(cv::Mat(contour),hull,false); cv::convexHull(cv::Mat(contour),hull,false);
//these are the "horizontal" lines //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; cv::Point corn_1, corn_2, corn_3, corn_4;
corn_1 = hull[maxdistances[0]]; corn_1 = hull[maxdistances[0]];
corn_2 = hull[(maxdistances[0]+1)%hull.size()]; corn_2 = hull[(maxdistances[0]+1)%hull.size()];
@ -88,7 +86,11 @@ int main(int argc, char *argv[])
std::vector<std::vector<cv::Point>> verticals; std::vector<std::vector<cv::Point>> verticals;
verticals.push_back(find_longest_line(hull, (maxdistances[0]+1)%hull.size(), maxdistances[1])); 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])); verticals.push_back(find_longest_line(hull, (maxdistances[1]+1)%hull.size(), maxdistances[0]));
free(maxdistances);
#ifdef _DEBUG #ifdef _DEBUG
//img = cv::imread(fname,CV_LOAD_IMAGE_COLOR); // uncomment to this to display image with colors //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 ) if( cv::waitKey(0) == 113 )
break; break;
} }
img.release();
#endif #endif
// theta is the angle of the line connecting point 1 and 2; it will be the // theta is the angle of the line connecting point 1 and 2; it will be the