opencv图片格式转换cv::mat与*BYTE相互转换

时间:2025-03-16 07:27:26
::Mat转BYTE*
void Mat_BYTE(Mat matImg, BYTE*& bImg)
{
int nTD = () * 8;
int nHeight = ;
int nWidth = ;
int nBytes = nHeight * nWidth * nTD / 8;
if(bImg!=NULL)
delete[] bImg;
bImg= new BYTE[nBytes];
memcpy(bImg, , nBytes);
}
2.BYTE转cv::Mat
bool BYTE_Mat(BYTE
bImg, int nHeight, int nWidth, int nTD, Mat& resImg)//nHeight,nWidth为图像的高和宽,nTD为通道
{
if(bImg == NULL) {return false; }
int nByte = nHeight* nWidth* nTD/ 8;
if(nTD==8)
{
resImg= Mat::zeros(nHeight, nWidth, CV_8UC1 );
}
else
{
resImg= Mat::zeros(nHeight, nWidth, CV_8UC3);
}
memcpy(, bImg, nByte);
reture true;
}