Exception at memory location with opencv












2















I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:




Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.




Here's my code



   int main()
{

Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);

//applying the superpixel

Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);

slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();

cv::cvtColor(image, image, CV_BGR2RGB);

cv::cvtColor(image, Gray,CV_RGB2GRAY);

split(image, RGB);

Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);

int f = 150;
Mat Green1 = Green.clone();
int Y =0;

for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {

double N = labels.at<double>(Point(i, j));
if (N =! f)

Green1.at<double>(Point(i, j)) = 00000;

}
}

cv::imshow("green", Green1);

waitKey(0); // Wait for a keystroke in the window
return 0;
}









share|improve this question




















  • 1





    Have you debugged this? This is not enough for us to help you more than this.

    – Matthieu Brucher
    Nov 26 '18 at 10:50






  • 1





    i'll update my post and put all the code

    – ben mbarek Manef
    Nov 26 '18 at 10:53






  • 1





    What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.

    – Max Langhof
    Nov 26 '18 at 11:36






  • 1





    how can i show the exception ?!

    – ben mbarek Manef
    Nov 26 '18 at 12:00






  • 2





    The error is in this line Green1.at<double>(Point(i, j)) = 00000; first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0; note that at receives row, column in comparison of point that receives x,y

    – api55
    Nov 26 '18 at 12:03
















2















I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:




Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.




Here's my code



   int main()
{

Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);

//applying the superpixel

Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);

slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();

cv::cvtColor(image, image, CV_BGR2RGB);

cv::cvtColor(image, Gray,CV_RGB2GRAY);

split(image, RGB);

Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);

int f = 150;
Mat Green1 = Green.clone();
int Y =0;

for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {

double N = labels.at<double>(Point(i, j));
if (N =! f)

Green1.at<double>(Point(i, j)) = 00000;

}
}

cv::imshow("green", Green1);

waitKey(0); // Wait for a keystroke in the window
return 0;
}









share|improve this question




















  • 1





    Have you debugged this? This is not enough for us to help you more than this.

    – Matthieu Brucher
    Nov 26 '18 at 10:50






  • 1





    i'll update my post and put all the code

    – ben mbarek Manef
    Nov 26 '18 at 10:53






  • 1





    What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.

    – Max Langhof
    Nov 26 '18 at 11:36






  • 1





    how can i show the exception ?!

    – ben mbarek Manef
    Nov 26 '18 at 12:00






  • 2





    The error is in this line Green1.at<double>(Point(i, j)) = 00000; first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0; note that at receives row, column in comparison of point that receives x,y

    – api55
    Nov 26 '18 at 12:03














2












2








2








I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:




Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.




Here's my code



   int main()
{

Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);

//applying the superpixel

Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);

slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();

cv::cvtColor(image, image, CV_BGR2RGB);

cv::cvtColor(image, Gray,CV_RGB2GRAY);

split(image, RGB);

Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);

int f = 150;
Mat Green1 = Green.clone();
int Y =0;

for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {

double N = labels.at<double>(Point(i, j));
if (N =! f)

Green1.at<double>(Point(i, j)) = 00000;

}
}

cv::imshow("green", Green1);

waitKey(0); // Wait for a keystroke in the window
return 0;
}









share|improve this question
















I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:




Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.




Here's my code



   int main()
{

Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);

//applying the superpixel

Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);

slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();

cv::cvtColor(image, image, CV_BGR2RGB);

cv::cvtColor(image, Gray,CV_RGB2GRAY);

split(image, RGB);

Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);

int f = 150;
Mat Green1 = Green.clone();
int Y =0;

for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {

double N = labels.at<double>(Point(i, j));
if (N =! f)

Green1.at<double>(Point(i, j)) = 00000;

}
}

cv::imshow("green", Green1);

waitKey(0); // Wait for a keystroke in the window
return 0;
}






c++ visual-studio opencv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 11:00









JBL

9,74333767




9,74333767










asked Nov 26 '18 at 10:49









ben mbarek Manefben mbarek Manef

256




256








  • 1





    Have you debugged this? This is not enough for us to help you more than this.

    – Matthieu Brucher
    Nov 26 '18 at 10:50






  • 1





    i'll update my post and put all the code

    – ben mbarek Manef
    Nov 26 '18 at 10:53






  • 1





    What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.

    – Max Langhof
    Nov 26 '18 at 11:36






  • 1





    how can i show the exception ?!

    – ben mbarek Manef
    Nov 26 '18 at 12:00






  • 2





    The error is in this line Green1.at<double>(Point(i, j)) = 00000; first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0; note that at receives row, column in comparison of point that receives x,y

    – api55
    Nov 26 '18 at 12:03














  • 1





    Have you debugged this? This is not enough for us to help you more than this.

    – Matthieu Brucher
    Nov 26 '18 at 10:50






  • 1





    i'll update my post and put all the code

    – ben mbarek Manef
    Nov 26 '18 at 10:53






  • 1





    What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.

    – Max Langhof
    Nov 26 '18 at 11:36






  • 1





    how can i show the exception ?!

    – ben mbarek Manef
    Nov 26 '18 at 12:00






  • 2





    The error is in this line Green1.at<double>(Point(i, j)) = 00000; first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0; note that at receives row, column in comparison of point that receives x,y

    – api55
    Nov 26 '18 at 12:03








1




1





Have you debugged this? This is not enough for us to help you more than this.

– Matthieu Brucher
Nov 26 '18 at 10:50





Have you debugged this? This is not enough for us to help you more than this.

– Matthieu Brucher
Nov 26 '18 at 10:50




1




1





i'll update my post and put all the code

– ben mbarek Manef
Nov 26 '18 at 10:53





i'll update my post and put all the code

