2 qq 29629287 qq_29629287 于 2015.07.15 15:06 提问

opencv中的一段代码,希望有人可以解释下 5C

还非得输入长度30-10000的问题描述。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
opencv中的一段代码,希望有人可以解释下。
就是从垂直投影开始的代码处 没有看懂,好几个循环, 希望大牛可以帮忙解释下,刚接触OPENCV不久。
难道代码没有 传上来 吗

3个回答

qq_29629287
qq_29629287   2015.07.15 15:05
 ```#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>   
#define  START  57
#define  END  181
#define  MOD_MAX 15
#define  MOD_MIN  3
#define  WIDTH  34 //模板宽度宽度
#define   S(image,x,y) ((uchar*)(image->imageData + image->widthStep*(y)))[(x)]
 int main()
{


    IplImage *src=0;
    IplImage *pImg8uSmooth=NULL;       //高斯滤波后的图
    IplImage *pImgHist=NULL; 
    IplImage *pImgThreshold=NULL;
    IplImage *pImgResize=NULL;        //归一化为高90,宽409的图像
    src=cvLoadImage("E:/image/car1/77.jpg",0);
        if(!src)
            printf("can not load file: %s","E:\\tupain\\1.jpg");
    else
    {  
        int nWidth=409,nHeight=90;
        pImg8uSmooth=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);
        pImgThreshold=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);
        pImgResize=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);//归一化

        cvResize(src,pImgResize,CV_INTER_LINEAR); //线性插值
        cvSmooth(pImgResize,pImg8uSmooth,CV_GAUSSIAN,3,0,0);//高斯滤波
        cvThreshold(pImg8uSmooth,pImgThreshold,100,255,CV_THRESH_BINARY ); 

        int l_sum[409]={0},modle[WIDTH]={0},subre[WIDTH]={0};
        int sum=0,i=0,j=0,k=0,g=0;
        int rig=0,end=0;//分隔符开始与结束位置
        int flag=0;


        modle[0]=MOD_MIN*255;
        modle[1]=MOD_MIN*255;
        modle[WIDTH-1]=MOD_MIN*255;
        modle[WIDTH-2]=MOD_MIN*255;
        for(i=2;i<WIDTH-2;i++)modle[i]=MOD_MAX*255;
        printf("The pImgThreshold->height is:%d and pImgThreshold->width is: %d\n",pImgThreshold->height,pImgThreshold->width);


        printf("垂直投影\n");//垂直投影
        for(i=0;i<pImgThreshold->width;i++)
        {  sum=0;
        for(j=0;j<pImgThreshold->height;j++)
        {
            sum=S(pImgThreshold,i,j)+sum;//灰度之和
        }
        l_sum[i]=sum;
        //printf("The l_sum[%d]=%d\n",i,l_sum[i]);
        }

        flag=0;
        int m=WIDTH;
        while(m>7)
        { 
            for(i=START;i+m<END;i++)
            {  

                for(j=0,g=i;j<m;j++,g++)
                {
                    subre[j]=modle[j]-l_sum[g];
                    // printf("The subre[%d]=%d\n",j,subre[j]);
                    //  printf("The l_sum[%d]=%d\n",g,l_sum[g]);
                }

                j=0;
                while(subre[j]>0&&j<m)j++;
                if(j==m)
                {
                    flag=1;
                    rig=i; 
                    end=rig+m;
                    break;
                }
            }

            if(!flag)
            {
                modle[m-3]=modle[m-1];
                modle[m-4]=modle[m-2];
                m--; 
            }
            else break;

        }
        if(m<=7) printf("have not found the rig and end",rig,end);
        printf("orig=%d and  end=%d\n",rig,end);


        int min_value=0,min_col=0;//最小值及其所在列
        int oneright=0,oneleft=0,twoleft=0,threeright=0,fourleft=0,fourright=0,fiveleft=0,fiveright=0,sixleft=0,sixright=0,sevenleft=0,sevenright=0;
        i=rig-(int)((45/90.0)*pImgThreshold->height)-1;
        min_value=l_sum[i];
        min_col=i;
        for(;i>=rig-(int)((57/90.0)*pImgThreshold->height)-1;i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                twoleft=i;break;
            }      
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the twoleft\n");
            twoleft=rig-(int)((51/90.0)*pImgThreshold->height);
        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                oneright=i;break;
            }                     
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the oneright\n");
            oneright=rig-(int)((51/90.0)*pImgThreshold->height);
        }

        printf("the oneright=%d and twoleft=%d\n",oneright,twoleft);



        i=oneright-(int)((40/90.0)*pImgThreshold->height)-1;
        min_value=l_sum[i];
        min_col=i;
        for(;i>=oneright-(int)((52/90.0)*pImgThreshold->height)-1;i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }
        }
        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                oneleft=i;break;
            }      
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the oneleft\n");
            oneleft=oneright-(int)((51/90.0)*pImgThreshold->height);
        }    
        if(oneleft<0){ oneleft=0;printf("have not found  the oneleft\n");}
        printf("the oneleft=%d\n",oneleft);

        i=end+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=end+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                threeright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the threerigth\n");
            threeright=end+(51/90)*pImgThreshold->height;
        }

        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fourleft=i;break;
            }      
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            //printf("hvan not found the fourleft\n");
            fourleft=end+(51/90)*pImgThreshold->height;
        }
        printf("the threeright=%d and the fourletf=%d\n",threeright,fourleft);

        i=fourleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=fourleft+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }
        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fourright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fouright\n");
            fourright=fourleft+(int)((51/90.0)*pImgThreshold->height);
        }

        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fiveleft=i;break;
            }                     
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fiveright\n");
            fiveleft=fourleft+(int)((51/90.0)*pImgThreshold->height);
        }
        printf("the fourright=%d and the fiveleft=%d\n",fourright,fiveleft);
        i=fiveleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=fiveleft+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fiveright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fiveright\n");
            fiveright=fiveleft+(int)((51/90.0)*pImgThreshold->height);
        }


        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sixleft=i;break;
            }                     
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the sixright\n");
            sixleft= fiveleft+(int)((51/90.0)*pImgThreshold->height);
        }
        printf("the fiveright=%d and the sixleft=%d\n",fiveright,sixleft);

        i=sixleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=sixleft+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sixright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            //printf("hvan not found the fiveright\n");
            sixright=sixleft+(int)((51/90.0)*pImgThreshold->height);
        }


        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sevenleft=i;break;
            }                     
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the sixright\n");
            sevenleft=sixleft+(int)((51/90.0)*pImgThreshold->height);
        }
        printf("the sixright=%d and the sevenleft=%d\n",sixright,sevenleft);
        i=sevenleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;(i<=sevenleft+(int)((57/90.0)*pImgThreshold->height))&&i<pImgThreshold->width;i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sevenright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fiveright\n");
            sevenright=sevenleft+(int)((51/90.0)*pImgThreshold->height);
        }
        if(sevenright>pImgThreshold->width-1){ sevenright=pImgThreshold->width-1;printf("have not found  the sevenright\n");}
        printf("the sevenrigh=%d\n", sevenright);

        cvLine(pImgThreshold,cvPoint(oneleft,0),cvPoint(oneleft,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(oneright,0),cvPoint(oneright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(twoleft,0),cvPoint(twoleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(rig,0),cvPoint(rig,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(end,0),cvPoint(end,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(threeright,0),cvPoint(threeright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fourleft,0),cvPoint(fourleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fourright,0),cvPoint(fourright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fiveleft,0),cvPoint(fiveleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fiveright,0),cvPoint(fiveright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sixleft,0),cvPoint(sixleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sixright,0),cvPoint(sixright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sevenleft,0),cvPoint(sevenleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sevenright,0),cvPoint(sevenright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);



        IplImage *pImgCharOne=NULL;//截取字符
        IplImage *pImgCharTwo=NULL;
        IplImage *pImgCharThree=NULL;
        IplImage *pImgCharFour=NULL;
        IplImage *pImgCharFive=NULL;
        IplImage *pImgCharSix=NULL;
        IplImage *pImgCharSeven=NULL;
        pImgCharOne=cvCreateImage(cvSize(oneright-oneleft+1,nHeight),IPL_DEPTH_8U,1);
        pImgCharTwo=cvCreateImage(cvSize(rig-twoleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharThree=cvCreateImage(cvSize(threeright-end+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharFour=cvCreateImage(cvSize(fourright-fourleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharFive=cvCreateImage(cvSize(fiveright-fiveleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharSix=cvCreateImage(cvSize(sixright-sixleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharSeven=cvCreateImage(cvSize(sevenright-sevenleft+1,nHeight),IPL_DEPTH_8U,1);

        CvRect ROI_rect1;
        ROI_rect1.x=oneleft;
        ROI_rect1.y=0;
        ROI_rect1.width=oneright-oneleft+1;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharOne,NULL); //获取第1个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=twoleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=rig-twoleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharTwo,NULL); //获取第2个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=end-1;
        ROI_rect1.y=0;
        ROI_rect1.width=threeright-end+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharThree,NULL); //获取第3个字符
        cvResetImageROI(pImgResize);


        ROI_rect1.x=fourleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=fourright-fourleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharFour,NULL); //获取第4个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=fiveleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=fiveright-fiveleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharFive,NULL); //获取第5个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=sixleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=sixright-sixleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharSix,NULL); //获取第6个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=sevenleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=sevenright-sevenleft+1;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharSeven,NULL); //获取第7个字符
        cvResetImageROI(pImgResize);


        cvNamedWindow("垂直投影",CV_WINDOW_AUTOSIZE);
        cvMoveWindow("垂直投影",0,0);
        cvShowImage("垂直投影",pImgThreshold);
        //cvSaveImage("E:\\new\\23.jpg",pImgThreshold);

        cvNamedWindow("one",CV_WINDOW_AUTOSIZE);
        cvMoveWindow("one",0,300);
        cvShowImage("one",pImgCharOne);

        cvNamedWindow("two",1);
        cvMoveWindow("two",50,300);
        cvShowImage("two",pImgCharTwo);
        //cvSaveImage("E:\\library\\0.jpg",pImgCharTwo);

        cvNamedWindow("three",1);
        cvMoveWindow("three",100,300);
        cvShowImage("three",pImgCharThree);
        //cvSaveImage("E:\\library\\0.jpg",pImgCharThree);

        cvNamedWindow("four",1);
        cvMoveWindow("four",150,300);
        cvShowImage("four",pImgCharFour);
        //cvSaveImage("E:\\library\\17.jpg",pImgCharFour);

        cvNamedWindow("five",1);
        cvMoveWindow("five",200,300);
        cvShowImage("five",pImgCharFive);
        //cvSaveImage("E:\\library\\3.jpg",pImgCharFive);

        cvNamedWindow("six",1);
        cvMoveWindow("six",250,300);
        cvShowImage("six",pImgCharSix);
        //cvSaveImage("E:\\library\\1.jpg",pImgCharSix);

        cvNamedWindow("seven",1);
        cvMoveWindow("seven",300,300);
        cvShowImage("seven",pImgCharSeven);
        //cvSaveImage("E:\\library\\14.jpg",pImgCharSeven);

        cvWaitKey();

        cvReleaseImage(&pImgThreshold);
        cvDestroyWindow("显示高斯滤波后图像");
        cvDestroyWindow("one");
        cvReleaseImage(&pImgCharOne);
        cvDestroyWindow("two");
        cvReleaseImage(&pImgCharTwo);
        cvDestroyWindow("three");
        cvReleaseImage(&pImgCharThree);
        cvDestroyWindow("four");
        cvReleaseImage(&pImgCharFour);
        cvDestroyWindow("five");
        cvReleaseImage(&pImgCharFive);
        cvDestroyWindow("six");
        cvReleaseImage(&pImgCharSix);
        cvDestroyWindow("seven");
        cvReleaseImage(&pImgCharSeven);
        return -1;
    }
    return 0;
}   
qq_29629287
qq_29629287   2015.07.15 15:06
 ```#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>   
