Duas versões do OpenCV: a atualização para uma quebrou a outra, embora devam ser separadas

0

Minha distribuição Linux (Antergos) instalou a versão mais recente do OpenCV dos repositórios (versão 3.14.1) há cerca de uma semana. Para compatibilidade, tenho o OpenCV 2 (versão 2.4.13.5) instalado em uma pasta separada no meu diretório pessoal.

Para facilitar a compilação com o g ++, criei aliases no meu arquivo .bashrc para cada versão. Esta configuração essencialmente me permite compilar, digamos, um programa com apenas um arquivo main.cpp, usando g++ main.cpp $(opencv2) Abaixo está o código relevante do meu arquivo .bashrc:

# Programming Related Aliases
# OpenCV
alias opencv3='pkg-config --cflags --libs opencv' # OpenCV 3
opencv2prefix="$HOME/separate-libs/opencv2/release/installed"   # Prefix that serves as the basis for the pathname of the OpenCV 2 directory.
export PKG_CONFIG_PATH="$opencv2prefix/lib/pkgconfig"
export LD_LIBRARY_PATH="$opencv2prefix/lib"
alias opencv2="pkg-config --cflags --libs opencv2"  # OpenCV 2 lib, include and runtime specifications for OpenCV 2. Defined in PKG_CONFIG_PATH.

Esta configuração funcionou perfeitamente até hoje cedo quando fui compilar um programa maior (que realiza segmentação de imagem) com a configuração OpenCV 2. No começo eu pensei que tinha esquecido uma opção de compilação necessária ao compilar o OpenCV 2 a partir do código-fonte. No entanto, apenas para verificar minha sanidade, tentei compilar um programa que eu tinha compilado com sucesso com o OpenCV 2 antes da atualização mencionada anteriormente. O seguinte foi o resultado:

