转BYTE*是利用Mat矩阵的什么机制,Mat类的哪个成员变量?
2. BYTE*转Mat利用的机制是一样的吗?
转BYTE*函数
void MatToByte(Mat srcImg, BYTE*& pImg)
{
int nFlag = () * 8;//一个像素的bits
int nHeight = ;
int nWidth = ;
int nBytes = nHeight * nWidth * nFlag / 8;//图像总的字节
if(pImg)
delete[] pImg;
pImg = new BYTE[nBytes];//new的单位为字节
memcpy(pImg, , nBytes);//转化函数,注意Mat的data成员
}
*转Mat函数
bool ByteToMat(BYTE* pImg, int nH, int nW, int nFlag, Mat& outImg)//nH,nW为BYTE*类型图像的高和宽,nFlag为通道数
{
if(pImg == nullptr)
{
return false;
}
int nByte = nH * nW * nFlag / 8;//字节计算
int nType = nFlag == 8 ? CV_8UC1 : CV_8UC3;
outImg = Mat::zeros(nH, nW, nType);
memcpy(, pImg, nByte);
reture true;
}