c图像识别源代码(图像识别代码c语言)
admin 发布:2022-12-19 19:05 124
本篇文章给大家谈谈c图像识别源代码,以及图像识别代码c语言对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
用c语言读取24位位图bmp文件
可以使用C语言标准函数库中的fopen、fseek、fclose等系列函数来打开bmp位图文件,以及进行相应的处理,下面是一个demo,仅供参考。以下代码在vc6.0中编译通过。
#include stdio.h
#include stdlib.h
#define BITMAPFILEHEADERLENGTH 14 // The bmp FileHeader length is 14
#define BM 19778 // The ASCII code for BM
/* Test the file is bmp file or not */
void bmpFileTest(FILE* fpbmp);
/* To get the OffSet of header to data part */
void bmpHeaderPartLength(FILE* fpbmp);
/* To get the width and height of the bmp file */
void BmpWidthHeight(FILE* fpbmp);
//get r,g,b data
void bmpDataPart(FILE* fpbmp);
// output data to corresponding txt file
void bmpoutput(FILE *fpout);
unsigned int OffSet = 0; // OffSet from Header part to Data Part
long width ; // The Width of the Data Part
long height ; // The Height of the Data Part
unsigned char r[2000][2000],output_r[2000][2000];
unsigned char g[2000][2000],output_g[2000][2000];
unsigned char b[2000][2000],output_b[2000][2000];
int main(int argc, char* argv[])
{
/* Open bmp file */
unsigned char *fp_temp;
FILE *fpbmp;
FILE *fpout;
fpbmp= fopen("1.bmp", "rb");
if (fpbmp == NULL)
{
printf("Open bmp failed!!!\n");
return 1;
}
fpout= fopen("out.bmp", "wb+");
if (fpout == NULL)
{
printf("Open out.bmp failed!!!\n");
return 1;
}
bmpFileTest(fpbmp); //Test the file is bmp file or not
bmpHeaderPartLength(fpbmp); //Get the length of Header Part
BmpWidthHeight(fpbmp); //Get the width and width of the Data Part
//
fseek(fpbmp, 0L, SEEK_SET);
fseek(fpout, 0L, SEEK_SET);
fp_temp=(unsigned char *)malloc(OffSet);
fread(fp_temp, 1, OffSet, fpbmp);
fwrite(fp_temp,1,OffSet,fpout);
bmpDataPart(fpbmp); //Reserve the data to file
/*
如果您想对图片进行处理,请您再这里插入处理函数!!!!!!!!!!!!!!!!!!
*/
bmpoutput(fpout);
fclose(fpbmp);
fclose(fpout);
return 0;
}
void bmpoutput(FILE* fpout)
{
int i, j=0;
int stride;
unsigned char* pixout=NULL;
stride=(24*width+31)/8;
stride=stride/4*4;
pixout=(unsigned char *)malloc(stride);
fseek(fpout, OffSet, SEEK_SET);
for(j=0;jheight;j++)
{
for(i=0;iwidth;i++)
{
pixout[i*3+2]=output_r[height-1-j][i];
pixout[i*3+1]=output_g[height-1-j][i];
pixout[i*3] =output_b[height-1-j][i];
}
fwrite(pixout, 1, stride, fpout);
}
}
void bmpDataPart(FILE* fpbmp)
{
int i, j=0;
int stride;
unsigned char* pix=NULL;
FILE* fpr;
FILE* fpg;
FILE* fpb;
if((fpr=fopen("bmpr.txt","w+")) == NULL)
{
printf("Failed to construct file bmpr.txt.!!!");
exit(1);
}
if((fpg=fopen("bmpg.txt","w+")) == NULL)
{
printf("Failed to construct file bmpg.txt.!!!");
exit(1);
}
if((fpb=fopen("bmpb.txt","w+")) == NULL)
{
printf("Failed to construct file bmpb.txt.!!!");
exit(1);
}
fseek(fpbmp, OffSet, SEEK_SET);
stride=(24*width+31)/8;
stride=stride/4*4;
pix=(unsigned char *)malloc(stride);
for(j=0;jheight;j++)
{
fread(pix, 1, stride, fpbmp);
for(i=0;iwidth;i++)
{
r[height-1-j][i] =pix[i*3+2];
g[height-1-j][i] =pix[i*3+1];
b[height-1-j][i] =pix[i*3];
output_r[height-1-j][i] =pix[i*3+2];
output_g[height-1-j][i] =pix[i*3+1];
output_b[height-1-j][i] =pix[i*3];
}
}
for(i =0; i height; i++)
{
for(j = 0; j width-1; j++)
{
fprintf(fpb,"%4d",b[i][j]);
fprintf(fpg,"%4d",g[i][j]);
fprintf(fpr,"%4d",r[i][j]);
}
fprintf(fpb,"%4d\n",b[i][j]);
fprintf(fpg,"%4d\n",g[i][j]);
fprintf(fpr,"%4d\n",r[i][j]);
}
fclose(fpr);
fclose(fpg);
fclose(fpb);
}
void bmpFileTest(FILE* fpbmp)
{
unsigned short bfType = 0;
fseek(fpbmp, 0L, SEEK_SET);//seek_set 起始位置
fread(bfType, sizeof(char), 2, fpbmp);
if (BM != bfType)
{
printf("This file is not bmp file.!!!\n");
exit(1);
}
}
/* To get the OffSet of header to data part */
void bmpHeaderPartLength(FILE* fpbmp)
{
fseek(fpbmp, 10L, SEEK_SET);
fread(OffSet, sizeof(char), 4, fpbmp);
printf("The Header Part is of length %d.\n", OffSet);
}
/* To get the width and height of the bmp file */
void BmpWidthHeight(FILE* fpbmp)
{
fseek(fpbmp, 18L, SEEK_SET);
fread(width, sizeof(char), 4, fpbmp);
fseek(fpbmp, 22L, SEEK_SET);
fread(height, sizeof(char), 4, fpbmp);
printf("The Width of the bmp file is %ld.\n", width);
printf("The Height of the bmp file is %ld.\n", height);
}
帮忙看一段C代码 图像处理方面
看了半天才看明白,这个程序是个画线程序,它的算法好苯,好复杂,看得我晕乎乎的
好了下面我不逐行解释了,但是我会帮你把理解该程序的关键点告诉你。
首先这个源图像肯定是256色DIB位图,这个毫无疑问,根据程序的像素附值0和255,有可能是256色黑白位图,0代表黑色像素,255代表白色像素,但是不一定,通常意义上是这样的,除非他更改了调色板的索引。BYTE *pE表示了图像数据的指针,int dh就是作为y0,y1之间的距离判断条件。
我把for循环中间的break,continue去掉,然后把循环合并,程序实际上实现了一个完整像素寻址,依次访问的过程,每次都是从第一列开始,垂直向上循环,然后第二列,再垂直向上,一直到第width列结束。
for(x=0;xWidth;x++)
{
for(y=0;yhy;y++)
{
pME=pE+rWidth*y+x; //这里pME就是指向图像中第y行第x列的像素的指针
*pME=255; //就是给像素附值
}
}
rWidth就是图像每一行的总字节数,只不过程序中用了pME+=rWidth的方式来表示,很不直观。
至于该程序实现的目标,为了更形象的表示,我用0,1画图给你表达图像
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
000000000000000000000000000000000000000000
000000000000000000000000000000000000000000
000000000000000000000000000000000000000000
000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
000000000000000000000000000000000000000000
000000000000000000000000000000000000000000
000000000000000000000000000000000000000000
运行该程序之后,就会把两个行1之间的距离小于int dh,则把0全部附值为255,恩就这么简单,结果编写这个程序的人弄得非常难以理解.
对图像进行二值化的处理方法,求源代码,最好是C++/C或者OPENCV
//声明IplImage指针
IplImage* pFrame = NULL;
IplImage* pFrImg = NULL;
IplImage* pBkImg = NULL;
CvMat* pFrameMat = NULL;
CvMat* pFrMat = NULL;
CvMat* pBkMat = NULL;
pBkImg = cvCreateImage(cvSize(pFrame-width, pFrame-height), IPL_DEPTH_8U,1);
pFrImg = cvCreateImage(cvSize(pFrame-width, pFrame-height), IPL_DEPTH_8U,1);
pBkMat = cvCreateMat(pFrame-height, pFrame-width, CV_32FC1);
pFrMat = cvCreateMat(pFrame-height, pFrame-width, CV_32FC1);
pFrameMat = cvCreateMat(pFrame-height, pFrame-width, CV_32FC1);
//转化成单通道图像再处理
cvCvtColor(pFrame, pBkImg, CV_BGR2GRAY);
cvCvtColor(pFrame, pFrImg, CV_BGR2GRAY);
cvConvert(pFrImg, pFrameMat);
cvConvert(pFrImg, pFrMat);
cvConvert(pFrImg, pBkMat);
//二值化前景图
cvThreshold(pFrMat, pFrImg, 60, 255.0, CV_THRESH_BINARY);
不知道你说的什么意思,要对一个图像进行二值化处理用OpenCV的话就是
void cvThreshold( const CvArr* src, CvArr* dst, double threshold,
double max_value, int threshold_type );
这个函数是定阈值二值化处理,比较粗略吧。另外可以用自适应阈值二值化,那样的话就会比这个更精细。
图像识别中怎么进行二次曲线的检测源代码
设二次函数为y=ax^2+bx+c,则图像为抛物线。
1 当a0时,抛物线开口向上,当a0时开口向下,对称轴是直线x=-b/2a,
顶点坐标是(-b/2a,[4ac-b^2]/4a)。
2 图象与y轴一定相交,交点坐标为(0,c);
3(1) 当△=b^2-4ac0,图象与x轴交于两点A(x₁,0)和B(x₂,0),
其中的x1,x2是一元二次方程ax^2+bx+c=0(a≠0)的两根.这两点间的
距离 AB=|x₂-x₁|
(2)当△=0.图象与x轴只有一个交点。
(3)当△0.图象与x轴没有交点.
关于c图像识别源代码和图像识别代码c语言的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:维修系统源代码(开源报修系统)
- 下一篇:top4net源代码的简单介绍
相关推荐
- 05-09网页代码,网页代码快捷键
- 05-07pb超级报表源代码(pb报表工具)[20240507更新]
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-07广告切换源代码免费下载(广告切换源代码免费下载安装)[20240507更新]
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06阁楼网源代码(阁楼是什么网站)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接