– ben mbarek Manef
Nov 26 '18 at 10:53




1




1





What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.

– Max Langhof
Nov 26 '18 at 11:36





What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.

– Max Langhof
Nov 26 '18 at 11:36




1




1





how can i show the exception ?!

– ben mbarek Manef
Nov 26 '18 at 12:00





how can i show the exception ?!

– ben mbarek Manef
Nov 26 '18 at 12:00




2




2





The error is in this line Green1.at<double>(Point(i, j)) = 00000; first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0; note that at receives row, column in comparison of point that receives x,y

– api55
Nov 26 '18 at 12:03





The error is in this line Green1.at<double>(Point(i, j)) = 00000; first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0; note that at receives row, column in comparison of point that receives x,y

– api55
Nov 26 '18 at 12:03












1 Answer
1






active

oldest

votes


















2














You have problems with the types of the image. When you load an image in OpenCV using:



image = imread(filename, CV_LOAD_IMAGE_COLOR);


it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:



Green1.at<double>(Point(i, j)) = 00000;


which should be:



Green1.at<uchar>(j,i) = 0;


Note that also Point(i,j) is not needed and can be replaced by j,i.



The .at<type>(row, column) function is more or less equivalent to do:



Mat test;
type* data = reinterpret_cast<type*>(test.data);
data[row][column];




You also have a problem in:



double N = labels.at<double>(Point(i, j));


but labels it is assign by



slic->getLabels(labels);


which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.



Then this should be :



int N = labels.at<int>(j,i);




Finally:



this



Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);


should be:



Red = RGB[0];
Green = RGB[1];
Blue = RGB[2];





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479495%2fexception-at-memory-location-with-opencv%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You have problems with the types of the image. When you load an image in OpenCV using:



    image = imread(filename, CV_LOAD_IMAGE_COLOR);


    it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:



    Green1.at<double>(Point(i, j)) = 00000;


    which should be:



    Green1.at<uchar>(j,i) = 0;


    Note that also Point(i,j) is not needed and can be replaced by j,i.



    The .at<type>(row, column) function is more or less equivalent to do:



    Mat test;
    type* data = reinterpret_cast<type*>(test.data);
    data[row][column];




    You also have a problem in:



    double N = labels.at<double>(Point(i, j));


    but labels it is assign by



    slic->getLabels(labels);


    which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.



    Then this should be :



    int N = labels.at<int>(j,i);




    Finally:



    this



    Red.push_back(RGB[0]);
    Green.push_back(RGB[1]);
    Blue.push_back(RGB[2]);


    should be:



    Red = RGB[0];
    Green = RGB[1];
    Blue = RGB[2];





    share|improve this answer




























      2














      You have problems with the types of the image. When you load an image in OpenCV using:



      image = imread(filename, CV_LOAD_IMAGE_COLOR);


      it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:



      Green1.at<double>(Point(i, j)) = 00000;


      which should be:



      Green1.at<uchar>(j,i) = 0;


      Note that also Point(i,j) is not needed and can be replaced by j,i.



      The .at<type>(row, column) function is more or less equivalent to do:



      Mat test;
      type* data = reinterpret_cast<type*>(test.data);
      data[row][column];




      You also have a problem in:



      double N = labels.at<double>(Point(i, j));


      but labels it is assign by



      slic->getLabels(labels);


      which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.



      Then this should be :



      int N = labels.at<int>(j,i);




      Finally:



      this



      Red.push_back(RGB[0]);
      Green.push_back(RGB[1]);
      Blue.push_back(RGB[2]);


      should be:



      Red = RGB[0];
      Green = RGB[1];
      Blue = RGB[2];





      share|improve this answer


























        2












        2








        2







        You have problems with the types of the image. When you load an image in OpenCV using:



        image = imread(filename, CV_LOAD_IMAGE_COLOR);


        it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:



        Green1.at<double>(Point(i, j)) = 00000;


        which should be:



        Green1.at<uchar>(j,i) = 0;


        Note that also Point(i,j) is not needed and can be replaced by j,i.



        The .at<type>(row, column) function is more or less equivalent to do:



        Mat test;
        type* data = reinterpret_cast<type*>(test.data);
        data[row][column];




        You also have a problem in:



        double N = labels.at<double>(Point(i, j));


        but labels it is assign by



        slic->getLabels(labels);


        which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.



        Then this should be :



        int N = labels.at<int>(j,i);




        Finally:



        this



        Red.push_back(RGB[0]);
        Green.push_back(RGB[1]);
        Blue.push_back(RGB[2]);


        should be:



        Red = RGB[0];
        Green = RGB[1];
        Blue = RGB[2];





        share|improve this answer













        You have problems with the types of the image. When you load an image in OpenCV using:



        image = imread(filename, CV_LOAD_IMAGE_COLOR);


        it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:



        Green1.at<double>(Point(i, j)) = 00000;


        which should be:



        Green1.at<uchar>(j,i) = 0;


        Note that also Point(i,j) is not needed and can be replaced by j,i.



        The .at<type>(row, column) function is more or less equivalent to do:



        Mat test;
        type* data = reinterpret_cast<type*>(test.data);
        data[row][column];




        You also have a problem in:



        double N = labels.at<double>(Point(i, j));


        but labels it is assign by



        slic->getLabels(labels);


        which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.



        Then this should be :



        int N = labels.at<int>(j,i);




        Finally:



        this



        Red.push_back(RGB[0]);
        Green.push_back(RGB[1]);
        Blue.push_back(RGB[2]);


        should be:



        Red = RGB[0];
        Green = RGB[1];
        Blue = RGB[2];






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 12:25









        api55api55

        6,86532543




        6,86532543
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479495%2fexception-at-memory-location-with-opencv%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks