findContours doesnt work after the code is transferred to another machine?

asked 2018-05-07 15:57:13 -0500

minh gravatar image

Im currently working on a lane detect project and it required detecting contour. The code im using will detect a number of contour on the image and return their center in a vector of a vector of points (std::vector<std::vector<Point> >) work perfectly fine on my laptop but when i send that project to Mat roi; roi = src(Rect(vect[0], vect[1], vect[2], vect[3]));another machine it was able to find the contour but when i checked every contours only contain 2 points and those point position is Nan type.

This is basically what i did:

first i get input image (8U3C), then cropped it

int vect[] = {0,45,160,75};
Mat roi;
roi = src(Rect(vect[0], vect[1], vect[2], vect[3]));

Next, covert it into gray and filterBinary it


Then i take that binary image and use findcontour on it

        std::vector<std::vector<Point> > cnts;
       std::vector<Point> res;
        findContours(input[i],cnts,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
        int cntsN = cnts.size();
        if (cntsN == 0) {
               cout << "empty";

        for (int j = 0; j < cntsN; j++) {
            int area = contourArea(cnts[j],false);
            if (area > 3) {
                Moments M1 = moments(cnts[j],false);
                Point2f center1 = Point2f( static_cast<float>(M1.m10/M1.m00) , static_cast<float>(M1.m01/M1.m00) );
                center1.y = center1.y + SLIDETHICKNESS*i;
                if (center1.x >0 && center1.y >0) {

what i get from cnts is couple of contours but only contain 2 Points and area = 0.

edit retag flag offensive close merge delete


Opencv version? platform? compiler?

LBerger gravatar imageLBerger ( 2018-05-08 03:42:16 -0500 )edit

Im not sure about the version on my jetson but mine is 3.4, platform ubuntu coding on netbean and compile with Cmake.

minh gravatar imageminh ( 2018-05-08 19:25:11 -0500 )edit

Do you transfer source code or executable file?

Is it exactly same image (Have you got a test image)?

Why do you use CV_RGB2GRAY ? and notBGR2GRAY?

threshold(input,input,FILTERCONTROL,255,THRESH_BINARY); and findContours(input[i],cnts,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); input[i]?

You can get version using getbuildInformation()

LBerger gravatar imageLBerger ( 2018-05-09 01:38:02 -0500 )edit