28
2020
04

423

        clock_t starttime = clock();
        clock_t endtime = 0;
        int found = 0;
         
        IplImage *source1 = cvLoadImage("G:\\vctest\\OpenCv_Test\\图片\\030.png");
        IplImage *source2 = cvLoadImage("G:\\vctest\\OpenCv_Test\\图片\\0311.png");
        cvShowImage("source1",source1);
        cvShowImage("source2",source2);
         
        //FILE *fp = fopen("G:\\vctest\\OpenCv_Test\\图片\\030.tes","wb");
        //FILE *fp1 = fopen("G:\\vctest\\OpenCv_Test\\图片\\031.tes","wb");
        //fwrite(source1->imageData,source1->imageSize,1,fp);
        //fwrite(source2->imageData,source2->imageSize,1,fp1);

        //fclose(fp);
        //fclose(fp1);
         
         
         
        char *source1_data = source1->imageData;
        char *source2_data = source2->imageData;
         
        for(int h=0;h<source1->height - source2->height-1;h++)
        {
        for (int w=0;w<source1->width-source2->width-1;w++)
        {
        if (1 == contrast((unsigned char *)&source1_data[h*source1->widthStep+w*source1->nChannels],(unsigned char *)&source2_data[source2->width*source2->nChannels],source2->width*source2->nChannels,1))
        {
        found = 1;
        for (int ih = 1;ih < source2->height-1;ih++)
        {
        if (0 == contrast((unsigned char *)&source1_data[(h+ih)*source1->widthStep+w*source1->nChannels],(unsigned char *)&source2_data[ih*source2->widthStep+source2->width*source2->nChannels],source2->width*source2->nChannels,1))
        {
        found = 0;
        continue;
        }
        }
        if (found == 0)
        {
        break;
        }
        AfxOutputDebugString("find 1 line at:%d %d\n",w,h);
        endtime = clock();
        AfxOutputDebugString("time:%d\n",endtime-starttime);
        break;
        }
         
         
        }
        // AfxOutputDebugString("h::%d\n",h);
        }
         
         
         
        cvReleaseImage(&source1);
        cvReleaseImage(&source2);
        endtime = clock();
        AfxOutputDebugString("time:%d\n",endtime-starttime);

            int Cimage_contrast_01Dlg::contrast(unsigned char *source1,unsigned char *source2,int len,int a)
        {
        int i = 0;
        for (i=0;i<len-1;i++)
        {
        //if(source1[i] <= source2[i] - a || source1[i] >= source2[i] + a)
        if((abs(source1[i] - source2[i]) >= a))
        {
        return 0;
        }
        }
         
        return 1;
        }
« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。