openCV生成灰度图像示例
临时用到,对openCV还不熟,慢慢研究。
#include "cxcore.h"
IplImage* pImg = cvCreateImage( cvSize( width, height ), 8, 1 );
cvZero( pImg );
for (int i = 0; i < width; ++i)
for (int j = 0; j < height; ++j)
{
CvPoint pt = cvPoint(i, j);
uchar* temp = &((uchar*)(pImg->imageDate /* +distance */))[pt.x];
temp[0] = static_cast<int>( value(0~255) );
}
cvSaveImage( filename, pImg);
cvReleaseImage(&pImg);
分类: Uncategorized
c/c++, openCV
If you take width as the inner loop and height as the outer, the code will be much more effective. Because of the layout of CvArr, it is cache-friendly to do so.