C++ OpenCV Mat pixel value and Opencv Errors





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am writing a simple c++ application using visual studio and opencv that stores Red, Green and Blue values from an image(named src in the code) and stores each Red, Green, Blue pixel values individually in 3 different Mat objects(named RM,BM,GM in the code). I saw this stackOverflow question
and did exactly as the first answer explained. I was able to save all the pixel values just fine, but wasn't able to change pixel values of other images because an Abort() has been called. This is the console window after I run the code.
Console Window



#include<opencv2/core.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include <stdio.h>
using namespace cv;
using namespace std;
int main() {
String file_name = "C:\images\haaand.jpg";
Mat src;
Mat RM, BM, GM;
//RM.create(src.cols, src.rows, CV_8UC(2));
//BM.create(src.cols, src.rows, CV_8UC(2));
//GM.create(src.cols, src.rows, CV_8UC(2));
Vec3b intensity;
Vec3b To[3];
src = imread(file_name);
imshow("src", src);
printf("cols:%d rows:%d n", src.cols, src.rows);
for (int i = 0; i < src.cols; i++) {
for (int j = 0; j < src.rows; j++) {
intensity = src.at<Vec3b>(j, i);
printf("intensity:%d %d %d n", intensity[0], intensity[1], intensity[2]);
for (int k = 0; k < 3; k++) {
//uchar bla;
//bla = intensity[k];
for (int p = 0; p < 3; p++) {
To[k][p] = intensity[k];
}
printf("(k:%d) %d %d %dn", k, To[k][0], To[k][1], To[k][2]);
}
printf("all donen");
BM.at<Vec3b>(j, i) = To[0];
GM.at<Vec3b>(j, i) = To[1];
RM.at<Vec3b>(j, i) = To[2];
}
}
imshow("RM", RM);
imshow("BM", BM);
imshow("GM", GM);
return 0;
}


Could anyone tell me why why this error might happen?










