I am processing video frames in real time. I loop through each pixel one at a time, do some math, and then set the pixel to a specific color (if necessary).
In a nutshell, my algorithm looks like this:
//videoFrame is IplImage, 8 bit, 4 channel
for(int i=0;i<videoFrame.width;i++){
for(int j=0;j<videoFrame.height;j++){
CvScalar pixel = cvGet2D(&videoFrame, i, j);
double red = pixel.val[0];
double green = pixel.val[1];
double blue = pixel.val[2];
//do some math
if (someCondition) {
cvSet2D(&videoFrame, i, j, white);
}
}
}
but i find that calls cvGet2D(&videoFrame, i, j);
and cvSet2D(&videoFrame, i, j, white);
are really expensive(slow). Is there an alternative faster way I can access red/green/blue value of each pixel?
Thanks!