基于Opencv平台开发的程序在其它电脑上独立运行

基于Opencv开发的程序可独立运行的方法讲解

注:学习心得,仅供参考。如有错误,请不吝赐教。

可执行程序独立运行的要求:无需安装第三方软件包,可在Windows7或ubuntu 14.04.1操作系统上独立运行(程序包拷贝到Windows7或ubuntu 14.04.1操作系统上可直接运行)。

本文以Win7x64+VS2012+Opencv2.4.13开发环境为例,讲解静态方法编译的程序开发过程。

【配置阶段】

步骤1:首先在vs2012环境下新建一个工程,工程命名为test。

步骤2:

(1)将opencv2.4.13安装目录\build下的include文件夹拷贝到当前工程目录下,重命名为opencv_include;

(2)将opencv2.4.13安装目录\build\x86\vc11下的staticlib文件夹拷贝到当前工程目录下,重命名为opencv_lib;

步骤3:返回到vs开发环境,在左侧【解决方案资源管理器】下目录树中右键项目名称,选择【属性】,在“配置属性”->“C/C++”->“常规”->“附加包含目录”中添加opencv_include目录(即步骤2(1)中的opencv_include的路径)。

步骤4:在“链接器”->“输入”->“附加依赖项”里添加相应的lib文件,debug版添加带d的lib,release版添加不带d的lib。详细如下:(注:这里使用了相对路径,其中“.”表示当前目录。)

//win32控制台程序需要的lib
vfw32.lib
comctl32.lib

//debug版
//opencv用到的第三方lib
//opencv各模块的lib
.\opencv_lib\IlmImfd.lib
.\opencv_lib\libjasperd.lib
.\opencv_lib\libjpegd.lib
.\opencv_lib\libpngd.lib
.\opencv_lib\libtiffd.lib
.\opencv_lib\zlibd.lib
.\opencv_lib\opencv_ml2413d.lib
.\opencv_lib\opencv_calib3d2413d.lib
.\opencv_lib\opencv_contrib2413d.lib
.\opencv_lib\opencv_core2413d.lib
.\opencv_lib\opencv_features2d2413d.lib
.\opencv_lib\opencv_flann2413d.lib
.\opencv_lib\opencv_gpu2413d.lib
.\opencv_lib\opencv_highgui2413d.lib
.\opencv_lib\opencv_imgproc2413d.lib
.\opencv_lib\opencv_legacy2413d.lib
.\opencv_lib\opencv_objdetect2413d.lib
.\opencv_lib\opencv_ts2413d.lib
.\opencv_lib\opencv_video2413d.lib
.\opencv_lib\opencv_nonfree2413d.lib
.\opencv_lib\opencv_ocl2413d.lib
.\opencv_lib\opencv_photo2413d.lib
.\opencv_lib\opencv_stitching2413d.lib
.\opencv_lib\opencv_superres2413d.lib
.\opencv_lib\opencv_videostab2413d.lib

//release版
.\opencv_lib\IlmImf.lib
.\opencv_lib\libjasper.lib
.\opencv_lib\libjpeg.lib
.\opencv_lib\libpng.lib
.\opencv_lib\libtiff.lib
.\opencv_lib\zlib.lib
.\opencv_lib\opencv_objdetect2413.lib
.\opencv_lib\opencv_ts2413.lib
.\opencv_lib\opencv_video2413.lib
.\opencv_lib\opencv_nonfree2413.lib
.\opencv_lib\opencv_ocl2413.lib
.\opencv_lib\opencv_photo2413.lib
.\opencv_lib\opencv_stitching2413.lib
.\opencv_lib\opencv_superres2413.lib
.\opencv_lib\opencv_videostab2413.lib
.\opencv_lib\opencv_calib3d2413.lib
.\opencv_lib\opencv_contrib2413.lib
.\opencv_lib\opencv_core2413.lib
.\opencv_lib\opencv_features2d2413.lib
.\opencv_lib\opencv_flann2413.lib
.\opencv_lib\opencv_gpu2413.lib
.\opencv_lib\opencv_highgui2413.lib
.\opencv_lib\opencv_imgproc2413.lib
.\opencv_lib\opencv_legacy2413.lib
.\opencv_lib\opencv_ml2413.lib

注意:需要把下图中圆圈处的默认勾选去掉。


步骤5:在“C/C++”->“代码生成”->“运行时库”中,debug版选择MTd,release版选择MT。


至此,配置已经完成。


【测试阶段】

现在添加一个源文件进行测试。本文以xml文件的读写操作为例,参考如下程序:

#include

#include

using namespace cv;

int main()
{
	FileStorage fs("xmltest.xml",FileStorage::WRITE);
	fs<<"frameCount"<<5;
	time_t rawtime;time(&rawtime);
	fs<<"calibrationDate"<< asctime(localtime(&rawtime));
	Mat cameraMatrix = (Mat_(3,3)<<1000,0,320,0,1000,240,0,0,1);
	Mat distCoeffs = (Mat_(5,1)<<0.1,0.01,-0.001,0,0);
	fs<<"cameraMatrix"<>j) & 1);
		}
		fs<<"]"<<"}";
	}
	fs<<"]";
	fs.release();

	printf("file has rearded over! please see it at current  project path");
	getchar();

	return 0;
}

编译通过,运行,则会在当前工程目录下生成文件xmltest。

最后将本工程文件拷贝到其它电脑,运行debug文件下test应用程序,则同样在debug文件下生成一个文件xmltest。


你可能感兴趣的:(OpenCV)