1. 程式人生 > >Package OpenCV not found? Let’s Find It.

Package OpenCV not found? Let’s Find It.

轉載地址:http://prateekvjoshi.com/2013/10/18/package-opencv-not-found-lets-find-it/

OpenCV has been refined over the years and installing it has become way more user-friendly now. If has been ported to many platforms and you don’t need an IDE to use it. There are many different ways in which you can install it and use it in your existing code. But sometimes, when people try to do different things with it, they run into problems. This post deals with one such problem. When you write code that uses OpenCV, you need to tell your compiler where it is. The reason for this is that this location will contains all the libraries and binaries necessary for the header files to work in your code. If you don’t specify this, you will encounter the following error:  

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

Where do we go from here?

The reason for the error is that when you try to compile your code from the command line, you need to tell it where to find OpenCV related stuff. People generally use pkg-config to take care of this because it’s easy to handle and it looks clean. Imagine doing the ‘-l’ library-includes every time you want to compile some code. Tedious! Just open your terminal and type the following:

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

This is the path to opencv.pc by default. If you have already installed OpenCV, you should already have opencv.pc somewhere on your machine. So in case you don’t have opencv.pc file in that path, just search for it and assign the path to the PKG_CONFIG_PATH variable:

$ export PKG_CONFIG_PATH=/path/to/the/file

And you are done! It’s better to add this line to your bashrc file so that you don’t have to do it every single time you reopen your terminal.

I can’t find my opencv.pc file, what do I do?

If you cannot find the opencv.pc file, don’t worry! Just create a new file called opencv.pc in /usr/local/lib/pkgconfig and add the following content to that file:

prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -l

After creating this file, make sure the PKG_CONFIG_PATH variable contains this path and you are good to go.

How do I run my OpenCV code now?

Now that all that installing stuff is out of the way, let’s see how we can run your OpenCV code:

  1. Install opencv on your system.
  2. Unzip the zip file
  3. Open the terminal and go to that folder
  4. Type the following on your terminal to compile:
    $ g++ main.cpp MyFile.h MyFile.cpp `pkg-config opencv --cflags --libs` -o main.o
  5. Type the following on your terminal to run (you may need to chmod 777 main.o):
    $ ./main.o

相關推薦

Package OpenCV not found? Lets Find It.

轉載地址:http://prateekvjoshi.com/2013/10/18/package-opencv-not-found-lets-find-it/ OpenCV has been refined over the years and installing i

OpenCV manager package was not found

就是一個依賴庫吧。把一些常用的底層庫封裝起來,然後,然後你就要安裝唄 於是下一個就好了 可是,強迫症發生了,不想安裝 參考 遮蔽OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, m

Error: package 'XXX' not found

我先用catkin_create_package創造了一個包,用catkin_make編譯,然後試圖用rosrun執行程式,出現 Error: package 'ndt_omp' not found的問

Error: Android SDK not found. Make sure that it is installed. If it is not at the default location,

自從升級android studio2.3.1後,執行ionic專案時無法再在android平臺上啟動。網上查了很多資訊後,得知是android sdk廢棄android命令,以及改變了目錄結構。 解決辦法如下: 移除android sdk目錄的tools

無法查詢功能包路徑的解決辦法:[rospack] Error : package 'chapter2_tuorials' not found

今天在ROS工作空間下建立功能包的時候遇到一個問題:當我找到我的工作空間(cd ~/dev/catkin_ws/src)之後,正確的輸入建立功能包命令$ catkin_create_pkg chapter2_tutorials std_msgs roscpp.顯示建立成功。如

but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be   NOT FOUND.

一、問題詳情 在ubuntu中使用CMake編譯連結opencv庫的程式時找不到opencv庫,資訊如下: CMake Warning at //home/smallping/opencv-3.1.0/cmake/OpenCVConfig.cmake:166 (messag

Package gtk+-3.0 was not found in the pkg-config search path

path 二進制 all 項目 有時 rpm fedora ack share 問題描述:   在fedora21系統上通過rpmbuild構建fcitx的二進制包時出現以上錯誤,經老程序員指點:“是相應的開發包沒有安裝” 解決辦法:   yum installl gtk3

