BYTE转换成Mat格式
int nImgMatType;
int nTmgMatType;
if ( nImgType == 0 )
{
nImgMatType = CV_8UC1;
}
else if ( nImgType == 1 )
{
nImgMatType = CV_8UC3;
}
else
{
return 1;
}
if ( nTmgType == 0 )
{
nTmgMatType = CV_8UC1;
}
else if ( nTmgType == 1 )
{
nTmgMatType = CV_8UC3;
}
else
{
return 1;
}
CvSize size;
size.width = (int)((fImgWidth*1000+1)/1000);
size.height = (int)((fImgHeight*1000+1)/1000);
CvSize sizeTemp;
sizeTemp.width = (int)((fTmgWidth*1000+1)/1000);
sizeTemp.height = (int)((fTmgHeight*1000+1)/1000);
Mat imgMat(size.height, size.width, nImgMatType, image_data);
Mat tmgMat(sizeTemp.height, sizeTemp.width, nTmgMatType, temp_data);
namedWindow("Source");
imshow("Source", imgMat);
namedWindow("Template");
imshow("Template", tmgMat);
cvWaitKey();
cvDestroyAllWindows();
BYTE转换成Hobject格式
//--------------------------------//
if ( nImgType == 0 ){
nImgMatType = 1;
unsigned char *dataGray = new unsigned char [nImgWidth * nImgHeight];
for(int i = 0; i<nImgHeight; i++)
{
for ( int j=0;j<nImgWidth;j++)
{
dataGray[nImgWidth*i + j] = image_data[(nImgWidth*nImgMatType)*i + j*nImgMatType];
}
}
gen_image1(&Image,"byte",nImgWidth,nImgHeight,(Hlong)(dataGray));
}
else if ( nImgType == 1 )
{
nImgMatType = 3;
unsigned char *dataRed = new unsigned char [nImgWidth * nImgHeight];
unsigned char *dataGreen = new unsigned char [nImgWidth * nImgHeight];
unsigned char *dataBlue = new unsigned char [nImgWidth * nImgHeight];
for(int i = 0; i<nImgHeight; i++)
{
for(int j = 0; j<nImgWidth; j++)
{
dataBlue[nImgWidth*i + j] = image_data[(nImgWidth*nImgMatType)*i + j*nImgMatType + 0];
dataGreen[nImgWidth*i + j] = image_data[(nImgWidth*nImgMatType)*i + j*nImgMatType + 1];
dataRed[nImgWidth*i + j] = image_data[(nImgWidth*nImgMatType)*i + j*nImgMatType + 2];
}
}
gen_image3(&Image,"byte",nImgWidth,nImgHeight,(Hlong)(dataRed),(Hlong)(dataGreen),(Hlong)(dataBlue));
HTuple Width, Height, WindowHandle;
if (HDevWindowStack::IsOpen())
close_window(HDevWindowStack::Pop());
get_image_size(Image, &Width, &Height);
set_window_attr("background_color","black");
open_window(0,0,Width,Height,0,"","",&WindowHandle);
HDevWindowStack::Push(WindowHandle);
if (HDevWindowStack::IsOpen())
disp_obj(Image, HDevWindowStack::GetActive());
write_image(Image, "bmp", 0, "e:/1.bmp");
}
else
{
return 1;
}
//--------------------------------//
if ( nTmgType == 0 )
{
nTmgMatType = 1;
unsigned char *dataGray = new unsigned char [nTmgWidth * nTmgHeight];
for(int i = 0; i<nTmgHeight; i++)
{
for ( int j=0;j<nTmgWidth;j++)
{
dataGray[nTmgWidth*i + j] = temp_data[(nTmgWidth*nImgMatType)*i + j*nImgMatType];
}
}
gen_image1(&TmpImage,"byte",nTmgWidth,nTmgHeight,(Hlong)(dataGray));
}
else if ( nTmgType == 1 )
{
nTmgMatType = 3;
unsigned char *dataRed = new unsigned char [nTmgWidth * nTmgHeight];
unsigned char *dataGreen = new unsigned char [nTmgWidth * nTmgHeight];
unsigned char *dataBlue = new unsigned char [nTmgWidth * nTmgHeight];
for(int i = 0; i<nTmgHeight; i++)
{
for(int j = 0; j<nTmgWidth; j++)
{
dataBlue[nTmgWidth*i + j] = temp_data[(nTmgWidth*nTmgMatType)*i + j*nTmgMatType + 0];
dataGreen[nTmgWidth*i + j] = temp_data[(nTmgWidth*nTmgMatType)*i + j*nTmgMatType + 1];
dataRed[nTmgWidth*i + j] = temp_data[(nTmgWidth*nTmgMatType)*i + j*nTmgMatType + 2];
}
}
gen_image3(&TmpImage,"byte",nTmgWidth,nTmgHeight,(Hlong)(dataRed),(Hlong)(dataGreen),(Hlong)(dataBlue));
HTuple Width, Height, WindowHandle;
// if (HDevWindowStack::IsOpen())
// close_window(HDevWindowStack::Pop());
get_image_size(TmpImage, &Width, &Height);
set_window_attr("background_color","black");
open_window(0,0,Width,Height,0,"","",&WindowHandle);
HDevWindowStack::Push(WindowHandle);
if (HDevWindowStack::IsOpen())
disp_obj(TmpImage, HDevWindowStack::GetActive());
write_image(TmpImage, "bmp", 0, "e:/2.bmp");
}
else
{
return 1;
}