Ask Your Question
0

Is it possible for me to set a collection of pixels to a (R,G,B) value?

asked 2017-01-16 22:01:01 -0600

JKep gravatar image

I have been trying to set a collection of pixels to red by doing this:

for(j=0;j<180;j++){
  for(i=0;i<180;i++){
    cv::Vec3b color =frame.at<cv::Vec3b>(j,i);
    color[0]=0;
    color[1]=0;
    color[2]=255;
    frame.at<cv::Vec3b>(j,i) = color;
  }
}

Instead I get rgb style layers like what you would see if you looked at a CRT tv really close. How should I be doing it if I would like to set specific pixels to an RGB value? I'm probably doing something really stupid :( If you think I can provide any more information to help please let me know. I'm very new to this :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-17 00:32:10 -0600

berak gravatar image

updated 2017-01-17 00:51:01 -0600

rule of thumb: if you're writing for-loops with pixels, you're doing it wrong.

either you type (Vec3b) does not match the image, or your assumption about the size (does 180 fit in?) does not match.

please use a ROI and setTo() to achieve this, like:

Rect r = Rect(0,0,180,180); // our desired ROI
r &= Rect(0,0,frame.cols,frame.rows); //crop to frame size, if nessecary !
frame(r).setTo(Scalar(0,0,255));
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-16 22:01:01 -0600

Seen: 144 times

Last updated: Jan 17 '17