You are not logged in.

#1 2018-03-26 13:19:17

nasser
Member
Registered: 2016-01-23
Posts: 56

[SOLVED]Can't link opencv libraries via Cmake in Linux

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_DIRS})
link_directories(${OpenCV_LINK_DIRS})
set(SRC main.cpp)
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

Here is the main.cpp file (for demonstrating, all prjects don't work anymore after recompiling them)

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

Here is the errors
https://i.imgur.com/FWFzRO7.png
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.

Mod Edit - Replaced oversized images with links.
CoC - Pasting pictures and code

Last edited by nasser (2018-03-30 07:44:14)

Offline

#2 2018-03-30 07:41:27

nasser
Member
Registered: 2016-01-23
Posts: 56

Re: [SOLVED]Can't link opencv libraries via Cmake in Linux

I have solved it by recompiling OpenCV and recompiling LPACKE
for Compiling OpenCV I've used their docs and this blog post
*Note for block post I haven't used the last two commands

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

I used this blog as a guid, I didn't need all the stuff in it
*Also I suggest that you should first learn about compiling from source(cmake and make) and also the structure of Linux system(you can find alot online), because the problem was that OpenCV can't found dependcies as someone said to me on G+ post.

Offline

Board footer

Powered by FluxBB