Ask Your Question
-1

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

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

zao93 gravatar image

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

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

    }
}
edit retag flag offensive close merge delete

Comments

you forgot the error msg

berak gravatar imageberak ( 2019-03-29 02:22:12 -0600 )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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

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

berak gravatar image

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

..... 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

Comments

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

zao93 gravatar imagezao93 ( 2019-04-08 00:17:43 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 165 times

Last updated: Mar 30 '19