Ask Your Question
0

eliminating a color in image

asked 2018-02-03 04:00:55 -0600

arh24 gravatar image

updated 2018-02-03 05:18:06 -0600

Hi i wanted to eliminate gray color from my image, i just need black or white

So i used this code,but in beagle bone black and in some computers, code crashes but in my laptop it works fine what is happening?

code:

typedef cv::Point3_<uint8_t> Pixel;
 for (Pixel &p : cv::Mat_<Pixel>(frame))
   {
         if(p.x<127 ||p.y<127 ||p.z<127 )
             {
                p.x = 0;
                p.y = 0;
                p.z = 0;
              }
   }

gives me this error: OpenCV Error: Bad argument (The total number of matrix elements is not divisible by the new number of rows) in reshape

edit retag flag offensive close merge delete

Comments

"compilers give me this error" ? that's not a compiler error

a good idea is to split frame and use threshold method : threshold(frame,frame,127,255,THRESH_TOZERO_INV )

LBerger gravatar imageLBerger ( 2018-02-03 04:18:30 -0600 )edit

you are right not a compiler error

arh24 gravatar imagearh24 ( 2018-02-03 05:17:29 -0600 )edit

" i wanted to eliminate gray color from my image, i just need black or white" -- that's not really, whatyour code is doing, in the 1st place.

berak gravatar imageberak ( 2018-02-03 05:22:20 -0600 )edit

my input image has only white black and gray colors, so under 127 will eliminate gray

arh24 gravatar imagearh24 ( 2018-02-04 05:25:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-02-03 05:20:31 -0600

berak gravatar image

please don't write per-pixel loops, when using opencv.

the problem in your case seems to be, that your input frame is grayscale(CV_8UC1), but your code assumes CV_8UC3

what you should use instead is threshold , which is type-safe, faster, and less error-prone, like:

   threshold(frame,frame,127,0,THRESH_TOZERO);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-02-03 04:00:55 -0600

Seen: 184 times

Last updated: Feb 03 '18