#define  START  57
#define  END  181
#define  MOD_MAX 15
#define  MOD_MIN  3
#define  WIDTH  34 //模板宽度宽度
#define   S(image,x,y) ((uchar*)(image->imageData + image->widthStep*(y)))[(x)]
 int main()
{


    IplImage *src=0;
    IplImage *pImg8uSmooth=NULL;       //高斯滤波后的图
    IplImage *pImgHist=NULL; 
    IplImage *pImgThreshold=NULL;
    IplImage *pImgResize=NULL;        //归一化为高90,宽409的图像
    src=cvLoadImage("E:/image/car1/77.jpg",0);
        if(!src)
            printf("can not load file: %s","E:\\tupain\\1.jpg");
    else
    {  
        int nWidth=409,nHeight=90;
        pImg8uSmooth=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);
        pImgThreshold=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);
        pImgResize=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);//归一化

        cvResize(src,pImgResize,CV_INTER_LINEAR); //线性插值
        cvSmooth(pImgResize,pImg8uSmooth,CV_GAUSSIAN,3,0,0);//高斯滤波
        cvThreshold(pImg8uSmooth,pImgThreshold,100,255,CV_THRESH_BINARY ); 

        int l_sum[409]={0},modle[WIDTH]={0},subre[WIDTH]={0};
        int sum=0,i=0,j=0,k=0,g=0;
        int rig=0,end=0;//分隔符开始与结束位置
        int flag=0;


        modle[0]=MOD_MIN*255;
        modle[1]=MOD_MIN*255;
        modle[WIDTH-1]=MOD_MIN*255;
        modle[WIDTH-2]=MOD_MIN*255;
        for(i=2;i<WIDTH-2;i++)modle[i]=MOD_MAX*255;
        printf("The pImgThreshold->height is:%d and pImgThreshold->width is: %d\n",pImgThreshold->height,pImgThreshold->width);


        printf("垂直投影\n");//垂直投影
        for(i=0;i<pImgThreshold->width;i++)
        {  sum=0;
        for(j=0;j<pImgThreshold->height;j++)
        {
            sum=S(pImgThreshold,i,j)+sum;//灰度之和
        }
        l_sum[i]=sum;
        //printf("The l_sum[%d]=%d\n",i,l_sum[i]);
        }

        flag=0;
        int m=WIDTH;
        while(m>7)
        { 
            for(i=START;i+m<END;i++)
            {  

                for(j=0,g=i;j<m;j++,g++)
                {
                    subre[j]=modle[j]-l_sum[g];
                    // printf("The subre[%d]=%d\n",j,subre[j]);
                    //  printf("The l_sum[%d]=%d\n",g,l_sum[g]);
                }

                j=0;
                while(subre[j]>0&&j<m)j++;
                if(j==m)
                {
                    flag=1;
                    rig=i; 
                    end=rig+m;
                    break;
                }
            }

            if(!flag)
            {
                modle[m-3]=modle[m-1];
                modle[m-4]=modle[m-2];
                m--; 
            }
            else break;

        }
        if(m<=7) printf("have not found the rig and end",rig,end);
        printf("orig=%d and  end=%d\n",rig,end);


        int min_value=0,min_col=0;//最小值及其所在列
        int oneright=0,oneleft=0,twoleft=0,threeright=0,fourleft=0,fourright=0,fiveleft=0,fiveright=0,sixleft=0,sixright=0,sevenleft=0,sevenright=0;
        i=rig-(int)((45/90.0)*pImgThreshold->height)-1;
        min_value=l_sum[i];
        min_col=i;
        for(;i>=rig-(int)((57/90.0)*pImgThreshold->height)-1;i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                twoleft=i;break;
            }      
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the twoleft\n");
            twoleft=rig-(int)((51/90.0)*pImgThreshold->height);
        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                oneright=i;break;
            }                     
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the oneright\n");
            oneright=rig-(int)((51/90.0)*pImgThreshold->height);
        }

        printf("the oneright=%d and twoleft=%d\n",oneright,twoleft);



        i=oneright-(int)((40/90.0)*pImgThreshold->height)-1;
        min_value=l_sum[i];
        min_col=i;
        for(;i>=oneright-(int)((52/90.0)*pImgThreshold->height)-1;i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }
        }
        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                oneleft=i;break;
            }      
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the oneleft\n");
            oneleft=oneright-(int)((51/90.0)*pImgThreshold->height);
        }    
        if(oneleft<0){ oneleft=0;printf("have not found  the oneleft\n");}
        printf("the oneleft=%d\n",oneleft);

        i=end+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=end+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                threeright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the threerigth\n");
            threeright=end+(51/90)*pImgThreshold->height;
        }

        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fourleft=i;break;
            }      
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            //printf("hvan not found the fourleft\n");
            fourleft=end+(51/90)*pImgThreshold->height;
        }
        printf("the threeright=%d and the fourletf=%d\n",threeright,fourleft);

        i=fourleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=fourleft+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }
        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fourright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fouright\n");
            fourright=fourleft+(int)((51/90.0)*pImgThreshold->height);
        }

        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fiveleft=i;break;
            }                     
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fiveright\n");
            fiveleft=fourleft+(int)((51/90.0)*pImgThreshold->height);
        }
        printf("the fourright=%d and the fiveleft=%d\n",fourright,fiveleft);
        i=fiveleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=fiveleft+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                fiveright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fiveright\n");
            fiveright=fiveleft+(int)((51/90.0)*pImgThreshold->height);
        }


        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sixleft=i;break;
            }                     
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the sixright\n");
            sixleft= fiveleft+(int)((51/90.0)*pImgThreshold->height);
        }
        printf("the fiveright=%d and the sixleft=%d\n",fiveright,sixleft);

        i=sixleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;i<=sixleft+(int)((57/90.0)*pImgThreshold->height);i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sixright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            //printf("hvan not found the fiveright\n");
            sixright=sixleft+(int)((51/90.0)*pImgThreshold->height);
        }


        for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sevenleft=i;break;
            }                     
        }
        if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the sixright\n");
            sevenleft=sixleft+(int)((51/90.0)*pImgThreshold->height);
        }
        printf("the sixright=%d and the sevenleft=%d\n",sixright,sevenleft);
        i=sevenleft+(int)((45/90.0)*pImgThreshold->height)+1;
        min_value=l_sum[i];
        min_col=i;
        for(;(i<=sevenleft+(int)((57/90.0)*pImgThreshold->height))&&i<pImgThreshold->width;i++)
        {
            // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(min_value>l_sum[i])
            { 
                min_value=l_sum[i];
                min_col=i;  
            }

        }
        for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
        {
            //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
            if(l_sum[i]>3*255)
            {
                sevenright=i;break;
            }      
        }
        if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
        {
            printf("hvan not found the fiveright\n");
            sevenright=sevenleft+(int)((51/90.0)*pImgThreshold->height);
        }
        if(sevenright>pImgThreshold->width-1){ sevenright=pImgThreshold->width-1;printf("have not found  the sevenright\n");}
        printf("the sevenrigh=%d\n", sevenright);

        cvLine(pImgThreshold,cvPoint(oneleft,0),cvPoint(oneleft,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(oneright,0),cvPoint(oneright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(twoleft,0),cvPoint(twoleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(rig,0),cvPoint(rig,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(end,0),cvPoint(end,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(threeright,0),cvPoint(threeright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fourleft,0),cvPoint(fourleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fourright,0),cvPoint(fourright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fiveleft,0),cvPoint(fiveleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(fiveright,0),cvPoint(fiveright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sixleft,0),cvPoint(sixleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sixright,0),cvPoint(sixright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sevenleft,0),cvPoint(sevenleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
        cvLine(pImgThreshold,cvPoint(sevenright,0),cvPoint(sevenright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);



        IplImage *pImgCharOne=NULL;//截取字符
        IplImage *pImgCharTwo=NULL;
        IplImage *pImgCharThree=NULL;
        IplImage *pImgCharFour=NULL;
        IplImage *pImgCharFive=NULL;
        IplImage *pImgCharSix=NULL;
        IplImage *pImgCharSeven=NULL;
        pImgCharOne=cvCreateImage(cvSize(oneright-oneleft+1,nHeight),IPL_DEPTH_8U,1);
        pImgCharTwo=cvCreateImage(cvSize(rig-twoleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharThree=cvCreateImage(cvSize(threeright-end+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharFour=cvCreateImage(cvSize(fourright-fourleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharFive=cvCreateImage(cvSize(fiveright-fiveleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharSix=cvCreateImage(cvSize(sixright-sixleft+2,nHeight),IPL_DEPTH_8U,1);
        pImgCharSeven=cvCreateImage(cvSize(sevenright-sevenleft+1,nHeight),IPL_DEPTH_8U,1);

        CvRect ROI_rect1;
        ROI_rect1.x=oneleft;
        ROI_rect1.y=0;
        ROI_rect1.width=oneright-oneleft+1;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharOne,NULL); //获取第1个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=twoleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=rig-twoleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharTwo,NULL); //获取第2个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=end-1;
        ROI_rect1.y=0;
        ROI_rect1.width=threeright-end+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharThree,NULL); //获取第3个字符
        cvResetImageROI(pImgResize);


        ROI_rect1.x=fourleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=fourright-fourleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharFour,NULL); //获取第4个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=fiveleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=fiveright-fiveleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharFive,NULL); //获取第5个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=sixleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=sixright-sixleft+2;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharSix,NULL); //获取第6个字符
        cvResetImageROI(pImgResize);

        ROI_rect1.x=sevenleft-1;
        ROI_rect1.y=0;
        ROI_rect1.width=sevenright-sevenleft+1;
        ROI_rect1.height=pImgResize->height;
        cvSetImageROI(pImgResize,ROI_rect1);
        cvCopy(pImgResize,pImgCharSeven,NULL); //获取第7个字符
        cvResetImageROI(pImgResize);


        cvNamedWindow("垂直投影",CV_WINDOW_AUTOSIZE);
        cvMoveWindow("垂直投影",0,0);
        cvShowImage("垂直投影",pImgThreshold);
        //cvSaveImage("E:\\new\\23.jpg",pImgThreshold);

        cvNamedWindow("one",CV_WINDOW_AUTOSIZE);
        cvMoveWindow("one",0,300);
        cvShowImage("one",pImgCharOne);

        cvNamedWindow("two",1);
        cvMoveWindow("two",50,300);
        cvShowImage("two",pImgCharTwo);
        //cvSaveImage("E:\\library\\0.jpg",pImgCharTwo);

        cvNamedWindow("three",1);
        cvMoveWindow("three",100,300);
        cvShowImage("three",pImgCharThree);
        //cvSaveImage("E:\\library\\0.jpg",pImgCharThree);

        cvNamedWindow("four",1);
        cvMoveWindow("four",150,300);
        cvShowImage("four",pImgCharFour);
        //cvSaveImage("E:\\library\\17.jpg",pImgCharFour);

        cvNamedWindow("five",1);
        cvMoveWindow("five",200,300);
        cvShowImage("five",pImgCharFive);
        //cvSaveImage("E:\\library\\3.jpg",pImgCharFive);

        cvNamedWindow("six",1);
        cvMoveWindow("six",250,300);
        cvShowImage("six",pImgCharSix);
        //cvSaveImage("E:\\library\\1.jpg",pImgCharSix);

        cvNamedWindow("seven",1);
        cvMoveWindow("seven",300,300);
        cvShowImage("seven",pImgCharSeven);
        //cvSaveImage("E:\\library\\14.jpg",pImgCharSeven);

        cvWaitKey();

        cvReleaseImage(&pImgThreshold);
        cvDestroyWindow("显示高斯滤波后图像");
        cvDestroyWindow("one");
        cvReleaseImage(&pImgCharOne);
        cvDestroyWindow("two");
        cvReleaseImage(&pImgCharTwo);
        cvDestroyWindow("three");
        cvReleaseImage(&pImgCharThree);
        cvDestroyWindow("four");
        cvReleaseImage(&pImgCharFour);
        cvDestroyWindow("five");
        cvReleaseImage(&pImgCharFive);
        cvDestroyWindow("six");
        cvReleaseImage(&pImgCharSix);
        cvDestroyWindow("seven");
        cvReleaseImage(&pImgCharSeven);
        return -1;
    }
    return 0;
}   
qq_29629287
qq_29629287   2015.07.15 15:29

#include
#include
#include
#include

#define START 57
#define END 181
#define MOD_MAX 15
#define MOD_MIN 3
#define WIDTH 34 //模板宽度宽度
#define S(image,x,y) ((uchar*)(image->imageData + image->widthStep*(y)))[(x)]
int main()
{

IplImage *src=0;
IplImage *pImg8uSmooth=NULL;       //高斯滤波后的图
IplImage *pImgHist=NULL; 
IplImage *pImgThreshold=NULL;
IplImage *pImgResize=NULL;        //归一化为高90,宽409的图像
src=cvLoadImage("E:/image/car1/77.jpg",0);
    if(!src)
        printf("can not load file: %s","E:\\tupain\\1.jpg");
else
{  
    int nWidth=409,nHeight=90;
    pImg8uSmooth=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);
    pImgThreshold=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);
    pImgResize=cvCreateImage(cvSize(nWidth,nHeight),IPL_DEPTH_8U,1);//归一化

    cvResize(src,pImgResize,CV_INTER_LINEAR); //线性插值
    cvSmooth(pImgResize,pImg8uSmooth,CV_GAUSSIAN,3,0,0);//高斯滤波
    cvThreshold(pImg8uSmooth,pImgThreshold,100,255,CV_THRESH_BINARY ); 

    int l_sum[409]={0},modle[WIDTH]={0},subre[WIDTH]={0};
    int sum=0,i=0,j=0,k=0,g=0;
    int rig=0,end=0;//分隔符开始与结束位置
    int flag=0;


    modle[0]=MOD_MIN*255;
    modle[1]=MOD_MIN*255;
    modle[WIDTH-1]=MOD_MIN*255;
    modle[WIDTH-2]=MOD_MIN*255;
    for(i=2;i<WIDTH-2;i++)modle[i]=MOD_MAX*255;
    printf("The pImgThreshold->height is:%d and pImgThreshold->width is: %d\n",pImgThreshold->height,pImgThreshold->width);


    printf("垂直投影\n");//垂直投影
    for(i=0;i<pImgThreshold->width;i++)
    {  sum=0;
    for(j=0;j<pImgThreshold->height;j++)
    {
        sum=S(pImgThreshold,i,j)+sum;//灰度之和
    }
    l_sum[i]=sum;
    //printf("The l_sum[%d]=%d\n",i,l_sum[i]);
    }

    flag=0;
    int m=WIDTH;
    while(m>7)
    { 
        for(i=START;i+m<END;i++)
        {  

            for(j=0,g=i;j<m;j++,g++)
            {
                subre[j]=modle[j]-l_sum[g];
                // printf("The subre[%d]=%d\n",j,subre[j]);
                //  printf("The l_sum[%d]=%d\n",g,l_sum[g]);
            }

            j=0;
            while(subre[j]>0&&j<m)j++;
            if(j==m)
            {
                flag=1;
                rig=i; 
                end=rig+m;
                break;
            }
        }

        if(!flag)
        {
            modle[m-3]=modle[m-1];
            modle[m-4]=modle[m-2];
            m--; 
        }
        else break;

    }
    if(m<=7) printf("have not found the rig and end",rig,end);
    printf("orig=%d and  end=%d\n",rig,end);


    int min_value=0,min_col=0;//最小值及其所在列
    int oneright=0,oneleft=0,twoleft=0,threeright=0,fourleft=0,fourright=0,fiveleft=0,fiveright=0,sixleft=0,sixright=0,sevenleft=0,sevenright=0;
    i=rig-(int)((45/90.0)*pImgThreshold->height)-1;
    min_value=l_sum[i];
    min_col=i;
    for(;i>=rig-(int)((57/90.0)*pImgThreshold->height)-1;i--)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }

    }
    for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            twoleft=i;break;
        }      
    }
    if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the twoleft\n");
        twoleft=rig-(int)((51/90.0)*pImgThreshold->height);
    }
    for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            oneright=i;break;
        }                     
    }
    if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the oneright\n");
        oneright=rig-(int)((51/90.0)*pImgThreshold->height);
    }

    printf("the oneright=%d and twoleft=%d\n",oneright,twoleft);



    i=oneright-(int)((40/90.0)*pImgThreshold->height)-1;
    min_value=l_sum[i];
    min_col=i;
    for(;i>=oneright-(int)((52/90.0)*pImgThreshold->height)-1;i--)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }
    }
    for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            oneleft=i;break;
        }      
    }
    if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the oneleft\n");
        oneleft=oneright-(int)((51/90.0)*pImgThreshold->height);
    }    
    if(oneleft<0){ oneleft=0;printf("have not found  the oneleft\n");}
    printf("the oneleft=%d\n",oneleft);

    i=end+(int)((45/90.0)*pImgThreshold->height)+1;
    min_value=l_sum[i];
    min_col=i;
    for(;i<=end+(int)((57/90.0)*pImgThreshold->height);i++)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }

    }
    for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            threeright=i;break;
        }      
    }
    if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the threerigth\n");
        threeright=end+(51/90)*pImgThreshold->height;
    }

    for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            fourleft=i;break;
        }      
    }
    if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
    {
        //printf("hvan not found the fourleft\n");
        fourleft=end+(51/90)*pImgThreshold->height;
    }
    printf("the threeright=%d and the fourletf=%d\n",threeright,fourleft);

    i=fourleft+(int)((45/90.0)*pImgThreshold->height)+1;
    min_value=l_sum[i];
    min_col=i;
    for(;i<=fourleft+(int)((57/90.0)*pImgThreshold->height);i++)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }
    }
    for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            fourright=i;break;
        }      
    }
    if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the fouright\n");
        fourright=fourleft+(int)((51/90.0)*pImgThreshold->height);
    }

    for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            fiveleft=i;break;
        }                     
    }
    if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the fiveright\n");
        fiveleft=fourleft+(int)((51/90.0)*pImgThreshold->height);
    }
    printf("the fourright=%d and the fiveleft=%d\n",fourright,fiveleft);
    i=fiveleft+(int)((45/90.0)*pImgThreshold->height)+1;
    min_value=l_sum[i];
    min_col=i;
    for(;i<=fiveleft+(int)((57/90.0)*pImgThreshold->height);i++)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }

    }
    for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            fiveright=i;break;
        }      
    }
    if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the fiveright\n");
        fiveright=fiveleft+(int)((51/90.0)*pImgThreshold->height);
    }


    for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            sixleft=i;break;
        }                     
    }
    if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the sixright\n");
        sixleft= fiveleft+(int)((51/90.0)*pImgThreshold->height);
    }
    printf("the fiveright=%d and the sixleft=%d\n",fiveright,sixleft);

    i=sixleft+(int)((45/90.0)*pImgThreshold->height)+1;
    min_value=l_sum[i];
    min_col=i;
    for(;i<=sixleft+(int)((57/90.0)*pImgThreshold->height);i++)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }

    }
    for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            sixright=i;break;
        }      
    }
    if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
    {
        //printf("hvan not found the fiveright\n");
        sixright=sixleft+(int)((51/90.0)*pImgThreshold->height);
    }


    for(i=min_col;i<min_col+(int)((12/90.0)*pImgThreshold->height);i++)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            sevenleft=i;break;
        }                     
    }
    if(i>=min_col+(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the sixright\n");
        sevenleft=sixleft+(int)((51/90.0)*pImgThreshold->height);
    }
    printf("the sixright=%d and the sevenleft=%d\n",sixright,sevenleft);
    i=sevenleft+(int)((45/90.0)*pImgThreshold->height)+1;
    min_value=l_sum[i];
    min_col=i;
    for(;(i<=sevenleft+(int)((57/90.0)*pImgThreshold->height))&&i<pImgThreshold->width;i++)
    {
        // printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(min_value>l_sum[i])
        { 
            min_value=l_sum[i];
            min_col=i;  
        }

    }
    for(i=min_col;i>min_col-(int)((12/90.0)*pImgThreshold->height);i--)
    {
        //printf ("l_sum[%d]=%d\n",i,l_sum[i]);
        if(l_sum[i]>3*255)
        {
            sevenright=i;break;
        }      
    }
    if(i<=min_col-(int)((12/90.0)*pImgThreshold->height))
    {
        printf("hvan not found the fiveright\n");
        sevenright=sevenleft+(int)((51/90.0)*pImgThreshold->height);
    }
    if(sevenright>pImgThreshold->width-1){ sevenright=pImgThreshold->width-1;printf("have not found  the sevenright\n");}
    printf("the sevenrigh=%d\n", sevenright);

    cvLine(pImgThreshold,cvPoint(oneleft,0),cvPoint(oneleft,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(oneright,0),cvPoint(oneright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(twoleft,0),cvPoint(twoleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(rig,0),cvPoint(rig,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(end,0),cvPoint(end,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(threeright,0),cvPoint(threeright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(fourleft,0),cvPoint(fourleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(fourright,0),cvPoint(fourright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(fiveleft,0),cvPoint(fiveleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(fiveright,0),cvPoint(fiveright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(sixleft,0),cvPoint(sixleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(sixright,0),cvPoint(sixright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(sevenleft,0),cvPoint(sevenleft,pImgThreshold->height),cvScalar(255,0,0),1,8,0);
    cvLine(pImgThreshold,cvPoint(sevenright,0),cvPoint(sevenright,pImgThreshold->height),cvScalar(188,0,0),1,8,0);



    IplImage *pImgCharOne=NULL;//截取字符
    IplImage *pImgCharTwo=NULL;
    IplImage *pImgCharThree=NULL;
    IplImage *pImgCharFour=NULL;
    IplImage *pImgCharFive=NULL;
    IplImage *pImgCharSix=NULL;
    IplImage *pImgCharSeven=NULL;
    pImgCharOne=cvCreateImage(cvSize(oneright-oneleft+1,nHeight),IPL_DEPTH_8U,1);
    pImgCharTwo=cvCreateImage(cvSize(rig-twoleft+2,nHeight),IPL_DEPTH_8U,1);
    pImgCharThree=cvCreateImage(cvSize(threeright-end+2,nHeight),IPL_DEPTH_8U,1);
    pImgCharFour=cvCreateImage(cvSize(fourright-fourleft+2,nHeight),IPL_DEPTH_8U,1);
    pImgCharFive=cvCreateImage(cvSize(fiveright-fiveleft+2,nHeight),IPL_DEPTH_8U,1);
    pImgCharSix=cvCreateImage(cvSize(sixright-sixleft+2,nHeight),IPL_DEPTH_8U,1);
    pImgCharSeven=cvCreateImage(cvSize(sevenright-sevenleft+1,nHeight),IPL_DEPTH_8U,1);

    CvRect ROI_rect1;
    ROI_rect1.x=oneleft;
    ROI_rect1.y=0;
    ROI_rect1.width=oneright-oneleft+1;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharOne,NULL); //获取第1个字符
    cvResetImageROI(pImgResize);

    ROI_rect1.x=twoleft-1;
    ROI_rect1.y=0;
    ROI_rect1.width=rig-twoleft+2;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharTwo,NULL); //获取第2个字符
    cvResetImageROI(pImgResize);

    ROI_rect1.x=end-1;
    ROI_rect1.y=0;
    ROI_rect1.width=threeright-end+2;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharThree,NULL); //获取第3个字符
    cvResetImageROI(pImgResize);


    ROI_rect1.x=fourleft-1;
    ROI_rect1.y=0;
    ROI_rect1.width=fourright-fourleft+2;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharFour,NULL); //获取第4个字符
    cvResetImageROI(pImgResize);

    ROI_rect1.x=fiveleft-1;
    ROI_rect1.y=0;
    ROI_rect1.width=fiveright-fiveleft+2;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharFive,NULL); //获取第5个字符
    cvResetImageROI(pImgResize);

    ROI_rect1.x=sixleft-1;
    ROI_rect1.y=0;
    ROI_rect1.width=sixright-sixleft+2;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharSix,NULL); //获取第6个字符
    cvResetImageROI(pImgResize);

    ROI_rect1.x=sevenleft-1;
    ROI_rect1.y=0;
    ROI_rect1.width=sevenright-sevenleft+1;
    ROI_rect1.height=pImgResize->height;
    cvSetImageROI(pImgResize,ROI_rect1);
    cvCopy(pImgResize,pImgCharSeven,NULL); //获取第7个字符
    cvResetImageROI(pImgResize);


    cvNamedWindow("垂直投影",CV_WINDOW_AUTOSIZE);
    cvMoveWindow("垂直投影",0,0);
    cvShowImage("垂直投影",pImgThreshold);
    //cvSaveImage("E:\\new\\23.jpg",pImgThreshold);

    cvNamedWindow("one",CV_WINDOW_AUTOSIZE);
    cvMoveWindow("one",0,300);
    cvShowImage("one",pImgCharOne);
    cvSaveImage("E:/image/car/1.jpg",pImgCharTwo);

    cvNamedWindow("two",1);
    cvMoveWindow("two",50,300);
    cvShowImage("two",pImgCharTwo);
    cvSaveImage("E:/image/car/2.jpg",pImgCharTwo);

    cvNamedWindow("three",1);
    cvMoveWindow("three",100,300);
    cvShowImage("three",pImgCharThree);
    cvSaveImage("E:/image/car/3.jpg",pImgCharThree);

    cvNamedWindow("four",1);
    cvMoveWindow("four",150,300);
    cvShowImage("four",pImgCharFour);
    cvSaveImage("E:/image/car/4.jpg",pImgCharFour);

    cvNamedWindow("five",1);
    cvMoveWindow("five",200,300);
    cvShowImage("five",pImgCharFive);
    cvSaveImage("E:/image/car/5.jpg",pImgCharFive);

    cvNamedWindow("six",1);
    cvMoveWindow("six",250,300);
    cvShowImage("six",pImgCharSix);
    cvSaveImage("E:/image/car/6.jpg",pImgCharSix);

    cvNamedWindow("seven",1);
    cvMoveWindow("seven",300,300);
    cvShowImage("seven",pImgCharSeven);
    cvSaveImage("E:/image/car/7.jpg",pImgCharSeven);

    cvWaitKey();

    cvReleaseImage(&pImgThreshold);
    cvDestroyWindow("显示高斯滤波后图像");
    cvDestroyWindow("one");
    cvReleaseImage(&pImgCharOne);
    cvDestroyWindow("two");
    cvReleaseImage(&pImgCharTwo);
    cvDestroyWindow("three");
    cvReleaseImage(&pImgCharThree);
    cvDestroyWindow("four");
    cvReleaseImage(&pImgCharFour);
    cvDestroyWindow("five");
    cvReleaseImage(&pImgCharFive);
    cvDestroyWindow("six");
    cvReleaseImage(&pImgCharSix);
    cvDestroyWindow("seven");
    cvReleaseImage(&pImgCharSeven);
    return -1;
}
不用每句都标注  帮我解释下大致思路就好。 这是一个车牌字符分割的代码
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
一段代码解析JAVA中的多态
直接贴代码
opencv检查图片中是否有人
使用opencv2.4.9检查图片中是否有人存在
matlab、vc++6.0、opencv多行注释快捷键
一、 matlab常用的多行注释 第一种方法: 直接在代码前面输入 % 第二种方法: 点击ctrl+R,注释程序;可多次点击,多次注释同一次选中的代码; 点击ctrl+T,取消注释程序。 第三种方法: 注释:%{。。。。。}% 取消注释的话,将%{ 和 %}删除即可。 二、 vc++6.0自定义多行注释 1、介绍有要找到vc安装路径,添加代码,我
前端基础之——网页文本与段落信息组织 (二)
上一章讲到了初识HTML的格式,这一章了解一下网页文本与段落信息组织 本文主要讲解: 文本基本标记 标题元素标记 段落元素标记 文本的间隔和布局 水平分割线元素标记 文本的样式设置 1 网页文本与段落信息组织  1.1 文本基本标记 标记用来控制字体、字号和颜色等属性。它是HTML中最基本的标记之一。 1.1.1 字体属性face face标记用于设置文本所采用的字体名称。
计算代码段运行时间(openCV版)
1.为了衡量函数或代码段的运行时间,openCV有一个很实用的函数:cv::getTickCount(),该函数返回从最近一次电脑开机到当前的时钟周期数。 2.为了得到代码的运行时间,还需要另外一个函数:cv::getTickFrequency(),这个函数返回每秒的时钟周期数。 3.最后,可以利用以下的程序模板来计算某个函数或者代码段的运行时间,单位为秒: const int64 star
一个java计算器(我自己的代码,分享,请教)
学java时写的一段代码,是在没有东西可以挣分啊,希望有人愿意看这代码 GUI 内部类 异常 还有什么我没复习 都有点不记得了
用opencv显示一张图像和播放一段视频,写入视频到文件
#include &amp;amp;amp;quot;mainwindow.h&amp;amp;amp;quot; #include &amp;amp;amp;amp;lt;QApplication&amp;amp;amp;amp;gt; #include &amp;amp;amp;amp;lt;iostream&amp;amp;amp;amp;gt; #include &amp;amp;amp;amp;lt;string&amp;amp;amp;amp;gt; #include &amp;amp;amp;
OpenCV自学笔记7:人脸检测 之 静态图像中的人脸检测
人脸检测 之 静态图像中的人脸检测OpenCV为我们提供了Harr分类器。我们使用预先训练好的人脸检测器haarcascade_frontalface_default.xml就可以运行人脸检测程序。haarcascade_frontalface_default.xml是一个xml格式的文件,在文件中包括人脸各个部位的Harr特征值,如图:OpenCV已经为我们训练好了分类器,可以直接使用。# -*-
通过C#实现xml的添加删除操作
一段简单的代码可以实现向XML中实现添加和删除,希望对初学者有用。
Matlab里怎么注释掉一段(多行)代码
<br />Matlab里怎么注释掉一段(多行)代码?你可以这样做,先选好你需要注释的那几行,单击右键,选择COMMENT。就可以了。如果要取消就同样选择要取消注释的那几行、依上述同样的操作选择Uncomment.就行了。