資源簡介
實(shí)現(xiàn)圖像格式的轉(zhuǎn)化,將bmp的彩色圖像轉(zhuǎn)化為其他簡單格式,便于使用。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
void?saveimage_ppm(const?char?*file_nameunsigned?char?*imageint?hint?wbool?is_binary=true);
void?write_binary_ppm(const?char*?file_nameunsigned?char*?imageint?hint?w);
void?write_ascii_ppm(const?char*?file_nameunsigned?char?*imageint?hint?w);
void?saveimage_pgm(const?char?*file_nameunsigned?char?*imageint?hint?wbool?is_binary=true);
void?write_binary_pgm(const?char?*?file_nameunsigned?char*?imageint?hint?w);
void?write_ascii_pgm(const?char?*?file_nameunsigned?char?*imageint?hint?w);
int?main()
{
BITMAPFILEHEADER?bf;//bmp文件頭結(jié)構(gòu)體;
BITMAPINFOHEADER?bi;//bmp信息頭結(jié)構(gòu)體;
FILE*?fp;
DWORD?LineByteImgSize;
unsigned?char**?Imgdata;
//打開文件;
int?num?=?100;
string?filepath?=?“E:\\多視角重建\\dataset\\Book?Arrival\\BookArrival_Cam10_Depth_bmp\\“;
string?savepath?=?“E:\\多視角重建\\dataset\\Book?Arrival\\BookArrival_Cam10_Depth_pgm\\“;
for(int?n?=?1;?n? {
char?ind[5];
string?basename?=?“Cam10_Depth_“;
string?postfix1?=?“.bmp“;
string?postfix2?=?“.pgm“;
itoa(nind10);
string?fullname;
fullname?=?filepath?+?basename;
fullname?=?fullname?+?ind?+?postfix1;
string?savename;
savename?=?savepath?+?basename;
savename?=?savename?+?ind?+?postfix2;
fp?=?fopen(fullname.c_str()“rb“);
if(fp?==?NULL)
{
printf(“can?not?open?file“);
exit(0);
return?-1;
}
//讀取信息頭、文件頭;
fread(&bf?sizeof(BITMAPFILEHEADER)?1?fp);
fread(&bi?sizeof(BITMAPINFOHEADER)?1?fp);
LineByte?=?bi.biSizeImage/bi.biHeight;
ImgSize?=?(DWORD)LineByte*bi.biHeight;
Imgdata?=?new?unsigned?char*[bi.biHeight];
if(bi.biBitCount?==?24)
{
for(int?i?=?0;?i? Imgdata[i]?=?new?unsigned?char[(bi.biWidth*3+3)/4*4];
for(int?i?=?0;?i? for(int?j?=?0;?j?(bi.biWidth*3+3)/4*4;?j++)
fread(&Imgdata[i][j]11fp);
}
fclose(fp);
//寫成ppm文件;
/*unsigned?char*?ImgData?=?new?unsigned?char[bi.biWidth*bi.biHeight*3];
memset(ImgData0sizeof(unsigned?char)*bi.biWidth*bi.biHeight*3);
for(int?i?=?0;?i? {
for(int?j?=?0;?j? {
int?tind?=?3*((bi.biHeight-1-i)*bi.biWidth?+?j);
ImgData[tind+0]?=?Imgdata[i][3*j+2];
ImgData[tind+1]?=?Imgdata[i][3*j+1];
ImgData[tind+2]?=?Imgdata[i][3*j+0];
}
}
saveimage_ppm(savename.c_str()ImgDatabi.biHeightbi.biWidth);*/
//寫成pgm文件;
unsigned?char*?ImgData?=?new?unsigned?char[bi.biWidth*bi.biHeight];
memset(ImgData0sizeof(unsigned?char)*bi.biWidth*bi.biHeight);
for(int?i?=?0;?i? {
for(int?j?=?0;?j? {
int?tind?=?(bi.biHeight-1-i)*bi.biWidth?+?j;
ImgData[tind+0]?=?Imgdata[i][3*j+0];
}
}
saveimage_pgm(savename.c_str()ImgDatabi.biHeightbi.biWidth);
for(int?i?=?0
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-04-28?15:45??Cvt_BMP_to_PPM\
?????目錄???????????0??2017-04-28?11:29??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\
?????文件????30494720??2017-04-28?15:45??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM.sdf
?????文件?????????909??2017-04-28?10:30??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM.sln
?????文件???????11776??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM.suo
?????文件????????3924??2017-04-28?10:35??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Cvt_BMP_to_PPM.vcxproj
?????文件?????????942??2017-04-28?10:35??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Cvt_BMP_to_PPM.vcxproj.filters
?????文件?????????143??2017-04-28?10:30??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Cvt_BMP_to_PPM.vcxproj.user
?????目錄???????????0??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\
?????文件?????????642??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\cl.command.1.tlog
?????文件???????19846??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\CL.read.1.tlog
?????文件?????????324??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\CL.write.1.tlog
?????文件?????????406??2017-04-28?11:29??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\Cvt_BMP_to_PPM.exe.em
?????文件?????????472??2017-04-28?11:29??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\Cvt_BMP_to_PPM.exe.em
?????文件?????????381??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\Cvt_BMP_to_PPM.exe.intermediate.manifest
?????文件??????????61??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\Cvt_BMP_to_PPM.lastbuildstate
?????文件????????3747??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\Cvt_BMP_to_PPM.log
?????文件?????????218??2017-04-28?11:29??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\Cvt_BMP_to_PPM_manifest.rc
?????文件???????????2??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件???????????2??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件???????????2??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件???????????2??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件???????????2??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件???????????2??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件????????3134??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件????????7902??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件?????????754??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\li
?????文件??????138991??2017-04-28?15:43??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\main.obj
?????文件?????????422??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\mt.command.1.tlog
?????文件?????????338??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\mt.read.1.tlog
?????文件?????????338??2017-04-28?15:44??Cvt_BMP_to_PPM\Cvt_BMP_to_PPM\Debug\mt.write.1.tlog
............此處省略14個文件信息
評論
共有 條評論