// MyConvert.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cv.h>
#include <cvcam.h>
#include <cxcore.h>
#include <highgui.h>
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cvcam.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"highgui.lib")
typedef unsigned int uint16;
uint16 *Convert24To16(IplImage *pSourceImage);
int main(int argc, char* argv[])
{
IplImage *pSourceImage = NULL;
FILE *pFile = NULL;
if ( (pSourceImage = cvLoadImage(argv[1])) != NULL)
{
pFile = fopen("data.txt","w+");
assert(pFile != NULL);
for (int nHeight = 0 ; nHeight < pSourceImage->height; nHeight++)
{
char *pTr = (pSourceImage->imageData + nHeight *pSourceImage->widthStep);
for (int nWidth = 0 ; nWidth < pSourceImage->width ; nWidth++)
{
uint16 temp = (uint16)(pTr[nWidth + 2] / 256.0 * 31.0);
temp |= ( (uint16)(pTr[nWidth + 1] / 256.0 * 0.63) ) << 5;
temp |= ( (uint16)( pTr[nWidth + 0] / 256.0 * 31.0) ) << 11;
fprintf(pFile," %d ",temp);
}
fprintf(pFile,"/n");
}
}
else
{
printf("Error :图像载入失败");
exit(-1);
}
//释放资源
if (pFile != NULL)
{
fclose(pFile);
}
cvReleaseImage(&pSourceImage);
return 0;
}