今天终于把困扰我三天的问题解决了。
我原本想把Visual C++数字图像模式识别典型案例详解中的人脸定位的CalSim()函数移植到VS2010中的。
但是就被unsigned char* 转换为char* 这个思想给困住了。
贴上书上的原函数:
void FaceDetect::CalSim()
{
//若灰度图像,则返回
if(m_nBitCount==8) return;
//释放旧的输出图像数据及颜色表缓冲区
if(m_pImgDataOut!=NULL){
delete []m_pImgDataOut;
m_pImgDataOut=NULL;
}
if(m_lpColorTableOut!=NULL){
delete []m_lpColorTableOut;
m_lpColorTableOut=NULL;
}
//灰值化后,每像素位数为8比特
m_nBitCountOut=8;
//颜色表长度
m_nColorTableLengthOut=ComputeColorTabalLength(m_nBitCountOut);
//申请颜色表缓冲区,生成灰度图像的颜色表
if(m_nColorTableLengthOut!=0){
m_lpColorTableOut=new RGBQUAD[m_nColorTableLengthOut];
for(int i=0; i<m_nColorTableLengthOut;i++){
m_lpColorTableOut[i].rgbBlue=i;
m_lpColorTableOut[i].rgbGreen=i;
m_lpColorTableOut[i].rgbRed=i;
m_lpColorTableOut[i].rgbReserved=0;
}
}
//输入图像每像素字节数,彩色图像为3字节/像素
int pixelByteIn=3;
//输入图像每行像素所占字节数,必须是4的倍数
int lineByteIn=(m_imgWidth*pixelByteIn+3)/4*4;
//输出图像的宽高,与输入图像相等
m_imgWidthOut=m_imgWidth;
m_imgHeightOut=m_imgHeight;
//输出图像每行像素所占字节数,必须是4的倍数
int lineByteOut=(m_imgWidth*m_nBitCountOut/8+3)/4*4;
//申请输出图像位图数据缓冲区
m_pImgDataOut=new unsigned char[lineByteOut*