Ubuntu 16.04 LTS 安裝libvips出現”Package vips was not found in the pkg-config search path”

arp dir exp export ron per gconf 部署 director 使用libvips來操作圖像,libvips的部署參考一個Node.js工程:https://github.com/lovell/sharp 在MAC下安裝很順利,到Linux環境下(

spring ----> ResourceBundle [message] not found for MessageSource: Can't find bundle for base name message, local_zh

blank 文件配置 dea name flow jdk get 資源 spring4 環境: idea 2018.1.3社區版,jdk8,spring4.2.0,maven3.5.2 主題: spring國際化 出現的問題: ResourceBundle [message

symbol(s) not found for architecture x86_64 ---QT\FFMPEG

QT引入ffmpeg標頭檔案一定要注意使用C編譯方式。 extern "C"{ #include <libavdevice/avdevice.h> } 如果不加extern 在mac下使用QT編譯會出現這樣的報錯: :-1: error: symbol(s) not f

MAC pydotplus.graphviz.InvocationException: GraphViz's executables not found

在學習機器學習-決策樹演算法,使用決策樹演算法進行訓練,在儲存為pdf時遇到錯誤: pydotplus.graphviz.InvocationException: GraphViz's executables not found 網上一通搜,有說是GraphViz 和pydot 安裝

java: System Java Compiler was not found in classpath: java.lang.ClassNotFoundException: com.s錯誤改正方法

剛開始編譯java 時候,什麼jdk也都安裝完畢了,但是老是出現 老是出現這個問題。現在出來寫一個博文進行記錄一下。        我的編譯環境:jdk版本:1.8;win7;編輯器:IntelliJ Idea ; 解決方法:

mac clion ld: symbol(s) not found for architecture x86_64

自從不小心把gcc刪掉後,重新安裝在clion下編譯就出現了這個問題。 Undefined symbols for architecture x86_64:\   "std::__1::basic_string<char, std::__1::char_traits&l

記一次Django報錯Reverse for 'indextwo' with no arguments not found. 1 pattern(s) tried: ['$index/$']

啟動python manage.py runserver 開啟127.0.0.1:8000,報錯資訊如下: Reverse for 'indextwo' with no arguments not found. 1 pattern(s) tried: ['$index/$'] 現象: 無論怎

編寫shell時,遇到let: not found錯誤及解決辦法

#!/bin/bash i=1 sum=0 while [ $i -le 100 ] do   let sum=sum+$i   let i++ done 在寫一個簡單的迴圈指令碼時,報錯 let: not found,在ubuntu預設是指向bin/dash直譯器的,das

在Jupyter Notebook上使用Graphivs出現GraphViz's executables not found 的問題

問題 在Jupyter Notebook上使用Graphivs來進行視覺化操作出現瞭如下bug: GraphViz’s executables not found 解決辦法 1.先去 https://graphviz.gitlab.io/_pages/Download/Download_

package 'orocos-bfl' not found

  -- ==> add_subdirectory(bp_fusion) -- checking for module 'orocos-bfl' -- package 'orocos-bfl' not found CMake Error at /usr/share/cmake-2.

匯入第三方報錯warning: -no_pie ignored for arm64 symbol(s) not found for architecture arm64

最近在老專案裡新增BGFMDB及AFNetWorking的時候一直報錯,具體錯誤資訊如下: ld: warning: -no_pie ignored for arm64 Undefined symbols for architecture arm64: "_OBJC_C

決策樹視覺化時GraphViz's executables not found的解決方法

用python做決策樹視覺化時,安裝了Graphviz,並將其新增到path的環境變數,並且已經安裝了pydotplus且import之後,仍然會出現GraphViz’s executables not found問題,可用以下程式碼解決: import os

opencvnot found的警告問題

最近在使用opencv庫交叉編譯的時候,總是報下面的警告,但其實庫的路徑和連結名字都是對的,程式也可以正常執行,但是不喜歡有警告的程式,於是折騰了一天,總算搞定了這個問題。 /usr/local/li