Can't link opencv libraries via Cmake in Linux

asked 2018-03-25 11:39:50 -0500

nasserahmed96 gravatar image

I used to have OpenCV3 from the Arch Linux pckage manager(pacman) and it worked fine but when I removed it and install OpenCV 3.4.1 and OpenCV-Contrib from source code nothing worked even the old project when I tryied to recompile them. Here is the CMakeLists.txt file

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_DIR})
include_directories(${ILMBASE_CUSTOM_INCLUDE_DIR})
link_directories(${OpenCV_LINK_DIR})
set(SRC main.cpp)
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

Here is the main.cpp file which contains

#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;
 }

Part of the Error The remainder errors are the same. Note:This code is from samples , and ofcourse this is part of it, other projects wouldn't work too although they are worked before I reinstalled it.

edit retag flag offensive close merge delete

Comments

find_package(OpenCV 3.4.0 REQUIRED) <-- 3.4.1, right ?

berak gravatar imageberak ( 2018-03-25 12:33:11 -0500 )edit

Actually, it says that it found it and also gave me the error, tht error in Linking phase I have tryied to change it to 3.4.1 and also it doesn't work

nasserahmed96 gravatar imagenasserahmed96 ( 2018-03-25 12:36:45 -0500 )edit