opencv对于图片中每个像素点的处理,有没有什么优化的方式?
void CKeyDlg::ThresholdImageByColor(IplImage * pRGBImage,IplImage * pBwImage)
{
int imgheight = pRGBImage->height;
int imgwidth = pRGBImage->width;
int step = pRGBImage->widthStep/sizeof(uchar);
uchar * data = (uchar *)pRGBImage->imageData;
uchar * dataDst = (uchar *)pBwImage->imageData;
int stepDST = pBwImage->widthStep/sizeof(uchar);
int i,j ;
for (i = 0 ;i < imgheight ; i++)
{
for (j = 0 ; j < imgwidth ; j++)
{
if ( (data + i*step)[j*3 + 2] < 20)//R通道信息
{
(dataDst + i*stepDST)[j] = 255 ;
}
else
{
(dataDst + i*stepDST)[j] = 0 ;
}
}
}
}
void CKeyDlg::ThresholdImageByColor(IplImage * pRGBImage,IplImage * pBwImage)
{
int imgheight = pRGBImage->height;
int imgwidth = pRGBImage->width;
int step = pRGBImage->widthStep/sizeof(uchar);
uchar * data = (uchar *)pRGBImage->imageData;
uchar * dataDst = (uchar *)pBwImage->imageData;
int stepDST = pBwImage->widthStep/sizeof(uchar);
int i,j ;
for (i = 0 ;i < imgheight ; i++)
{
uchar * src = (uchar *)pRGBImage->imageData+i*step+2;
uchar * dst = (uchar *)pBwImage->imageData+i*stepDST;
for (j = 0 ; j < imgwidth ; j++)
{
if ( src[0] < 20)//R通道信息
{
dst[0] = 255 ;
}
else
{
dst[0] = 0 ;
}
src+=3;
dst++;
}
}
}