我剛剛開始使用OpenCV。我有一個Raspberry Pi和Pi相機,我想學習OpenCV以用於機器視覺項目。我正在使用vi編寫C代碼,在Raspberry Pi上編寫。我對Linux有點新鮮,在編輯器中編寫代碼而不是在IDE中是絕對新的!連接opencv庫的麻煩
我能夠從Github上下載OpenCV倉庫並編譯它,而不麻煩。 OpenCV(3.2.0)已安裝。
我輸入正確的密碼,然後取得了CMake的文件。
這裏是我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 2.8)
project(DisplayImage)
find_package(OpenCV COMPONENTS core imgproc highgui REQUIRED)
add_executable(DisplayImage DisplayImage.cpp)
target_link_libraries(DisplayImage ${OpenCCV_LIBS})
LINK_DIRECTORIES("/usr/local/lib")
我試圖使該項目,但它似乎有錯誤鏈接庫。我是新手,無法確定它是否是版本衝突,庫缺失,或者只是鏈接器正在尋找錯誤位置的庫。
下面是當make命令由輸出:
[email protected]:~/Programming $ cmake .
-- Found OpenCV: /usr/local (found version "3.2.0") found components: core imgproc highgui
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/Programming
[email protected]:~/Programming $ make
[ 50%] Linking CXX executable DisplayImage
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `main':
DisplayImage.cpp:(.text+0x6c): undefined reference to `cv::imread(cv::String const&, int)'
DisplayImage.cpp:(.text+0xd4): undefined reference to `cv::namedWindow(cv::String const&, int)'
DisplayImage.cpp:(.text+0x118): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
DisplayImage.cpp:(.text+0x138): undefined reference to `cv::waitKey(int)'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::String::String(char const*)':
DisplayImage.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x50): undefined reference to `cv::String::allocate(unsigned int)'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::String::~String()':
DisplayImage.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::String::operator=(cv::String const&)':
DisplayImage.cpp: (.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x30): undefined reference to `cv::String::deallocate()'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::Mat::~Mat()':
DisplayImage.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::Mat::operator=(cv::Mat const&)':
DisplayImage.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x140): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `cv::Mat::release()':
DisplayImage.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x68): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/DisplayImage.dir/build.make:94: recipe for target 'DisplayImage' failed
make[2]: *** [DisplayImage] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
[email protected]:~/Programming $
下一步是什麼?在Linux中對鏈接錯誤進行故障排除的過程是什麼?/ OpenCV 您可以提供的任何見解都將不勝感激!
真棒謝謝你馬克, – FrankieForceps
好ectory我糾正了OpenCV_LIBS中的CMakeLists.txt文件,並提出了構建目錄如你所說。對於include_directories,我是否直接輸入「OpenCV_INCLUDE_DIR」,還是意味着指向OpenCV目錄的路徑?我想我不確定路徑變量在Linux/OpenCV中的工作方式。謝謝你的幫助! – FrankieForceps