Hi,
i’m new to OpenCV and after installing all i needed, when trying to build with a text project i got a strange linker error :
[main] Building folder: src all
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/hugo/Downloads/COURS/TRAITEMENT/src/build --config Debug --target all -- -j 10
[build] Scanning dependencies of target CMakeCXXCompilerId
[build] [ 16%] Building CXX object CMakeFiles/CMakeCXXCompilerId.dir/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp.o
[build] Scanning dependencies of target tp3_exo1
[build] Scanning dependencies of target tp3_exo2
[build] [ 33%] Building CXX object CMakeFiles/tp3_exo1.dir/src/tp3_exo1.cpp.o
[build] [ 50%] Linking CXX executable bin/CMakeCXXCompilerId
[build] [ 66%] Building CXX object CMakeFiles/tp3_exo2.dir/src/tp3_exo2.cpp.o
[build] [ 66%] Built target CMakeCXXCompilerId
[build] [ 83%] Linking CXX executable bin/tp3_exo2
[build] [100%] Linking CXX executable bin/tp3_exo1
[build] /usr/bin/ld: /usr/lib/libgdal.so.26: undefined reference to `sqlite3_column_origin_name'
[build] /usr/bin/ld: /usr/lib/libgdal.so.26: undefined reference to `sqlite3_column_table_name'
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [CMakeFiles/tp3_exo2.dir/build.make:132: bin/tp3_exo2] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/tp3_exo2.dir/all] Error 2
[build] make[1]: *** Waiting for unfinished jobs....
[build] /usr/bin/ld: /usr/lib/libgdal.so.26: undefined reference to `sqlite3_column_origin_name'
[build] /usr/bin/ld: /usr/lib/libgdal.so.26: undefined reference to `sqlite3_column_table_name'
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [CMakeFiles/tp3_exo1.dir/build.make:132: bin/tp3_exo1] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:107: CMakeFiles/tp3_exo1.dir/all] Error 2
[build] make: *** [Makefile:84: all] Error 2
[build] Build finished with exit code 2
but my project dont even use sqlite or anything related to it,
code :
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
cv::Mat computeHistogramGS(const cv::Mat &image)
{
// create and initialize and 1d array of integers
cv::Mat histogram(256,1,CV_32S,cv::Scalar(0));
// compute the histogram
for(int i=0; i<image.rows; ++i)
for(int j=0; j<image.cols; ++j)
histogram.at<int>(image.at<unsigned char>(i,j))++;
return histogram;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
cv::Mat histogramToImageGS(const cv::Mat &histogram)
{
// create an image
const unsigned int histoHeight = 100;
cv::Mat histogramImage(histoHeight,256,CV_8U,cv::Scalar(0));
// find the max value of the histogram
double minValue,maxValue;
cv::minMaxLoc(histogram, &minValue, &maxValue);
// write the histogram lines
for(int j=0; j<256; ++j)
cv::line(histogramImage, cv::Point(j,histoHeight), cv::Point(j,histoHeight-(histoHeight*histogram.at<int>(j))/maxValue), cv::Scalar(255), 1);
return histogramImage;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char ** argv)
{
// check arguments
if(argc != 2){
std::cout << "usage: " << argv[0] << " image" << std::endl;
return -1;
}
// load the input image
std::cout << "load image ..." << std::endl;
cv::Mat image = cv::imread(argv[1]);
if(image.empty()){
std::cout << "error loading " << argv[1] << std::endl;
return -1;
}
std::cout << "image size : " << image.cols << " x " << image.rows << std::endl;
// display an image
std::cout << "appuyer sur une touche ..." << std::endl;
cv::imshow("image", image);
cv::waitKey();
// convert the image to grayscale
// cvtColor(image,image,CV_BGR2GRAY);
cvtColor(image,image,cv::COLOR_BGR2GRAY);
// display an image
std::cout << "appuyer sur une touche ..." << std::endl;
cv::imshow("image", image);
cv::imshow("histogramme", histogramToImageGS(computeHistogramGS(image)));
cv::waitKey();
return 1;
}
CMakeLists :
cmake_minimum_required(VERSION 2.8)
# give a name to the project
project(tp03)
# find opencv
find_package(OpenCV REQUIRED)
# check opencv version
if(${OpenCV_VERSION} VERSION_LESS 2.0.0)
message(FATAL_ERROR “OpenCV version is not compatible : ${OpenCV_VERSION}”)
endif()
# compilation flags
set(CMAKE_CXX_FLAGS "-Wall -g -O2 -std=c++11")
# put the binary files in this directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# create a directory called 'output' in the project binary directory
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/output)
# or the automatic version
file(GLOB_RECURSE SRC_FILES *.cpp)
# for each sample file, make an exe
foreach(SRC_FILE ${SRC_FILES})
get_filename_component(FILE ${SRC_FILE} NAME_WE)
add_executable(${FILE} ${SRC_FILE})
target_link_libraries(${FILE} ${OpenCV_LIBS})
endforeach()
i am on linux with a ubuntu distribution