• opencv在VS2010命令行编译过程


    最近这两天一直在研究命令行参数的编译,现代吗如下:

    #include <highgui.h>
    #include <math.h>
    #include <cv.h>
    
    IplImage *Igray = 0, *It = 0, *Iat;
    
    int main( int argc, char** argv )
    {
    	//输入命令行
    	double threshold = (double)atof( argv[1] ); //convert string to double
    	int threshold_type = atoi( argv[2] ) ? CV_THRESH_BINARY : CV_THRESH_BINARY_INV;
    	int adaptive_method = atoi( argv[3] ) ? CV_ADAPTIVE_THRESH_MEAN_C : CV_ADAPTIVE_THRESH_GAUSSIAN_C;
    	int block_size = atoi( argv[4] );
    	double offset = (double)atof( argv[5] );
    	//加载灰度图
    	if( ( Igray = cvLoadImage( argv[6], CV_LOAD_IMAGE_GRAYSCALE ) ) == 0 )
    	{
    		return -1;
    	}
    	//创建同样大小8位灰度图用于输出
    	It = cvCreateImage( cvSize( Igray -> width, Igray -> height ), IPL_DEPTH_8U, 1 ); //单通道8位灰度图
    	Iat = cvCreateImage( cvSize( Igray -> width, Igray -> height ), IPL_DEPTH_8U, 1 );
    	//阈值化
    	cvThreshold( Igray, It, threshold, 255, threshold_type );
    	cvAdaptiveThreshold( Igray, Iat, 255, adaptive_method, threshold_type, block_size, offset );
    	//命名窗体输出
    	cvNamedWindow( "Raw", 1 );
    	cvNamedWindow( "Threshold", 1 );
    	cvNamedWindow( "Adaptive Threshold", 1 );
    	cvShowImage( "Raw", Igray );
    	cvShowImage( "Threshold", It );
    	cvShowImage( "Adaptive Threshold", Iat );
    	cvWaitKey(0);
    	//回收内存
    	cvReleaseImage( &Igray );
    	cvReleaseImage( &It );
    	cvReleaseImage( &Iat );
    	cvDestroyWindow( "Raw" );
    	cvDestroyWindow( "Threshold" );
    	cvDestroyWindow( "Adaptive Threshold" );
    
    	return 0;
    }
    

      上述代码是二值化和自适应二值化的比较,在该工程文件夹同级目录下面的Debug文件找到 自适应阈值.exe 文件,然后打开命令行提示符,针对上述文件可进行下面操作:

          1,首先进到Debug文件,找到.exe文件,如D:myopencvopencvCodeOpencvDebug

          2,在命令行输入下面:

             D:myopencvopencvCodeOpencvDebug>自适应阈值.exe 15 1 1 71 15 D:myopencvopencvCodeOpencv自适应阈值2.jpg

          3,结果如下:

                 

    简单的和大家分享一下。

  • 相关阅读:
    CreateDIBSection函数
    rand()和srand()GetTickCount函数用法
    PRIMARY LANGUAGE ID not a number
    videojs 动态加载视频
    [记录] nicescroll 在bootstrap tabs中工作
    [记录] js判断数组key是否存在
    li 水平排列并自动填满 ul
    [Laravel] 获取执行的Sql
    [Laravel]配置路由小记
    昨天冲动的搬到外面住了,oh yeah
  • 原文地址:https://www.cnblogs.com/wuyuankun/p/3596310.html
Copyright © 2020-2023  润新知