二、Linux嵌入式系统代码

参考  https://blog.csdn.net/qq_36449541/article/details/80206477

原先的开发者是在友善之臂的平台上(好像cpu是arm9 S3C2440的)开发的

最原始的车牌识别程序

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "cv.h"
//#include "highgui.h"
#include "math.h"
#define pi 3.14
#define RADIAN(angle) ((angle)*3.14/180.0)#define max(a,b)            (((a) > (b)) ? (a) : (b))
#define min(a,b)            (((a) < (b)) ? (a) : (b))typedef unsigned long       DWORD;
typedef int                 BOOL;
typedef unsigned char       BYTE;
typedef unsigned short      WORD;
typedef float               FLOAT;
typedef unsigned char       byte;
//#define MAX(a,b,c) a>(b>c?b:c)?a:
struct BMP_img
{WORD  bfType;DWORD size;DWORD reser;DWORD header_length;DWORD infoheader_length;DWORD width;DWORD height;WORD  biplanes;WORD  bmp_type;        /* 8bit 24bit; */DWORD compres;DWORD datasize;DWORD bixpm;DWORD biypm;DWORD clrused;DWORD  relclrused;BYTE *image;byte *header_info;DWORD lineBytes;};struct Bmp1{DWORD width;DWORD height;byte strc[67][800];BYTE *image;int p1[15];//xlint p2[15];//xrint p3[15];//yuint p4[15];//ydint up;int down;byte strr[7][2500];byte string[7];float ang;//倾斜角度
};struct HSV{float H;float S;int V;
};struct RGB{byte bitb;byte bitg;byte bitr;byte  re;};
void read_img(FILE *infile, struct BMP_img *img);
//void read_img(FILE *infile, struct BMP_img *img);void displaytwo(struct Bmp1 img,byte *srcBmp,byte *dstBmp,int yuzhi);
unsigned char  myGetMedianNum(unsigned char * bArray, int iFilterLen);
void cuizhitouying(struct Bmp1 *img,byte *temp);
void sob(byte *srcBmp,int width,int height,int type);
void shuipingtouying(struct Bmp1 *img,byte *temp);
//void display(BMP_img img,byte *temp);void grayScale(struct BMP_img img,byte *srcBmp,byte *dstBmp);
void junheng(struct BMP_img img,byte *srcBmp,byte *dstBmp);
void CutBmp(struct BMP_img img,struct Bmp1 *img1,int HL,int HH,int VL,int VH);
void CutBmp1(struct Bmp1 *img1,int HL,int HH,int VL,int VH);
void testhsv(float h,float s,float v,byte r,byte g,byte b);
void hsvzation(byte *image,struct HSV *hsv,int width,int height);
void location(byte *image,int width,int height,int yuzhi,int *HL,int *HH,int *VL,int *VH);
void huidu(struct Bmp1 img,byte *srcBmp,byte *dstBmp);
void bmptwo(struct Bmp1 img,byte *srcBmp,byte *dstBmp,byte yuzhi);
void Thiningtest(struct BMP_img img,byte *srcBmp,byte *dstBmp);
void Thining(byte *srcBmp,int width,int height);
void ThinnerRosenfeld(void *image, unsigned long lx, unsigned long ly);
void delpoint(byte *dst,int width,int height,int yuzhi);
void Erosion(byte *image,int width,int height,int type,int num);
void deljunzao(byte *dst,int width,int height,int yuzhi);
void pingjun(byte *dst,int width,int height);
void changeGray(byte *srcBmp,byte *dstBmp,int width,int height,int nWidth,int nHeight);
byte *changeRGB(byte *srcBmp,int width,int height,int *lwidth,int *lheight,float f);
void strBmp(struct Bmp1 *img,byte *temp);
void guiyi(struct Bmp1 *img);
void readstr(FILE *infile, byte *srcBmp);
char *myitoa(int num, char *str, int radix);   // 整数字符串转换。
void readmoban(char *path,struct Bmp1 *img2);
void writebmp(const char *path,const char *name,byte *temp);
int cmpstr(byte *src,byte *moban);
void Hough(struct Bmp1 *img);
void strout(struct Bmp1 *img);
void edgesob8(byte *image,int width,int height);
void edgesob4(byte *image,int width,int height);//4邻域
int hough(byte *srcBmp,int width,int height);
void Dilation(byte *image,int width,int height,int type,int num);
void RotateGray(byte *image,int width,int height, float iRotateAngle);
byte *RotateRGB(byte *image, float iRotateAngle,int width,int height,int *lwidth,int *lheight);
void xuanzhuan(struct Bmp1 *img1);
byte *myMalloc(int num,const byte *bmp,int type);
void guiyiRGB(struct Bmp1 *img1);
void outtext(struct Bmp1 img1,int x,int y);
int calstr(byte *srcBmp);int main()
{while(1){int HL=0,HH=0,VH=0,VL=0;struct BMP_img img;struct Bmp1 img1;FILE *f;byte *temp,*temp1;//char path[80]="C:\\test\\2.bmp";char path1[80]="C:\\test\\moban\\";char path[80];char path3[40];printf("Please Input Path\n");scanf("%s",path3);strcpy(path,path3);printf("the path is :%s\n",path);// char path1[80]="//mnt//arm1//test//moban//";//char path[80]="C:\\Documents and Settings\\liujia\\桌面\\test\\example06.bmp";//char path1[80]="C:\\Documents and Settings\\liujia\\桌面\\test\\moban\\";if((f=fopen(path,"rb"))==NULL){printf( "\nCan not open the path: %s \n", path);exit(-1);}read_img(f, &img);fclose(f);temp=myMalloc(img.height*img.width*4,temp,0);//(byte *)malloc(sizeof(byte)*img.height*img.width*4);// byte *temp2=(byte *)malloc(sizeof(byte)*img.height*img.width);temp1=myMalloc(img.height*img.width*4,temp,0);location(img.image,img.width,img.height,15,&HL,&HH,&VL,&VH);CutBmp(img,&img1,HL,HH,VL,VH);Hough(&img1);xuanzhuan(&img1);location(img1.image,img1.width,img1.height,0,&HL,&HH,&VL,&VH);CutBmp1(&img1,HL,HH,VL,VH);huidu(img1,img1.image,temp);displaytwo(img1,temp,temp1,30);delpoint(temp1,img1.width,img1.height,3);shuipingtouying(&img1,temp1);delpoint(temp1,img1.width,img1.height,2);cuizhitouying(&img1,temp1);memset(temp,0,sizeof(char)*img1.width*img1.height);strBmp(&img1,temp1);//把车牌字符放到数组里面guiyi(&img1);readmoban(path1,&img1);strout(&img1);outtext(img1,0,600);free(temp1);free(temp);getch();
}return 0;}
void read_img(FILE *infile, struct BMP_img *img)
{DWORD i,j,l,bitcolor;DWORD line24;DWORD line8;struct RGB *bitmap;fread(&img->bfType,sizeof(WORD),1,infile);//printf("\n打开的图为 %d",img->bfType);fread(&img->size,sizeof(DWORD),1,infile);     //        printf("\nBMP size             :%l",img->size);fread(&img->reser,sizeof(DWORD),1,infile);//printf("\n保留位:");fread(&img->header_length,sizeof(DWORD),1,infile); //printf("\nheader length    :%l",img->header_length);fread(&img->infoheader_length,sizeof(DWORD),1,infile);fread(&img->width, sizeof(DWORD), 1, infile);fread(&img->height, sizeof(DWORD), 1, infile);     //printf( "\nwidth   :%l\n  height  :%l ", img->width, img->height);fread(&img->biplanes, sizeof(WORD), 1, infile);fread(&img->bmp_type, sizeof(WORD), 1, infile);  // printf("\nBMP Tpye             :%l ", img->bmp_type);fread(&img->compres, sizeof(DWORD), 1, infile);    //if(img->compres==0) {printf("\nbmp图片为非压缩!");}printf(" ");fread(&img->datasize, sizeof(DWORD), 1, infile);//printf("\nBMP Data Size        :%l ",img->datasize);fread(&img->bixpm, sizeof(DWORD), 1, infile);fread(&img->biypm, sizeof(DWORD), 1, infile);fread(&img->clrused, sizeof(DWORD), 1, infile);    //printf("\n实际使用颜色数=%d ",img->clrused);printf(" ");fread(&img->relclrused, sizeof(DWORD), 1, infile);img->lineBytes=(img->width*img->bmp_type+31)/32*4;//printf("\nLineBytes            :%l\n",img->lineBytes);line24=(img->width*24+31)/32*4;line8=(img->width*8+31)/32*4;if(img->bmp_type==1){bitcolor=2;printf("不能读取退出");exit(-1);}if(img->bmp_type==4){bitcolor=16;printf("不能读取退出");exit(-1);}if(img->bmp_type==8){byte *temp=(BYTE*)malloc(img->height*line8*sizeof(BYTE));memset(temp,0x00,img->height*img->lineBytes*sizeof(BYTE));bitcolor=256;bitmap=(struct RGB *)calloc(bitcolor,sizeof(struct RGB));img->image=(unsigned char *)malloc(sizeof(unsigned char)*(line8*img->height));memset(img->image,0x00,sizeof(byte)*line8*img->height);if(img->image==NULL) {fprintf(stderr, "\n Allocation error for temp in read_bmp() \n");}fseek(infile,0x36, SEEK_SET);fread(bitmap,sizeof(struct RGB),bitcolor,infile);fseek(infile, img->header_length, SEEK_SET);//fread(temp, sizeof(unsigned char),lineBytes*img->height, infile);fread(temp, img->lineBytes*img->height,1, infile);if(temp==NULL)printf("\n读取失败\n");for(i=0;i<img->height;i++){for(j=0;j<img->width;j++){img->image[i*img->width+j]=(byte)(0.299*bitmap[temp[i*line8+j]].bitb+0.578*bitmap[temp[i*line8+j]].bitg+0.114*bitmap[temp[i*line8+j]].bitr);// putpixel(j,img->height-i,RGB(img->image[i*img->width+j],img->image[i*img->width+j],img->image[i*img->width+j]));}}free(temp);temp=NULL;}if(img->bmp_type==24){byte *temp=(byte *)malloc(sizeof(byte)*img->height*img->lineBytes); if(temp==NULL)exit(-1);img->image=(unsigned char *)malloc(sizeof(unsigned char)*((line24)*img->height));if(img->image==NULL) fprintf(stderr, "\n Allocation error for temp in read_bmp() \n");fseek(infile, img->header_length, SEEK_SET);fread(temp, sizeof(unsigned char), (img->lineBytes)*img->height, infile);// byte *temp=(byte *)malloc(sizeof(byte)*img->lineBytes*img->height)for(i=0;i<img->height;i++){l=0;for(j=0;j<img->width*3;j+=3){//l=(img->height-i-1)*img->lineBytes+j;l=(img->height-i-1)*img->width*3+j;img->image[l+2]=*(temp+i*img->lineBytes+j+2);img->image[l+1]=*(temp+i*img->lineBytes+j+1);img->image[l]=*(temp+i*img->lineBytes+j);}}free(temp);temp=NULL;}
}void readstr(FILE *infile, byte *srcBmp)
{int width,height, headlength;int i,j,bitcolor,line8;byte *temp;byte temp1;struct RGB *bitmap;width=20;height=40;headlength=1078;line8=(width*8+31)/32*4;temp=(BYTE*)malloc(height*line8*sizeof(BYTE));memset(temp,0x00,height*line8*sizeof(BYTE));bitcolor=256;bitmap=(struct RGB *)malloc(sizeof(struct RGB)*bitcolor);fseek(infile,0x36, SEEK_SET);fread(bitmap,sizeof(struct RGB),bitcolor,infile);fseek(infile, headlength, SEEK_SET);fread(temp, line8*height,1, infile);if(temp==NULL){printf("\n读取失败\n"); exit(-1);}for(i=0;i<height;i++){for(j=0;j<width;j++){temp1=temp[i*line8+j];if(temp1>=150)temp1=255;else temp1=0;srcBmp[(height-i-1)*width+j]=temp1;//(byte)(0.299*bitmap[temp[i*line8+j]].bitb+0.578*bitmap[temp[i*line8+j]].bitg+0.114*bitmap[temp[i*line8+j]].bitr);}}free(temp);temp=NULL;}void grayScale(struct BMP_img img,byte *srcBmp,byte *dstBmp)
{int i,j,temp1,n;float gray;temp1=img.width*3;srcBmp=img.image;for(i=0;i<img.height;i++){for(j=0,n=0;j<img.width;n+=3,j++){gray=(*(srcBmp+i*img.lineBytes+n+2)*0.299)+(*(srcBmp+i*img.lineBytes+n+1)*0.578)+(*(srcBmp+i*img.lineBytes+n)*0.114);dstBmp[i*img.lineBytes+n]=(byte)(gray+0.5);dstBmp[i*img.lineBytes+n+1]=(byte)(gray+0.5);dstBmp[i*img.lineBytes+n+2]=(byte)(gray+0.5);}}
}
void huidu(struct Bmp1 img,byte *srcBmp,byte *dstBmp)
{int i,j,n;float gray;srcBmp=img.image;for(i=0;i<img.height;i++){for(j=0,n=0;j<img.width;n+=3,j++){gray=(*(srcBmp+i*img.width*3+n+2)*0.299)+(*(srcBmp+i*img.width*3+n+1)*0.578)+(*(srcBmp+i*img.width*3+n)*0.114);dstBmp[i*img.width+j]=(byte)(gray+0.5);}}
}
void hsvzation(byte *image,struct HSV *hsv,int width,int height)
{int i,j,k;float min,max,delta,tmp;//h,s,v,m,n;//int lineBytes=(width*24+31)/32*4;byte r,g,b;for(i=0;i<height;i++){for(k=0,j=0;j<width*3;k++,j+=3){g=image[i*width*3+j+1];b=image[i*width*3+j];r=image[i*width*3+j+2];tmp=min(r,g);min=min(tmp,b);tmp=max(r,g);max=max(tmp,b);hsv[i*width+k].V=(int)max;delta=max-min;if(delta==0){hsv[i*width+k].H=0;continue;//value=0;//return value;}if(max!=0){//tmp=delta/max;hsv[i*width+k].S=delta/max;//tmp;}else{hsv[i*width+k].S=0;hsv[i*width+k].H=0;continue;}if(r==max){// tmp=(g-b)/delta;hsv[i*width+k].H=(g-b)/delta;//tmp;}else if(g==max)hsv[i*width+k].H=2+(b-r);else{//tmp=4+(r-g)/delta;hsv[i*width+k].H=4+(r-g)/delta;//tmp;}hsv[i*width+k].H*=60;if(hsv[i*width+k].H<0)hsv[i*width+k].H+=360;//value=(int)(h+0.5);}}}void location(byte *image,int width,int height,int yuzhi,int *HL,int *HH,int *VL,int *VH)
{int i,j,n,maxnum,flag=0;struct HSV *hsv;int temp[2000]={0};byte *temp1;hsv=(struct HSV *)malloc(sizeof(struct HSV)*width*height);hsvzation(image,hsv,width,height);temp1=(byte *)malloc(sizeof(byte)*height*width);//int lineBytes=(width*24+31)/32*4;for(i=0;i<height;i++){for(j=0,n=0;j<width;n+=3,j++){if((hsv[i*width+j].H<220.0)&&(hsv[i*width+j].H>180.0)&&(hsv[i*width+j].V<250)&&(hsv[i*width+j].S>0.6)){temp1[i*width+j]=255;//putpixel(j,i,RGB(255,255,255));}else{temp1[i*width+j]=0;//putpixel(j,i,RGB(0,0,0));}}}for(i=0;i<height;i++){for(j=0;j<width;j++){if(temp1[i*width+j]==255){temp[i]++;}}}edgesob8(temp1,width,height);maxnum=temp[0];for(i=1;i<height;i++){if(temp[i]>maxnum)maxnum=temp[i];}maxnum=maxnum/3;for(i=0;i<height;i++){if(flag==0){if(temp[i]>maxnum){*HL=i-yuzhi;flag=1;}}if(flag==1){if(temp[i]==0){*HH=i+yuzhi;break;}}}memset(temp,0x00,sizeof(int)*width);for(i=0;i<width;i++){for(j=0;j<height;j++){if(temp1[j*width+i]==255){temp[i]++;}}}flag=0;maxnum=temp[0];for(i=1;i<width;i++){if(temp[i]>maxnum)maxnum=temp[i];}maxnum=maxnum/3;for(i=0;i<width;i++){if(temp[i]>maxnum){*VL=i-yuzhi;break;}}for(i=width;i>*VL;i--){if(temp[i]>maxnum){*VH=i+yuzhi;break;}}free(temp1);temp1=NULL;free(hsv);
}
void Hough(struct Bmp1 *img)
{int i,j,n;float ang;byte *temp1;//int temp[2000]={0};struct HSV *hsv=(struct HSV *)malloc(sizeof(struct HSV)*img->width*img->height);hsvzation(img->image,hsv,img->width,img->height);temp1=(byte *)malloc(sizeof(byte)*img->height*img->width);for(i=0;i<img->height;i++){for(j=0,n=0;j<img->width;n+=3,j++){if((hsv[i*img->width+j].H<220.0)&&(hsv[i*img->width+j].H>180.0)&&(hsv[i*img->width+j].V<250)&&(hsv[i*img->width+j].S>0.6)){temp1[i*img->width+j]=255;}else{temp1[i*img->width+j]=0;}}}Dilation(temp1,img->width,img->height,1,5);sob(temp1,img->width,img->height,0);ang=hough(temp1,img->width,img->height);if((ang<=8)&&(ang>=1))ang=ang-1;if(ang>90){ang=ang-180;}img->ang=ang;}
void bmptwo(struct Bmp1 img,byte *srcBmp,byte *dstBmp,byte yuzhi)
{int i,j;for(i=0;i<img.height;i++){for(j=0;j<img.width;j++){if(srcBmp[i*img.width+j]>=yuzhi){dstBmp[i*img.width+j]=255;}else{dstBmp[i*img.width+j]=0;}}}
}void displaytwo(struct Bmp1 img,byte *srcBmp,byte *dstBmp,int yuzhi)
{//int i,j,T,n,k,t,l;//int m;int totalPixels = img.width * img.height;int bestT = 0;int i,j;int histogramArray[256]={0};double densityArray[256]={0};double u0 = 0;double u1 = 0;double w0 = 0;double w1 = 0;double bestDeviation = 0;for(i=0;i<img.height;i++){for(j=0;j<img.width;j++){histogramArray[srcBmp[i*img.width+j]]++;}}for(i=0;i<256;i++){densityArray[i] = histogramArray[i] * 1.0 / totalPixels;}for (i = 0; i < 256; i++){w0 = 0;w1 = 0;for (j = 0; j <= i; j++) {w0 += densityArray[j];}for (j = i + 1; j < 256; j++) {w1 += densityArray[j];}u0 = 0;u1 = 0;for (j = 0; j <= i; j++) {u0 += j * densityArray[j];}for (j = i + 1; j < 256; j++) {u1 += j * densityArray[j];}u0 = u0 / w0;u1 = u1 / w1;if (w0 * w1 * (u0 - u1) * (u0 - u1) > bestDeviation) {bestT = i;bestDeviation = w0 * w1 * (u0 - u1) * (u0 - u1);}}for (i = 0; i < 256; i++) {histogramArray[i] = 0;}bestT=bestT+yuzhi;if(bestT<0)bestT=0;if(bestT>255)bestT=255;for(i=0;i<img.height;i++){for(j=0;j<img.width;j++){if(srcBmp[i*img.width+j]>bestT){dstBmp[i*img.width+j]=255;}else{dstBmp[i*img.width+j]=0; }}}
}

从代码上来看,开发者可能还是学生,没经过职业训练,代码可读性不高,缩进对齐什么的都没有(我只是校对了最后一个函数)。下面的好像是抄来的,比较正规点。

有关 车牌识别(二、Linux嵌入式系统代码)相关推荐

  1. LINUX嵌入式系统开发平台选择

    1 嵌入式系统与Linux 按照电气工程师协会的一个定义:嵌入式系统是用来控制或监视机器.装置或工厂等的大规模系统的设备.具体说来,它是电脑软件和硬件的综合体:是以应用为中心,以计算机技术为基础,软硬 ...

  2. 基于Arm板linux嵌入式系统RS485串口读写通讯

    最近在做基于Arm板linux嵌入式系统的RS485串口读写通讯首先参考 http://bbs.chinaunix.net/thread-3650543-1-1.html上的文章,该文章写道,读的时候 ...

  3. 【Matlab车牌识别】停车计费系统【含GUI源码 735期】

    一.代码运行视频(哔哩哔哩) [Matlab车牌识别]停车计费系统[含GUI源码 735期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 蔡利梅.MATLA ...

  4. Linux嵌入式系统开发之Led开发——应用篇(一)

    与Linux嵌入式系统开发之Led开发--驱动篇(一),对于的应用篇 看看咱们的开发板,有四个led灯,对吧,这次就是向办法用程序来点亮它,请看下边的代码: #include <stdlib.h ...

  5. Linux嵌入式系统简答题复习

    1. 嵌入式系统的定义是什么? IEEE给出的嵌入式系统定义是:控制.监视或者辅助装置.机器和设备运行的装置. 目前国内的被普遍认同的定义是:以应用为中心,以计算机技术为基础.软件硬件可裁剪.适应应用 ...

  6. (二)Linux嵌入式开发——软件安装(Ubuntu)

    文章目录 (二)Linux嵌入式开发--软件安装(Ubuntu) APP Store APT工具 问题 解决办法1 解决办法2 deb软件包 程序源码 问题1 解决办法 问题2 解决办法 总结 (二) ...

  7. linux嵌入式系统程序加密工具推荐:Virbox Protector.

    linux嵌入式系统程序加密工具推荐:Virbox Protector. 软件开发商 Virbox Protector是由北京深思数盾科技股份有限公司研发,2018年上市的一款加密工具. ARM-Li ...

  8. python车牌识别系统抬杆_昆明车牌识别自动抬杆系统

    您当前的位置:首页 » 供应产品 » 昆明车牌识别自动抬杆系统 昆明车牌识别自动抬杆系统 点击图片查看大图 产品/服务: 浏览次数:679车牌识别自动抬杆系统 规 格: 标准 品 牌: 交安通 单 价 ...

  9. linux嵌入式系统算法,嵌入式Linux操作系统调度算法研究

    嵌入式Linux操作系统调度算法研究 嵌入式操作系统在互联网时代的今天得到广泛应用.Linux系统本身并不是严格的实时操作系统.为了提高它对实时任务的处理能力,国内外对Linux进行了不断的实时性能的 ...

最新文章

  1. DotNet并行计算的使用误区(二)
  2. 前端渐进式框架Vue讲解
  3. 账单比较java代码_Java代码比较两个文件的MD5
  4. WDK开发环境构建驱动程序入门、Windows驱动程序的Check Build和Free Build
  5. C语言试题五之计算并输出给定数组(长度为9)中每相邻两个元素之平均值的平方根之和
  6. 嵌入式码头,Vaadin和焊接
  7. [LeetCode] Power of Two 判断2的次方数
  8. shell脚本中用到的条件和循环语句
  9. 系统总结vue组件间通信、数据传递(父子组件,同级组件)
  10. 乐高无限无法连接到服务器,乐高无限近期热点问题FQ 新手问题解答
  11. MySQL数据库和Oracle数据库的区别
  12. c语言运行VBA,C语言选择题部分模块和VBA.ppt
  13. 介绍10款常用的JAVA测试工具
  14. java 40期_【40期】说一下线程池内部工作原理
  15. Java中迭代Map的方法
  16. 查找对方IP地址经典技巧汇总
  17. Vue 之 下载本地资源文件
  18. 数据包络分析法(DEA) R实现
  19. 推送微信公众号模板消息通知(Java版)
  20. CSS3权威指南读书笔记

热门文章

  1. Passbook详解与开发案例
  2. java springcloud面试题_JAVA语言之springboot+springcloud相关面试题
  3. php foreach 唯一订单号_PHP 单例模式的解析和实战
  4. linux的cc防火墙,SAE打造高性能CC防火墙
  5. 【从零学Python】深拷贝和浅拷贝、二维数组初始化
  6. nn.Softmax(dim=1)(outputs) 与 torch.max(probs, 1)[1]的理解
  7. 怎么看服务器内存型号频率,怎么查看服务器内存频率
  8. django redirect传递参数_Django 视图层(四):视图函数 - views.py
  9. powerpc linux交叉编译器,[转载]搭建PowerPC交叉编译器 二
  10. react-native实现不重启App的情况下更新分包