转载地址: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}/libName: 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? Let’s Find It.相关推荐

  1. 为什么OpenCV4 “pkg-config --modversion opencv”显示“ No package ‘opencv‘ found”?解决方法!

    为什么OpenCV4 "pkg-config --modversion opencv"显示" No package 'opencv' found"?解决方法! ...

  2. Ubuntu安装运行YOLOV3 解决opencv报错 No package ‘opencv‘ found

    YOLO系列 本文概述 一些软件依赖 官方网站和官方英文教程 下载YOLOV3并直接make编译 编译GPU实现YOLO 要求N卡和cuda 编译GPU版YOLOV3 gpu运行YOLOV3 dete ...

  3. 视觉SLAM十四讲 报错 Could not find a configuration file for package “OpenCV“ that is compatible with reques

    视觉SLAM十四讲 报错 Could not find a configuration file for package "OpenCV" that is compatible w ...

  4. AI视频行为分析系统项目复盘——技术篇1:Ubuntu 18.04部署编译OpenCV+contrib、TensorFlow2.1、CUDA10.1+cuDNN7.6.5、tensorRT6.0.1等

    0 项目背景 接手他人的项目,全过程重头梳理下. 7台服务器,其中6台GPU服务器(GPU:2*2080Ti,CPU:2*Xeon Gold 5118(12核24线程)),一台调度服务器,Ubuntu ...

  5. OpenCV下车牌定位算法实现代码

    转自:http://blog.csdn.net/heihei723/archive/2006/05/14/728046.aspx#FeedBack 车牌定位算法在车牌识别技术中占有很重要地位,一个车牌 ...

  6. opencv 检测直线、线段、圆、矩形

    转自:http://blog.csdn.net/byxdaz/archive/2009/12/01/4912136.aspx 检测直线:cvHoughLines,cvHoughLines2 检测圆:c ...

  7. OPENCV打开图片进行边缘检测

    OPENCV打开图片并且进行边缘检测 #ifdef _CH_ #pragma package <opencv> #endif#ifndef _EiC #include "cv.h ...

  8. c++ opencv 基本操作

    下载地址: https://opencv.org/releases/ 归一化,转vector: Opencv C++ 归一化_jacke121的专栏-CSDN博客_c++ opencv 归一化 c++ ...

  9. opencv形状识别学习总结

    OpenCV基元检测 Primitive Detection 目录 基元的概念 基元泛指图像中有特点的单元.常说的基元有:边缘.角点.斑点.直线段.圆.等 基元检测是图像分析的基础 边缘(Edge)检 ...

最新文章

  1. WordPress页面Page和文章Post的相互转换
  2. WebDev.WebServer 学习
  3. 中国桑叶市发展态势分析与前景动态预测报告场2022-2028年版
  4. javascript进阶教程第二章对象案例实战
  5. 关于Qt的CRUD增删改查数据库那些事,带GUI图像界面
  6. C#锐利体验-第八讲 索引器与操作符重载(转)
  7. 移植wpa_supplicant 2.2问题
  8. highgui java opencv_OpenCV在C Qt应用程序中的highgui
  9. 微课|中学生可以这样学Python(8.1节):解析算法例题讲解
  10. usd to php exchange,999500 USD to PHP Currency Converter - 美元 菲律宾比索 汇率兑换
  11. c语言经典题(期中/期末复习)(xdoj)
  12. 微信小程序上传照片到服务器
  13. 第9届蓝桥杯Java组省赛
  14. 常见视频分辨率及码率
  15. 大学语文复习详细资料
  16. 第三季度编程语言排行榜出炉,它太稳了!
  17. oracle增加字段为主键自增_Oracle新增自增一的主键字段和赋值代码
  18. 秒改文件md5,各PC系统可用
  19. Social Radio:像收听广播一样收听Twitter状态更新
  20. qt4.8.5在arm下的移植

热门文章

  1. 银行信用评分卡建模原理
  2. Activiti学习(一)之工作流的介绍和使用
  3. helm安装cert-manager自动化Https(1.8)
  4. 计算机编程语言及Java
  5. 吉林大学软件学院软构件与中间件JavaEE实验
  6. Linux_终端命令大全
  7. Qt Central Widget
  8. 电容笔和触控笔有什么区别?实用平板电脑手写电容笔推荐
  9. 就现在!体验高科技的虚拟孪生
  10. CATTECATT 分析