Ask Your Question

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

asked 2019-03-28 21:56:15 -0500

zao93 gravatar image

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

berak gravatar image


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);

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

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

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

        //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);

        //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);

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

edit retag flag offensive close merge delete


you forgot the error msg

berak gravatar imageberak ( 2019-03-29 02:22:12 -0500 )edit

Unhandled exception at 0x00007FF8B035A388 in exudate.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000EDDAB8D0F0.

zao93 gravatar imagezao93 ( 2019-04-08 00:20:50 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-29 03:59:27 -0500

berak gravatar image

updated 2019-03-30 03:39:26 -0500

..... is not a valid path your image was never loaded, and you have to CHECK if imread actually returned a valid image:

  image = imread(some_invalid_path);
  if (image.empty())
       // you can't go on !

then, if you load a grayscale (single channel) image, you cannot split() it into 3 channels.

edit flag offensive delete link more


Actually the '........' is my correct path, i just edited it before upload the code here.

zao93 gravatar imagezao93 ( 2019-04-08 00:17:43 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-03-28 21:53:44 -0500

Seen: 44 times

Last updated: Mar 30