opencv3.0.0在ubuntu12.04下的配置

更新时间:2024-04-05 06:44:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1.下载好OpenCV3.0.0的压缩包; tar -xvf OpenCV-3.0.0.tar.baz 2. cd OpenCV-3.0.0

sudo mkdir build (创建一个新的文件存放必需的安装文件信息) cd build

sudo apt-get install libgtk2.0-dev

3查看是否安装了cmake

如果没有,则 sudo apt-get install cmake

4./kugroe/opencv-3.0.0-beta 是我自定义在系统中安装的路径

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/kugroe/opencv-3.0.0-beta -D BUILD_PYTHON_SUPPORT=ON -D WITH_IPP=OFF ..

5.配置完毕后就是要 make && make install

sudo make && make install -j8 (-j8是开8个线程)

出现错误:(内存空间不够造成的)

/kugroe/opencv-3.0.0-beta/modules/imgcodecs/include/opencv2/imgcodecs.hpp:93:1: fatal error: can’t write PCH file: No space left on device compilation terminated.

Preprocessed source stored into /tmp/ccDrpV9p.out file, please attach this to your bugreport.

make[2]: *** [modules/photo/perf_precomp.hpp.gch/opencv_perf_photo_RELEASE.gch] Error 1 make[1]: *** [modules/photo/CMakeFiles/pch_Generate_opencv_perf_photo.dir/all] Error 2 make: *** [all] Error 2

到这里,OpenCV的安装算是完成了,但是怎么用它编译我们自己的代码呢?

1.添加库路径

sudo vim /etc/ld.so.conf.d/opencv.conf

添加一句: /kugroe/opencv-3.0.0-beta

2.更新系统库

sudo ldconfig

3.设置环境变量

export PKG_CONFIG_PATH=/kugroe/opencv-3.0.0-beta/lib/pkgconfig:$PKG_CONFIG_PATH

makefile 的编写

OBJS= test.o CC=g++

INCLUDE= -I/kugore/opencv-3.0.0-beta/include -I/kugore/opencv-3.0.0-beta/include/opencv -I/usr/include

LIB= -L /kugore/opencv-3.0.0-beta/lib `pkg-config --libs opencv` Test:$(OBJS)

$(CC) -o Test $(OBJS) $(LIB) test.o:test.cpp

$(CC) -c -g test.cpp $(INCLUDE) clean:

-rm Test $(OBJS)

#`pkg-config --libs opencv` -I/usr/local/OpenCV-2.4.2/build/include/opencv2-lopencv_highgui -lopencv_core

编译程序:

test.cpp

#include #include \#include %using namespace std;

int main() {

IplImage* img=cvloadImage(\

cvNameWindoe(\

cvWaitKey(0);

cvDestroyWindow(\

cvReleaseImage(&img);

return 0; }

~

缺少makefile时的编译执行命令: g++ test.cpp -o test `pkg-config opencv --cflags --libs` ./test 2000.jpg

gcc `pkg-config opencv --cflags --libs opencv` -o test test.c -I /kugore/opencv-3.0.0-beta -L /usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_gpu -lopencv_ts -lopencv_video -lopencv_objdetect -lopencv_ml -lpthread –lrt

~ 遇到问题:

can't find iostream ...

解决方法: sudo apt-get install build_essential(安装必需库文件) ~

查找OpenCV相关的软件包 apt-cache search opencv

本文来源:https://www.bwwdw.com/article/scxr.html

Top