c语言二值化图像源码,求解决为何不能运行,代码从网上找的
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<malloc.h>#include<ctype...
# include <stdio.h># include <stdlib.h># include <string.h># include <malloc.h># include <ctype.h># include <process.h># include <windows.h>#pragma comment(lib,"ws2_32.lib") int bitmapToGray(char *OriginalBMP, char *ResultBMP);int main(){ bitmapToGray("E:\\xljFile\\pictureProcessing\\LONGJIANG.bmp", "E:\\xljFile\\pictureProcessing\\LONGJIANG2.bmp"); return 0;}int bitmapToGray(char *OriginalBMP, char *ResultBMP){ unsigned char *BMP24Image, *BMP8Image; BITMAPFILEHEADER fh; BITMAPINFOHEADER ih; // RGBQUAD Color[256]; // BYTE CTemp[3]; //颜色分量 int Row, Col, nCol; int i, j, k; FILE *f, *p; BMP24Image = (unsigned char*)calloc(2000 * 2000, sizeof(unsigned char)); BMP8Image = (unsigned char*)calloc(1000 * 1000, sizeof(unsigned char)); if ((f = fopen(OriginalBMP, "rb")) == NULL) { printf("open error,please check\n"); return 0; } fread(&fh, sizeof(BITMAPFILEHEADER), 1, f); if (fh.bfType != 'MB') { printf("This is not a BMP picture\n"); return 0; } fh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); // +sizeof(RGBQUAD)*256; fread(&ih, sizeof(BITMAPINFOHEADER), 1, f); Row = ih.biHeight; Col = ih.biWidth; Col = Col / 4 * 4; // nCol=Col*4/4*4; //扫描宽度 ih.biBitCount = 8; //改变像素位数大小,8位,256色 fread(BMP24Image, sizeof(unsigned char), Row*Col, f); for (i = 0;i<Row;i++) { for (j = 0;j<Col;j++) { if (BMP24Image[i*Col + j]>128) BMP8Image[i*Col + j] = 255; else BMP8Image[i*Col + j] = 100; // for(k=0;k<3;k++) // { // CTemp[k]=BMP24Image[i*nCol+j*3+k]; // } // BMP8Image[i*Col+j]=CTemp[2]*0.299+CTemp[1]*0.587+CTemp[0]*0.114;//转化公式 } } fclose(f); if ((p = fopen(ResultBMP, "wb")) == NULL) { printf("open savefile error\n"); return 0; } // for(i=0;i<256;i++) //调色板 // { // Color[i].rgbBlue=i; // Color[i].rgbGreen=i; // Color[i].rgbRed=i; // Color[i].rgbReserved=0; // } fwrite(&fh, sizeof(BITMAPFILEHEADER), 1, p); fwrite(&ih, sizeof(BITMAPINFOHEADER), 1, p); //fwrite(Color,sizeof(RGBQUAD),256,p); fwrite(BMP8Image, sizeof(unsigned char), Row*Col, p); fclose(p); return 0;}始终提醒无法解析的外部符号_main什么的。。。。
。。。 展开
。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询