Ask Your Question

Revision history [back]

Why 'resize' become error after looping function was added?

char * filepath = new char[100]; for (int j = 0; j<100; j++) // for all images { sprintf(filepath, ".....pic", j); // changing the path Mat src = imread(filepath, CV_LOAD_IMAGE_GRAYSCALE);

    //load source image
    //Mat src = imread(".....IDRiD_001.jpg", 1);
    //imshow("source", src);
    //imwrite(".....1source.jpg", src);
    //cvWaitKey(5000);

    //resize source image
    Mat resized;
    int ColumnOfNewImage = 720;
    int RowsOfNewImage = 480;
    resize(src, resized, Size(ColumnOfNewImage, RowsOfNewImage));
    //imshow("source", resized);
    imwrite(".....1source.jpg", resized);
    cvWaitKey(1000);

    //rgb to green channel image
    Mat bgr[3];
    split(resized, bgr);
    Mat green = bgr[1];
    //imshow("2green", green);
    imwrite(".....2green.jpg", green);
    cvWaitKey(1000);

    //invert the green channel
    Mat green_inv;
    bitwise_not(green, green_inv);
    //imshow("2green_inv", green_inv);
    imwrite(".....3green_inv.jpg", green_inv);
    cvWaitKey(1000);

    //morphology tophat
    Mat tophat;
    Mat element = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
    morphologyEx(green_inv, tophat, MORPH_TOPHAT, element, Point(-1, -1), 9);
    //imshow("3tophat", tophat);
    imwrite(".....4tophat.jpg", tophat);
    cvWaitKey(1000);

    //morphology closing
    Mat closing;
    Mat element2 = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
    morphologyEx(tophat, closing, MORPH_CLOSE, element2, Point(-1, -1));
    //imshow("4closing", closing);
    imwrite(".....5closing.jpg", closing);
    cvWaitKey(1000);

    //threshold the image
    Mat thr;
    threshold(closing, thr, 40, 255, THRESH_BINARY);
    //imshow("5threshold", thr);
    imwrite(".....6threshold.jpg", thr);
    cvWaitKey(5000);

}

}

click to hide/show revision 2
None

updated 2019-03-29 01:54:13 -0600

berak gravatar image

Why 'resize' become error after looping function was added?

char * filepath = new char[100]; for (int j = 0; j<100; j++) // for all images { sprintf(filepath, ".....pic", j); // changing the path Mat src = imread(filepath, CV_LOAD_IMAGE_GRAYSCALE);

  //load source image
     //Mat src = imread(".....IDRiD_001.jpg", 1);
     //imshow("source", src);
     //imwrite(".....1source.jpg", src);
     //cvWaitKey(5000);

     //resize source image
     Mat resized;
     int ColumnOfNewImage = 720;
     int RowsOfNewImage = 480;
     resize(src, resized, Size(ColumnOfNewImage, RowsOfNewImage));
     //imshow("source", resized);
     imwrite(".....1source.jpg", resized);
     cvWaitKey(1000);

     //rgb to green channel image
     Mat bgr[3];
     split(resized, bgr);
     Mat green = bgr[1];
     //imshow("2green", green);
     imwrite(".....2green.jpg", green);
     cvWaitKey(1000);

     //invert the green channel
     Mat green_inv;
     bitwise_not(green, green_inv);
     //imshow("2green_inv", green_inv);
     imwrite(".....3green_inv.jpg", green_inv);
     cvWaitKey(1000);

     //morphology tophat
     Mat tophat;
     Mat element = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
     morphologyEx(green_inv, tophat, MORPH_TOPHAT, element, Point(-1, -1), 9);
     //imshow("3tophat", tophat);
     imwrite(".....4tophat.jpg", tophat);
     cvWaitKey(1000);

     //morphology closing
     Mat closing;
     Mat element2 = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
     morphologyEx(tophat, closing, MORPH_CLOSE, element2, Point(-1, -1));
     //imshow("4closing", closing);
     imwrite(".....5closing.jpg", closing);
     cvWaitKey(1000);

     //threshold the image
     Mat thr;
     threshold(closing, thr, 40, 255, THRESH_BINARY);
     //imshow("5threshold", thr);
     imwrite(".....6threshold.jpg", thr);
     cvWaitKey(5000);

    }
}

}

click to hide/show revision 3
None

updated 2019-03-29 02:21:50 -0600

berak gravatar image

Why 'resize' become error after looping function was added?

.

char * filepath = new char[100];
     for (int j = 0; j<100; j++) // for all images
     {
         sprintf(filepath, ".....pic", j); // changing the path
         Mat src = imread(filepath, CV_LOAD_IMAGE_GRAYSCALE);

CV_LOAD_IMAGE_GRAYSCALE);

        //load source image
        //Mat src = imread(".....IDRiD_001.jpg", 1);
        //imshow("source", src);
        //imwrite(".....1source.jpg", src);
        //cvWaitKey(5000);

        //resize source image
        Mat resized;
        int ColumnOfNewImage = 720;
        int RowsOfNewImage = 480;
        resize(src, resized, Size(ColumnOfNewImage, RowsOfNewImage));
        //imshow("source", resized);
        imwrite(".....1source.jpg", resized);
        cvWaitKey(1000);

        //rgb to green channel image
        Mat bgr[3];
        split(resized, bgr);
        Mat green = bgr[1];
        //imshow("2green", green);
        imwrite(".....2green.jpg", green);
        cvWaitKey(1000);

        //invert the green channel
        Mat green_inv;
        bitwise_not(green, green_inv);
        //imshow("2green_inv", green_inv);
        imwrite(".....3green_inv.jpg", green_inv);
        cvWaitKey(1000);

        //morphology tophat
        Mat tophat;
        Mat element = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
        morphologyEx(green_inv, tophat, MORPH_TOPHAT, element, Point(-1, -1), 9);
        //imshow("3tophat", tophat);
        imwrite(".....4tophat.jpg", tophat);
        cvWaitKey(1000);

        //morphology closing
        Mat closing;
        Mat element2 = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
        morphologyEx(tophat, closing, MORPH_CLOSE, element2, Point(-1, -1));
        //imshow("4closing", closing);
        imwrite(".....5closing.jpg", closing);
        cvWaitKey(1000);

        //threshold the image
        Mat thr;
        threshold(closing, thr, 40, 255, THRESH_BINARY);
        //imshow("5threshold", thr);
        imwrite(".....6threshold.jpg", thr);
        cvWaitKey(5000);

    }
}