share|improve this question





























    1















    I am writing a simple c++ application using visual studio and opencv that stores Red, Green and Blue values from an image(named src in the code) and stores each Red, Green, Blue pixel values individually in 3 different Mat objects(named RM,BM,GM in the code). I saw this stackOverflow question
    and did exactly as the first answer explained. I was able to save all the pixel values just fine, but wasn't able to change pixel values of other images because an Abort() has been called. This is the console window after I run the code.
    Console Window



    #include<opencv2/core.hpp>
    #include<opencv2/highgui.hpp>
    #include<opencv2/imgproc.hpp>
    #include <stdio.h>
    using namespace cv;
    using namespace std;
    int main() {
    String file_name = "C:\images\haaand.jpg";
    Mat src;
    Mat RM, BM, GM;
    //RM.create(src.cols, src.rows, CV_8UC(2));
    //BM.create(src.cols, src.rows, CV_8UC(2));
    //GM.create(src.cols, src.rows, CV_8UC(2));
    Vec3b intensity;
    Vec3b To[3];
    src = imread(file_name);
    imshow("src", src);
    printf("cols:%d rows:%d n", src.cols, src.rows);
    for (int i = 0; i < src.cols; i++) {
    for (int j = 0; j < src.rows; j++) {
    intensity = src.at<Vec3b>(j, i);
    printf("intensity:%d %d %d n", intensity[0], intensity[1], intensity[2]);
    for (int k = 0; k < 3; k++) {
    //uchar bla;
    //bla = intensity[k];
    for (int p = 0; p < 3; p++) {
    To[k][p] = intensity[k];
    }
    printf("(k:%d) %d %d %dn", k, To[k][0], To[k][1], To[k][2]);
    }
    printf("all donen");
    BM.at<Vec3b>(j, i) = To[0];
    GM.at<Vec3b>(j, i) = To[1];
    RM.at<Vec3b>(j, i) = To[2];
    }
    }
    imshow("RM", RM);
    imshow("BM", BM);
    imshow("GM", GM);
    return 0;
    }


    Could anyone tell me why why this error might happen?










    share|improve this question

























      1












      1








      1








      I am writing a simple c++ application using visual studio and opencv that stores Red, Green and Blue values from an image(named src in the code) and stores each Red, Green, Blue pixel values individually in 3 different Mat objects(named RM,BM,GM in the code). I saw this stackOverflow question
      and did exactly as the first answer explained. I was able to save all the pixel values just fine, but wasn't able to change pixel values of other images because an Abort() has been called. This is the console window after I run the code.
      Console Window



      #include<opencv2/core.hpp>
      #include<opencv2/highgui.hpp>
      #include<opencv2/imgproc.hpp>
      #include <stdio.h>
      using namespace cv;
      using namespace std;
      int main() {
      String file_name = "C:\images\haaand.jpg";
      Mat src;
      Mat RM, BM, GM;
      //RM.create(src.cols, src.rows, CV_8UC(2));
      //BM.create(src.cols, src.rows, CV_8UC(2));
      //GM.create(src.cols, src.rows, CV_8UC(2));
      Vec3b intensity;
      Vec3b To[3];
      src = imread(file_name);
      imshow("src", src);
      printf("cols:%d rows:%d n", src.cols, src.rows);
      for (int i = 0; i < src.cols; i++) {
      for (int j = 0; j < src.rows; j++) {
      intensity = src.at<Vec3b>(j, i);
      printf("intensity:%d %d %d n", intensity[0], intensity[1], intensity[2]);
      for (int k = 0; k < 3; k++) {
      //uchar bla;
      //bla = intensity[k];
      for (int p = 0; p < 3; p++) {
      To[k][p] = intensity[k];
      }
      printf("(k:%d) %d %d %dn", k, To[k][0], To[k][1], To[k][2]);
      }
      printf("all donen");
      BM.at<Vec3b>(j, i) = To[0];
      GM.at<Vec3b>(j, i) = To[1];
      RM.at<Vec3b>(j, i) = To[2];
      }
      }
      imshow("RM", RM);
      imshow("BM", BM);
      imshow("GM", GM);
      return 0;
      }


      Could anyone tell me why why this error might happen?










      share|improve this question














      I am writing a simple c++ application using visual studio and opencv that stores Red, Green and Blue values from an image(named src in the code) and stores each Red, Green, Blue pixel values individually in 3 different Mat objects(named RM,BM,GM in the code). I saw this stackOverflow question
      and did exactly as the first answer explained. I was able to save all the pixel values just fine, but wasn't able to change pixel values of other images because an Abort() has been called. This is the console window after I run the code.
      Console Window



      #include<opencv2/core.hpp>
      #include<opencv2/highgui.hpp>
      #include<opencv2/imgproc.hpp>
      #include <stdio.h>
      using namespace cv;
      using namespace std;
      int main() {
      String file_name = "C:\images\haaand.jpg";
      Mat src;
      Mat RM, BM, GM;
      //RM.create(src.cols, src.rows, CV_8UC(2));
      //BM.create(src.cols, src.rows, CV_8UC(2));
      //GM.create(src.cols, src.rows, CV_8UC(2));
      Vec3b intensity;
      Vec3b To[3];
      src = imread(file_name);
      imshow("src", src);
      printf("cols:%d rows:%d n", src.cols, src.rows);
      for (int i = 0; i < src.cols; i++) {
      for (int j = 0; j < src.rows; j++) {
      intensity = src.at<Vec3b>(j, i);
      printf("intensity:%d %d %d n", intensity[0], intensity[1], intensity[2]);
      for (int k = 0; k < 3; k++) {
      //uchar bla;
      //bla = intensity[k];
      for (int p = 0; p < 3; p++) {
      To[k][p] = intensity[k];
      }
      printf("(k:%d) %d %d %dn", k, To[k][0], To[k][1], To[k][2]);
      }
      printf("all donen");
      BM.at<Vec3b>(j, i) = To[0];
      GM.at<Vec3b>(j, i) = To[1];
      RM.at<Vec3b>(j, i) = To[2];
      }
      }
      imshow("RM", RM);
      imshow("BM", BM);
      imshow("GM", GM);
      return 0;
      }


      Could anyone tell me why why this error might happen?







      c++ opencv






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 14:52









      andrewsonchaandrewsoncha

      84




      84
























          1 Answer
          1






          active

          oldest

          votes


















          0















          //RM.create(src.cols, src.rows, CV_8UC(2));
          //BM.create(src.cols, src.rows, CV_8UC(2));
          //GM.create(src.cols, src.rows, CV_8UC(2));
          ...
          BM.at<Vec3b>(j, i) = To[0];



          RM, BM, and GM are not setup. The debugger should show an error when you try to set BM.at<Vec3b>(j, i).



          Try instead:



          int main() 
          {
          String file_name = "C:\images\haaand.jpg";
          Mat src = imread(file_name);
          Mat RM = Mat(src.size(), CV_8UC3);
          Mat BM = Mat(src.size(), CV_8UC3);
          Mat GM = Mat(src.size(), CV_8UC3);
          Vec3b intensity;
          Vec3b To[3];
          for(int i = 0; i < src.cols; i++)
          {
          for(int j = 0; j < src.rows; j++)
          {
          intensity = src.at<Vec3b>(j, i);
          for(int k = 0; k < 3; k++)
          for(int p = 0; p < 3; p++)
          To[k][p] = intensity[k];
          BM.at<Vec3b>(j, i) = To[0];
          GM.at<Vec3b>(j, i) = To[1];
          RM.at<Vec3b>(j, i) = To[2];
          }
          }

          imshow("src", src);
          imshow("RM", RM);
          imshow("BM", BM);
          imshow("GM", GM);
          waitKey(0);
          return 0;
          }





          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%2f53459364%2fc-opencv-mat-pixel-value-and-opencv-errors%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









            0















            //RM.create(src.cols, src.rows, CV_8UC(2));
            //BM.create(src.cols, src.rows, CV_8UC(2));
            //GM.create(src.cols, src.rows, CV_8UC(2));
            ...
            BM.at<Vec3b>(j, i) = To[0];



            RM, BM, and GM are not setup. The debugger should show an error when you try to set BM.at<Vec3b>(j, i).



            Try instead:



            int main() 
            {
            String file_name = "C:\images\haaand.jpg";
            Mat src = imread(file_name);
            Mat RM = Mat(src.size(), CV_8UC3);
            Mat BM = Mat(src.size(), CV_8UC3);
            Mat GM = Mat(src.size(), CV_8UC3);
            Vec3b intensity;
            Vec3b To[3];
            for(int i = 0; i < src.cols; i++)
            {
            for(int j = 0; j < src.rows; j++)
            {
            intensity = src.at<Vec3b>(j, i);
            for(int k = 0; k < 3; k++)
            for(int p = 0; p < 3; p++)
            To[k][p] = intensity[k];
            BM.at<Vec3b>(j, i) = To[0];
            GM.at<Vec3b>(j, i) = To[1];
            RM.at<Vec3b>(j, i) = To[2];
            }
            }

            imshow("src", src);
            imshow("RM", RM);
            imshow("BM", BM);
            imshow("GM", GM);
            waitKey(0);
            return 0;
            }





            share|improve this answer




























              0















              //RM.create(src.cols, src.rows, CV_8UC(2));
              //BM.create(src.cols, src.rows, CV_8UC(2));
              //GM.create(src.cols, src.rows, CV_8UC(2));
              ...
              BM.at<Vec3b>(j, i) = To[0];



              RM, BM, and GM are not setup. The debugger should show an error when you try to set BM.at<Vec3b>(j, i).



              Try instead:



              int main() 
              {
              String file_name = "C:\images\haaand.jpg";
              Mat src = imread(file_name);
              Mat RM = Mat(src.size(), CV_8UC3);
              Mat BM = Mat(src.size(), CV_8UC3);
              Mat GM = Mat(src.size(), CV_8UC3);
              Vec3b intensity;
              Vec3b To[3];
              for(int i = 0; i < src.cols; i++)
              {
              for(int j = 0; j < src.rows; j++)
              {
              intensity = src.at<Vec3b>(j, i);
              for(int k = 0; k < 3; k++)
              for(int p = 0; p < 3; p++)
              To[k][p] = intensity[k];
              BM.at<Vec3b>(j, i) = To[0];
              GM.at<Vec3b>(j, i) = To[1];
              RM.at<Vec3b>(j, i) = To[2];
              }
              }

              imshow("src", src);
              imshow("RM", RM);
              imshow("BM", BM);
              imshow("GM", GM);
              waitKey(0);
              return 0;
              }





              share|improve this answer


























                0












                0








                0








                //RM.create(src.cols, src.rows, CV_8UC(2));
                //BM.create(src.cols, src.rows, CV_8UC(2));
                //GM.create(src.cols, src.rows, CV_8UC(2));
                ...
                BM.at<Vec3b>(j, i) = To[0];



                RM, BM, and GM are not setup. The debugger should show an error when you try to set BM.at<Vec3b>(j, i).



                Try instead:



                int main() 
                {
                String file_name = "C:\images\haaand.jpg";
                Mat src = imread(file_name);
                Mat RM = Mat(src.size(), CV_8UC3);
                Mat BM = Mat(src.size(), CV_8UC3);
                Mat GM = Mat(src.size(), CV_8UC3);
                Vec3b intensity;
                Vec3b To[3];
                for(int i = 0; i < src.cols; i++)
                {
                for(int j = 0; j < src.rows; j++)
                {
                intensity = src.at<Vec3b>(j, i);
                for(int k = 0; k < 3; k++)
                for(int p = 0; p < 3; p++)
                To[k][p] = intensity[k];
                BM.at<Vec3b>(j, i) = To[0];
                GM.at<Vec3b>(j, i) = To[1];
                RM.at<Vec3b>(j, i) = To[2];
                }
                }

                imshow("src", src);
                imshow("RM", RM);
                imshow("BM", BM);
                imshow("GM", GM);
                waitKey(0);
                return 0;
                }





                share|improve this answer














                //RM.create(src.cols, src.rows, CV_8UC(2));
                //BM.create(src.cols, src.rows, CV_8UC(2));
                //GM.create(src.cols, src.rows, CV_8UC(2));
                ...
                BM.at<Vec3b>(j, i) = To[0];



                RM, BM, and GM are not setup. The debugger should show an error when you try to set BM.at<Vec3b>(j, i).



                Try instead:



                int main() 
                {
                String file_name = "C:\images\haaand.jpg";
                Mat src = imread(file_name);
                Mat RM = Mat(src.size(), CV_8UC3);
                Mat BM = Mat(src.size(), CV_8UC3);
                Mat GM = Mat(src.size(), CV_8UC3);
                Vec3b intensity;
                Vec3b To[3];
                for(int i = 0; i < src.cols; i++)
                {
                for(int j = 0; j < src.rows; j++)
                {
                intensity = src.at<Vec3b>(j, i);
                for(int k = 0; k < 3; k++)
                for(int p = 0; p < 3; p++)
                To[k][p] = intensity[k];
                BM.at<Vec3b>(j, i) = To[0];
                GM.at<Vec3b>(j, i) = To[1];
                RM.at<Vec3b>(j, i) = To[2];
                }
                }

                imshow("src", src);
                imshow("RM", RM);
                imshow("BM", BM);
                imshow("GM", GM);
                waitKey(0);
                return 0;
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 25 '18 at 0:01









                Barmak ShemiraniBarmak Shemirani

                22.1k42448




                22.1k42448
































                    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%2f53459364%2fc-opencv-mat-pixel-value-and-opencv-errors%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







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini