标题: Linux 下编译安装OpenCV [打印本页] 作者: thinkfunny 时间: 2021-4-14 09:02 标题: Linux 下编译安装OpenCV 本帖最后由 thinkfunny 于 2021-4-14 09:03 编辑 2 ~6 x% e4 m+ m2 p3 Z
4 n' C: n4 q6 I- Z- I2 |/ a5 h
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/chengchenglu/work/Opencv/opencv-3.4.0/modules/highgui/src/window.cpp, line 611
terminate called after throwing an instance of 'cv::Exception'
what(): /home/chengchenglu/work/Opencv/opencv-3.4.0/modules/highgui/src/window.cpp:611: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
5 F# G, z. ~+ s( X: u6 y 5 m5 g( _' R8 s( C3 g/ @Ubuntu 下安装 OpenCV / g+ o- i7 i5 y7 r! u7 E. `; |4 `6 L+ D3 X: [; u: i
软件环境:+ X5 t8 [' l5 F3 \1 ? K& x
; @" C- j; m( o' o* ~) V
Ubuntu 12.04 5 T% u, s& Z6 {6 s d' l; h% k$ A6 v8 k1 A
OpenCV 2.4.32 H) N. L6 m+ b' j" r4 @2 a" F2 X
$ ^8 Y" k' F# l: W- h ?. QCmake 2.8.10.19 b0 C9 `$ P; w- C! _
: x9 t M1 t# Y& z, H5 }
gcc 4.6.3 (系统默认)" `# Q E6 _. m3 E
% R$ P7 e0 j, ^7 w, ], P : ^- U: _3 x; [1 M4 K$ D
$ P) @+ V' d9 ^7 R; Z8 _, @4 d
1、先安装 libgtk2.0-dev 和 pkg-config,,否则后期编译运行程序会出现类似如下的问题: # a2 r, V+ ]1 \$ R0 x( ` - D/ S1 j9 k0 R. U' KOpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /usr/local/opencv/OpenCV-2.0.0/src/highgui/window.cpp, line 100 & I1 \( [% F# s- q8 I: f7 D6 w( f
terminate called after throwing an instance of 'cv::Exception'6 S# p+ Q" L6 ~; v q' D! {5 f- y% }6 q
8 P! p2 |/ m; j. I, C这里指对一个地方进行修改,CMAKE_BUILD_TYPE 值输入RELEASE,其他保持不变,图中蓝色虚线部分显示了默认的安装目录,生成makefile文件最后执行 make install时就会安装到这个目录,这里可以根据个人需求更改。在这里的配置中我勾选了WITH_QT 去掉了WITH_TIFF,其他更多的配置也不清楚,OpenCV中文网站也没找到系统的说明,这里暂时不深究,点击Generate生成配置文件。7 l; t7 O7 H) f
7 q" b) p* C8 C/ E8 J2 {进入OpenCV-x86目录可以查看Makefile文件,可以留意文件的生成时间是否和刚才的生成时间一致。 U9 J9 m& S# F. ?+ l0 f
% d% ?: T: v, U* ^8 N% G3 z4、接下来在OpenCV-x86 分别执行make和make install即可完成编译安装。 ( |4 C6 Z- g8 W. O8 g3 B- W0 g( M( Y
5、安装完成后需要对系统相关环境变量进行配置:+ w5 h+ q" f1 J: ?- t+ p* V
4 _8 I! e! ~3 q7 ^ i
) t T, ]. \- Y$ a6 Q( e# l$ G& Y I/ q) V8 A% R
保存退出,在运行下面的例程之前,需要重新开启终端来使配置生效。- K& O9 f! S- P, e3 h q
! e% z: I2 h6 x( }) f8 S! A5 r 5 p1 y& Z/ U$ c2 n+ p' h# |例程测试& r5 A5 D; ?" F& R* T5 ^8 h
) T' H. n2 y7 l& c, L
拷贝步骤2中解压的的/OpenCV-2.4.3/samples/c 将c文件夹拷贝出来,下面运行一下这里面的一个例程,初步体验下OpenCV。拷贝完成后进入这个文件夹: 7 K, A2 `# {3 Q3 G# P; ~* y- o . _/ V1 e# h, ?chmod +x build_all.sh 0 f9 v4 ]) ^+ x( q! U9 Z 2 J( q9 a0 B# H./build_all.sh) i% M# U- P" A
' S; f6 _! z# `" W9 J5 I+ v" W+ }% n) Q
这样就对例程目录下的源文件进行了编译,这里运行一个人脸检测的程序,下面摘录自本文参考资料3。6 Y8 W4 |8 J, T0 R/ G( j$ @0 r' I
2 n% ]9 @* z& S4 W7 O9 W# [
Some of the training data for object detection is stored in /usr/local/share/opencv/haarcascades. You need to tell OpenCV which training data to use. I will use one of the frontal face detectors available. Let’s find a face: 2 J+ j; }) F) ]+ @! G% a + O, o+ }4 G6 x* @0 P, z N终端中运行:0 T9 V' N: X4 \5 ]6 G