我曾经使用 Arch Linux pckage 管理器(pacman)中的 OpenCV3,它工作得很好,但是当我删除它并从源代码安装 OpenCV 3.4.1 和 OpenCV-Contrib 时,即使是旧项目,当我尝试重新编译它们时,也没有任何效果,在这里是 CMakeLists.txt 文件:
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0012 NEW)
project(Face_Detection)
find_package(OpenCV 3.4.0 REQUIRED)
message("OpenCV Version ${OpenCV_Version}")
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LINK_DIRS})
set(SRC main.cpp)
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
这是main.cpp文件(为了演示,所有项目在重新编译后不再工作)
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/face.hpp"
#include "opencv2/imgproc.hpp"
#include <stdio.h>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace cv::face;
using namespace std;
//Normalize image
static Mat norm_0_255(Mat _src){
Mat src (_src);
//The returned normalized image
Mat dst;
switch (src.channels()){
case 1:
normalize(src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
break;
case 3:
normalize(src, dst, 0, 255, NORM_MINMAX, CV_8UC3);
break;
default:
src.copyTo(dst);
break;
}
return dst;
}
//Read CSV which containts the paths to images
static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';'){
ifstream file(filename.c_str(), ifstream::in);
if(!file){
string error_message = "No valid inout file was given\n";
CV_Error(Error::StsBadArg, error_message);
}
string line, path, classlabel;
while(getline(file, line)){
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
if(!path.empty() && !path.empty()){
images.push_back(imread(path, 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
}
int main(int argc,const char* argv[]){
return 0;
}
重新编译项目后出现错误
cmake ..
make
其余错误相同。注意:此代码来自示例,当然这是其中的一部分,其他项目也无法工作,尽管它们在我重新安装之前就可以工作。