Cmake 配置opencv

  假如下载解压之后得到的opencv配置文件无法正常使用,你需要自己将开源文件编译一次,这样才更适合你的电脑。

https://opencv.org/opencv-3-4-1.html

https://cmake.org/files/v3.12/cmake-3.12.1.zip

并且,cmake需要与opencv版本号相兼容。

打开cmake.(路径最好不要出现中文)

Cmake 配置opencv_第1张图片

选择opencv源文件夹。以及生成的文件夹。

Cmake 配置opencv_第2张图片

生成文件夹的路径随意。

Cmake 配置opencv_第3张图片

 

点击Configure  选择编译器版本

Cmake 配置opencv_第4张图片

 

点击finish。结束之后,点击generate。生成项目。最后在选择的生成路径下找到opencv.sin(针对vs2017).打开项目。

Cmake 配置opencv_第5张图片

 

Cmake 配置opencv_第6张图片

点击重新生成解决方案。

生成结束之后。

找到Cmake 配置opencv_第7张图片

Cmake 配置opencv_第8张图片

 

最终

  1. VC++目录-->包含目录,添加:
    D:\opencv3\opencv\mybuild\install\include

  2. VC++目录-->库目录,添加:
    D:\opencv3\opencv\mybuild\install\x86\vc12\lib
    D:\opencv3\opencv\mybuild\install\x86\vc12\staticlib

  3. 链接器-->输入-->附加依赖项,添加:opencv_aruco341d.lib
    opencv_bgsegm341d.lib
    opencv_bioinspired341d.lib
    opencv_calib3d341d.lib
    opencv_ccalib341d.lib
    opencv_core341d.lib
    opencv_datasets341d.lib
    opencv_dnn_objdetect341d.lib
    opencv_dnn341d.lib
    opencv_dpm341d.lib
    opencv_face341d.lib
    opencv_features2d341d.lib
    opencv_flann341d.lib
    opencv_fuzzy341d.lib
    opencv_hfs341d.lib
    opencv_highgui341d.lib
    opencv_img_hash341d.lib
    opencv_imgcodecs341d.lib
    opencv_imgproc341d.lib
    opencv_line_descriptor341d.lib
    opencv_ml341d.lib
    opencv_objdetect341d.lib
    opencv_optflow341d.lib
    opencv_phase_unwrapping341d.lib
    opencv_photo341d.lib
    opencv_plot341d.lib
    opencv_reg341d.lib
    opencv_rgbd341d.lib
    opencv_saliency341d.lib
    opencv_shape341d.lib
    opencv_stereo341d.lib
    opencv_stitching341d.lib
    opencv_structured_light341d.lib
    opencv_superres341d.lib
    opencv_surface_matching341d.lib
    opencv_text341d.lib
    opencv_tracking341d.lib
    opencv_video341d.lib
    opencv_videoio341d.lib
    opencv_videostab341d.lib
    opencv_world341.lib
    opencv_world341d.lib
    opencv_xfeatures2d341d.lib
    opencv_ximgproc341d.lib
    opencv_xobjdetect341d.lib
    opencv_xphoto341d.lib   

---------------------------2019年9月26日添加--------------------------------------

获取文件名字可以参考这个程序

#define _CRT_SECURE_NO_WARNINGS
#include       
#include     
#include     
#include     
#include
using namespace std;
//获取特定格式的文件名    
void getAllFiles(string path, vector& files, string format)
{
	long  hFile = 0;//文件句柄  64位下long 改为 intptr_t
	struct _finddata_t fileinfo;//文件信息 
	string p;
	if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1) //文件存在
	{
		do
		{
			if ((fileinfo.attrib & _A_SUBDIR))//判断是否为文件夹
			{
				if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)//文件夹名中不含"."和".."
				{
					files.push_back(p.assign(path).append("\\").append(fileinfo.name)); //保存文件夹名
					getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, format); //递归遍历文件夹
				}
			}
			else
			{
				files.push_back(p.assign(path).append("\\").append(fileinfo.name));//如果不是文件夹,储存文件名
			}
		} while (_findnext(hFile, &fileinfo) == 0);
		_findclose(hFile);
	}
}

int main()
{
	string filePath = "D:\\Program\\Cpp\\CTOS_projact\\face_recgnition\\ConsoleApplication2\\at";
	vector files;
	string format = "";				 //查找文件的格式
	getAllFiles(filePath, files, format);
	int size = files.size();
	char str[100];
	std::ofstream outfile;
	outfile.open("at.txt");
	if (!outfile)
	{
		printf("error\n");
	}
	else
	{
		
		for (int i = 0; i < files.size(); i++)
		{
			//sprintf(str, "%s;\n", files[i]);
			outfile<

---------------------------2019年9月26日添加--------------------------------------

配置完成。参见https://segmentfault.com/a/1190000003496009

你可能感兴趣的:(opencv,opencv)