使用的主要函数为:
(1)得到一个32位的浮动图像
IplImage* convertFloatImageToUcharImage(const IplImage *srcImg)
{
IplImage *dstImg = 0;
if ((srcImg) && (srcImg->width > 0 && srcImg->height > 0))
{
double minVal, maxVal;
cvMinMaxLoc(srcImg, &minVal, &maxVal);
if (cvIsNaN(minVal) || minVal < -1e30)
minVal = -1e30;
if (cvIsNaN(maxVal) || maxVal > 1e30)
maxVal = 1e30;
if (maxVal-minVal == 0.0f)
maxVal = minVal + 0.001;
dstImg = cvCreateImage(cvSize(srcImg->width, srcImg->height), 8, 1);
cvConvertScale(srcImg, dstImg, 255.0 / (maxVal - minVal), - minVal * 255.0 / (maxVal-minVal));
}
return dstImg;
}
(2) 保存源图片的所有特征向量
void FaceRec::storeEigenfaceImages()
{源-自/751+文,论`文'网]www.751com.cn
if (nEigens > 0)
{
int COLUMNS = 8; // Put upto 8 images on a row.
int nCols = min(nEigens, COLUMNS);
int nRows= 1 + (nEigens / COLUMNS);// Put the rest on new rows.
int w = eigenVectArr[0]->width;
int h = eigenVectArr[0]->height;
CvSize size;
size = cvSize(nCols * w, nRows * h);
IplImage *bigImg = cvCreateImage(size, IPL_DEPTH_8U, 1);
for (int i=0; i<nEigens; i++)
{
IplImage*byteImg=convertFloatImageToUcharImage(eigenVectArr[i]);
int x = w * (i % COLUMNS);
int y = h * (i / COLUMNS);
CvRect ROI = cvRect(x, y, w, h);
cvSetImageROI(bigImg, ROI);
cvCopyImage(byteImg, bigImg);
cvResetImageROI(bigImg);
cvReleaseImage(&byteImg); OPENCV基于ARM的图像识别系统的设计与实现(6):http://www.751com.cn/zidonghua/lunwen_56628.html