/usr/bin/ld: warning: libImath-2_2.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIlmImf-2_2.so.22, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIex-2_2.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libHalf.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIlmThread-2_2.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::globalThreadCount()'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::ChannelList::insert(char const*, Imf_2_2::Channel const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::InputFile::header() const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::hasChromaticities(Imf_2_2::Header const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::OutputFile::writePixels(int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::InputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::InputFile::readPixels(int, int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Channel::Channel(Imf_2_2::PixelType, int, int, bool)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Slice::Slice(Imf_2_2::PixelType, char*, unsigned long, unsigned long, int, int, double, bool, bool)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::OutputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Header::dataWindow() const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Header::channels()'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'half::_eLut'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Header::channels() const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Header::~Header()'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Header::Header(int, int, float, Imath_2_2::Vec2<float> const&, float, Imf_2_2::LineOrder, Imf_2_2::Compression)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::InputFile::InputFile(char const*, int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::OutputFile::OutputFile(char const*, Imf_2_2::Header const&, int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::FrameBuffer::insert(char const*, Imf_2_2::Slice const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::ChannelList::findChannel(char const*) const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::chromaticities(Imf_2_2::Header const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'half::convert(int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::Chromaticities::Chromaticities(Imath_2_2::Vec2<float> const&, Imath_2_2::Vec2<float> const&, Imath_2_2::Vec2<float> const&, Imath_2_2::Vec2<float> const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to 'Imf_2_2::OutputFile::~OutputFile()'
collect2: error: ld returned 1 exit status

Eu tentei executar sudo ldconfig , além de verificar se os nomes dos meus caminhos estão corretos. Além disso, verifiquei problemas de compatibilidade nas instruções include de todos os arquivos e não encontrei problemas. Estou presumindo que a atualização do gerenciador de pacotes para a instalação do OpenCV 3 foi o que estragou tudo. Mas se for esse o caso, por quê? Obviamente, se as instalações do OpenCV estivessem na mesma pasta, eu poderia entender. Mas os dois parecem estar completamente separados e inconscientes um do outro. Meu único outro palpite seria algo com o pkg-config.

Quando tento compilar o programa de segmentação de imagens que contém arquivos de objeto e código mais complexo, obtenho:

/tmp/ccpvnIWK.o: In function 'main':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:37: undefined reference to 'cv::waitKey(int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:51: undefined reference to 'cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:74: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:75: undefined reference to 'cv::namedWindow(cv::String const&, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:76: undefined reference to 'cv::imshow(cv::String const&, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:77: undefined reference to 'cv::waitKey(int)'
/tmp/ccpvnIWK.o: In function 'cv::String::String(char const*)':
/usr/include/opencv2/core/cvstd.hpp:602: undefined reference to 'cv::String::allocate(unsigned long)'
/tmp/ccpvnIWK.o: In function 'cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:648: undefined reference to 'cv::String::deallocate()'
/tmp/ccpvnIWK.o: In function 'cv::String::operator=(cv::String const&)':
/usr/include/opencv2/core/cvstd.hpp:656: undefined reference to 'cv::String::deallocate()'
/tmp/ccpvnIWK.o: In function 'cv::Mat::Mat(cv::Mat const&)':
/usr/include/opencv2/core/mat.inl.hpp:490: undefined reference to 'cv::Mat::copySize(cv::Mat const&)'
/tmp/ccpvnIWK.o: In function 'cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.inl.hpp:704: undefined reference to 'cv::fastFree(void*)'
/tmp/ccpvnIWK.o: In function 'cv::Mat::release()':
/usr/include/opencv2/core/mat.inl.hpp:816: undefined reference to 'cv::Mat::deallocate()'
/tmp/ccpvnIWK.o: In function 'cv::Mat::operator=(cv::Mat&&)':
/usr/include/opencv2/core/mat.inl.hpp:1383: undefined reference to 'cv::fastFree(void*)'
/tmp/ccpvnIWK.o: In function 'cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/include/opencv2/core/cvstd.inl.hpp:83: undefined reference to 'cv::String::allocate(unsigned long)'
Loader.o: In function 'void cv::operator>><std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(cv::FileNode const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/usr/include/opencv2/core/cvstd.inl.hpp:156: undefined reference to 'cv::read(cv::FileNode const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Loader.o: In function 'Loader::loadControlParameters(ControlParameters&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:16: undefined reference to 'cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:17: undefined reference to 'cv::FileStorage::isOpened() const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:20: undefined reference to 'cv::waitKey(int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:24: undefined reference to 'cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:25: undefined reference to 'cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:26: undefined reference to 'cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:27: undefined reference to 'cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:16: undefined reference to 'cv::FileStorage::~FileStorage()'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:16: undefined reference to 'cv::FileStorage::~FileStorage()'
Loader.o: In function 'Loader::loadOriginalImage(ControlParameters const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:35: undefined reference to 'cv::imread(cv::String const&, int)'
Loader.o: In function 'void cv::operator>><int>(cv::FileNode const&, int&)':
/usr/include/opencv2/core/persistence.hpp:1238: undefined reference to 'cv::read(cv::FileNode const&, int&, int)'
MeanShift.o: In function 'cv::operator*=(cv::Mat&, double const&)':
/usr/include/opencv2/core/operations.hpp:254: undefined reference to 'cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:22: undefined reference to 'cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:24: undefined reference to 'cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:26: undefined reference to 'cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:28: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:29: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:30: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:32: undefined reference to 'cv::merge(cv::Mat const*, unsigned long, cv::_OutputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:44: undefined reference to 'cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:46: undefined reference to 'cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:48: undefined reference to 'cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:50: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:51: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:52: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:54: undefined reference to 'cv::merge(cv::Mat const*, unsigned long, cv::_OutputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingRGB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:74: undefined reference to 'cv::countNonZero(cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::segmentUsingRGB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::segmentUsingRGB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:121: undefined reference to 'cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::segmentFromFeatureSpace(cv::Mat const&, unsigned int, std::vector<SWin, std::allocator<SWin> > const&, std::vector<std::vector<cv::Point3_<int>, std::allocator<cv::Point3_<int> > >, std::allocator<std::vector<cv::Point3_<int>, std::allocator<cv::Point3_<int> > > > > const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:145: undefined reference to 'cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function 'MeanShift::getChannelsRanges(cv::Mat, int*, SImgDims&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:204: undefined reference to 'cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function 'MeanShift::getChannelsRanges(cv::Mat, int*, SImgDims&)':
/usr/include/opencv2/core.hpp:819: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::getChannelsRanges(cv::Mat, int*, SImgDims&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:214: undefined reference to 'cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_<int>*, cv::Point_<int>*, cv::_InputArray const&)'
MeanShift.o: In function 'MeanShift::showImage(cv::Mat, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:789: undefined reference to 'cv::namedWindow(cv::String const&, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:795: undefined reference to 'cv::imshow(cv::String const&, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:797: undefined reference to 'cv::waitKey(int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:800: undefined reference to 'cv::destroyWindow(cv::String const&)'
MeanShift.o: In function 'MeanShift::makeIt8bit(cv::Mat)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:811: undefined reference to 'cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
MeanShift.o: In function 'MeanShift::standardization(cv::Mat const&)':
/usr/include/opencv2/core.hpp:819: undefined reference to 'cv::noArray()'
MeanShift.o: In function 'MeanShift::standardization(cv::Mat const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:827: undefined reference to 'cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_<int>*, cv::Point_<int>*, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:829: undefined reference to 'cv::operator-(cv::Mat const&, cv::Scalar_<double> const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:829: undefined reference to 'cv::operator*(cv::MatExpr const&, double)'
MeanShift.o: In function 'cv::Mat::Mat(int, int const*, int)':
/usr/include/opencv2/core/mat.inl.hpp:446: undefined reference to 'cv::Mat::create(int, int const*, int)'
MeanShift.o: In function 'cv::Mat::Mat(int, int const*, int, cv::Scalar_<double> const&)':
/usr/include/opencv2/core/mat.inl.hpp:454: undefined reference to 'cv::Mat::create(int, int const*, int)'
/usr/include/opencv2/core/mat.inl.hpp:455: undefined reference to 'cv::Mat::operator=(cv::Scalar_<double> const&)'
MeanShift.o: In function 'cv::Mat::create(int, int, int)':
/usr/include/opencv2/core/mat.inl.hpp:796: undefined reference to 'cv::Mat::create(int, int const*, int)'
collect2: error: ld returned 1 exit status
make: *** [makefile:6: segmentation] Error 1

O que me parece particularmente estranho nesta saída é que os arquivos * .o parecem em /usr/include/opencv2 para definições de funções, parece. Se foi chamado com $opencv2 , não deveria aparecer em /home/kvasir/separate-libs/opencv2/release/installed/* ?

O makefile que produz o erro acima é mostrado abaixo:

segmentation : main.cpp Loader.o MeanShift.o ControlParameters.h defs.h
    g++ -g -o segmentation main.cpp Loader.o MeanShift.o $(opencv2)

Loader.o : Loader.cpp Loader.h
    g++ -g -c Loader.cpp

MeanShift.o : MeanShift.cpp MeanShift.h
    g++ -g -c MeanShift.cpp

clean:
    rm segmentation *.o

Eu também tentei compilar os arquivos objeto com a versão OpenCV 2 sem sucesso. Meu próximo passo provavelmente será reinstalar o OpenCV 2. No entanto, estou curioso para saber por que isso aconteceu em primeiro lugar e se há alguma maneira de corrigir e evitar que isso aconteça no futuro.

Além disso, ambos os programas compilam com sucesso com o OpenCV 3 sem problemas. Por exemplo, alterar $(opencv2) no meu makefile acima para $ (opencv3) resulta em nenhum erro e em um programa em funcionamento.

Edit: Eu sou um estudante universitário e esses programas são atribuições para um curso de Ciência da Computação. O programa mais complicado mencionado acima não foi escrito por mim. Foi fornecido pelo meu professor e emprestado de outra universidade. Eu tenho que modificá-lo, mas ele está em um estado compilar como está com a exceção de main em main.cpp sendo anulada. Eu mudei para int e fiz a declaração de retorno return 0; , e pareceu compilar perfeitamente com o OpenCV 3.

Nota: eu sei que o código para ambos os programas funciona. Eu não estou pedindo ajuda com codificação, mas estou perguntando por que uma atualização para a instalação do OpenCV 3 em /usr/include/ iria estragar uma instalação personalizada do OpenCV 2 em um local separado.

Editar: Aqui é um link para os mais complicados (segmentação de imagens ) programa.

Editar: enviei o código-fonte do programa mais simples para o Google Drive. Está disponível aqui .

    
por Saul Kapruac 21.03.2018 / 05:48

1 resposta

0

Corrigi os problemas que estava enfrentando. Um sobre o qual não tenho certeza. O outro foi resultado da minha própria ignorância. Quanto aos estranhos erros de compilação que eu estava experimentando com o OpenCV 2 e o mais simples dos dois programas, eu não tenho certeza. No entanto, a recompilação do OpenCV 2 parece ter resolvido o problema.

O maior erro que cometi foi com o meu makefile. Eu não sabia que os aliases definidos em .bashrc não se traduzem em makefiles e que os makefiles têm uma sintaxe minimamente diferente em comparação com o bash. Em bash $(opencv2) chama o comando opencv2 refere-se e usa sua saída no comando atual. Usar $opencv2 se referiria a uma variável e retornaria seu valor. Nos makefiles este não é o caso. De fato, $(opencv2) retorna o valor de uma variável definida localmente chamada opencv2. Comandos podem ser definidos por essas variáveis, mas devem ser cercados por marcas graves / backticks. Abaixo está meu makefile corrigido:

OPENCV='pkg-config --cflags --libs opencv2'
segmentation : main.cpp Loader.o MeanShift.o ControlParameters.h defs.h
         g++ -g main.cpp Loader.o MeanShift.o $(OPENCV) -o segmentation      

Loader.o : Loader.cpp Loader.h
         g++ -g -c Loader.cpp $(OPENCV)

MeanShift.o : MeanShift.cpp MeanShift.h
         g++ -g -c MeanShift.cpp $(OPENCV)

clean:
         rm segmentation *.o
    
por 22.03.2018 / 21:16