我在Red Hat Linux上。我在C++文件中遇到了一些(可能是新手)問題。我在我進入使用OpenCV標頭編譯C++文件時沒有此類文件或目錄錯誤
g++ my_simple_script.cpp
終端創建了以下簡單的OpenCV的腳本,
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(int argc, char ** argv){
Mat img = imread(argv[1], -1);
if (img.empty()) return -1;
namedWindow("Example1", cv::WINDOW_AUTOSIZE);
imshow("Example1", img);
waitKey(0);
destroyWindow("Example1");
}
然後,得到了錯誤
newfile.cpp:1:39: error: opencv2/highgui/highgui.hpp: No such file or directory
newfile.cpp:3: error: 'cv' is not a namespace-name
newfile.cpp:3: error: expected namespace-name before ';' token
newfile.cpp: In function 'int main(int, char**)':
newfile.cpp:6: error: 'Mat' was not declared in this scope
newfile.cpp:6: error: expected ';' before 'img'
newfile.cpp:7: error: 'img' was not declared in this scope
newfile.cpp:8: error: 'cv' has not been declared
newfile.cpp:8: error: 'namedWindow' was not declared in this scope
newfile.cpp:9: error: 'img' was not declared in this scope
newfile.cpp:9: error: 'imshow' was not declared in this scope
newfile.cpp:10: error: 'waitKey' was not declared in this scope
newfile.cpp:11: error: 'destroyWindow' was not declared in this scope
我加
/home/m/maxwell9/2.4.3/include
我PATH,其中2.4.3表示給出了我使用的OpenCV版本。 當我鍵入
echo $PATH
我看到
/opt/apps/jdk1.6.0_22.x64/bin:/apps/smlnj/110.74/bin:/usr/local/cuda/bin:/sbin:/bin:/usr/sbin:/usr/bin:/apps/weka/3.7.12:/home/m/maxwell9/bin:/home/m/maxwell9/2.4.3/include
我證實,在
/home/m/maxwell9/2.4.3/include/opencv2/highgui/highgui.hpp
我選擇了一個奇怪的目錄,因爲我在學校的一臺電腦,並沒有sudo特權。現在在家裏,在Ubuntu上,將嘗試從源代碼構建OpenCV。您是否有鏈接到安裝說明的好頁面?我特別想知道在構建OpenCV之前是否需要安裝依賴關係。我在網上找到了一些OpenCV的安裝說明,所以我不確定選擇哪一個。官方在opencv.org上安裝Linux的說明列出了一些依賴性,但沒有提到使用ldconfig,我認爲這是必要的。 – Max
這是一篇博客文章,向您介紹如何在Ubuntu 14.04中安裝OpenCV並支持CUDA(GPU):http://blog.aicry.com/ubuntu-14-04-install-opencv-with-cuda/ – jsb097