1 | initial version |
You can save it to the file with fwrite(..) function. It is sample for 16U one-channel Mat:
FILE *imageFile = fopen(imageName, "wb");
fwrite(image.data, camFrameWidth*camFrameHeight, sizeof(u_int16_t), imageFile);
For reading(but you should know rows and cols count):
FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen ( imagePath.c_str() , "rb" );
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
// obtain file size:
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
// clean up
fclose (pFile);
Mat image;
uint16_t *imageMap = (uint16_t*)buffer;
image.create( rows, cols, CV_16UC1 );
memcpy( image.data, imageMap, rows*cols*sizeof(uint16_t) );