【问题标题】:install opencv for perl (centos)为 perl (centos) 安装 opencv
【发布时间】:2014-04-21 12:29:51
【问题描述】:

我正在尝试在 perl 上进行人脸检测,但我发现了 OpenCV 和 CPAN herehere 上的 perl 模块 Image::ObjectDetect。我已经在虚拟机上完成了 CentOS 6.5(最小)的全新安装来测试这个,然后:

yum -y update
yum -y install perl cpan opencv

好的,考虑到我以前从未使用过 cpan,我尝试了明显的(经过一些简短的谷歌搜索)

perl -MCPAN -e shell
[accept default]
install Image::ObjectDetect

这给了我一些错误:

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

在谷歌搜索该错误后,我做到了:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
mkdir /usr/local/lib/pkgconfig
vi /usr/local/lib/pkgconfig/opencv.pc

文件内容:

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

再次运行安装后,我发现我缺少 gcc:

/bin/sh: gcc: command not found
yum -y install gcc

现在再次运行安装会给我:

...
Note (probably harmless): No library found for -lopencv_calib3d
Note (probably harmless): No library found for -lopencv_imgproc
Note (probably harmless): No library found for -lopencv_contrib
Note (probably harmless): No library found for -lopencv_legacy
Note (probably harmless): No library found for -l
Writing Makefile for Image::ObjectDetect
Could not read '/root/.cpan/build/Image-ObjectDetect-0.12-BsNNjF/META.yml'. Falling back to other methods to determine prerequisites
cp lib/Image/ObjectDetect.pm blib/lib/Image/ObjectDetect.pm
cp lib/Image/ObjectDetect.xs blib/lib/Image/ObjectDetect.xs
/usr/bin/perl /usr/share/perl5/ExtUtils/xsubpp  -typemap /usr/share/perl5/ExtUtils/typemap  ObjectDetect.xs > ObjectDetect.xsc && mv ObjectDetect.xsc ObjectDetect.c
gcc -c   -I/usr/include/opencv -I/usr/include/opencv2  -Isrc -I/usr/include/opencv -I/usr/include/opencv2   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables   -DVERSION=\"0.12\" -DXS_VERSION=\"0.12\" -fPIC "-I/usr/lib/perl5/CORE"   ObjectDetect.c
In file included from ObjectDetect.xs:7:
/usr/lib/perl5/CORE/cv.h:13: error: redefinition of ‘struct xpvcv’
/usr/lib/perl5/CORE/cv.h:94: error: conflicting types for ‘xpvcv_allocated’
/usr/lib/perl5/CORE/cv.h:94: note: previous declaration of ‘xpvcv_allocated’ was here
ObjectDetect.xs:8:21: error: highgui.h: No such file or directory
ObjectDetect.xs: In function ‘XS_Image__ObjectDetect_new’:
ObjectDetect.xs:19: error: ‘CvHaarClassifierCascade’ undeclared (first use in this function)
ObjectDetect.xs:19: error: (Each undeclared identifier is reported only once
ObjectDetect.xs:19: error: for each function it appears in.)
ObjectDetect.xs:19: error: ‘cascade’ undeclared (first use in this function)
ObjectDetect.xs:22: warning: implicit declaration of function ‘cvLoad’
ObjectDetect.xs: In function ‘XS_Image__ObjectDetect_xs_detect’:
ObjectDetect.xs:37: error: ‘IplImage’ undeclared (first use in this function)
ObjectDetect.xs:37: error: ‘img’ undeclared (first use in this function)
ObjectDetect.xs:37: error: ‘gray’ undeclared (first use in this function)
ObjectDetect.xs:37: warning: left-hand operand of comma expression has no effect
ObjectDetect.xs:39: error: ‘CvMemStorage’ undeclared (first use in this function)
ObjectDetect.xs:39: error: ‘storage’ undeclared (first use in this function)
ObjectDetect.xs:40: error: ‘CvHaarClassifierCascade’ undeclared (first use in this function)
ObjectDetect.xs:40: error: ‘cascade’ undeclared (first use in this function)
ObjectDetect.xs:41: error: ‘CvSeq’ undeclared (first use in this function)
ObjectDetect.xs:41: error: ‘objects’ undeclared (first use in this function)
ObjectDetect.xs:42: error: ‘CvRect’ undeclared (first use in this function)
ObjectDetect.xs:42: error: ‘rect’ undeclared (first use in this function)
ObjectDetect.xs:46: warning: implicit declaration of function ‘cvLoadImage’
ObjectDetect.xs:50: warning: implicit declaration of function ‘cvCreateImage’
ObjectDetect.xs:50: warning: implicit declaration of function ‘cvSize’
ObjectDetect.xs:51: warning: implicit declaration of function ‘cvCvtColor’
ObjectDetect.xs:51: error: ‘CV_BGR2GRAY’ undeclared (first use in this function)
ObjectDetect.xs:52: warning: implicit declaration of function ‘cvEqualizeHist’
ObjectDetect.xs:54: warning: implicit declaration of function ‘cvCreateMemStorage’
ObjectDetect.xs:55: error: expected expression before ‘)’ token
ObjectDetect.xs:56: warning: implicit declaration of function ‘cvHaarDetectObjects’
ObjectDetect.xs:58: error: ‘CV_HAAR_DO_CANNY_PRUNING’ undeclared (first use in this function)
ObjectDetect.xs:65: error: expected expression before ‘)’ token
ObjectDetect.xs:74: warning: implicit declaration of function ‘cvReleaseMemStorage’
ObjectDetect.xs:75: warning: implicit declaration of function ‘cvReleaseImage’
ObjectDetect.xs: In function ‘XS_Image__ObjectDetect_DESTROY’:
ObjectDetect.xs:86: error: ‘CvHaarClassifierCascade’ undeclared (first use in this function)
ObjectDetect.xs:86: error: ‘cascade’ undeclared (first use in this function)
ObjectDetect.xs:88: error: expected expression before ‘)’ token
ObjectDetect.xs:89: warning: implicit declaration of function ‘cvReleaseHaarClassifierCascade’
make: *** [ObjectDetect.o] Error 1
JIRO/Image-ObjectDetect-0.12.tar.gz
/usr/bin/make -- NOT OK
Warning (usually harmless): 'YAML' not installed, will not store persistent state
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
JIRO/Image-ObjectDetect-0.12.tar.gz          : make NO

有什么帮助吗?谢谢。

【问题讨论】:

  • 在编译日志的最后部分,您会收到关于 make 的错误。虽然您可能需要在这里使用gmake,但更有可能的是ObjectDetect.o 尚未构建,因此无法运行测试。而不是我在下面建议的 OpenCV 列表,您最好只通过电子邮件发送 JIRO 以查看 Image::ObjectDetect 是否适用于较新版本的 OpenCV。
  • 这里记录了一些可能相关的 ObjectDetect 编译冒险:perlmonks.org/?node_id=1037892 这可能会让您了解人们如何尝试调试使用 C 的模块的问题。

标签: perl opencv cpan


【解决方案1】:

很高兴看到有人在 Perl 中使用 OpenCV!我希望你能让它工作并向我们展示一些不错的 asps 和脚本 :-)

您似乎是从源代码构建安装包(使用yum) - 这有时会使依赖关系复杂化。例如,您的 OpenCV 版本可能对于 CPAN 模块来说太新。 Image::ObjectDetect` 相当老了 (上一个版本是几年前的 http://metacpan.org/pod/Image::ObjectDetect),而 OpenCV 正在积极开发中。

注意这一行:

ObjectDetect.xs:8:21: error: highgui.h: No such file or directory

最近一次更新后,我在编译依赖于 OpenCV 的应用程序时遇到了类似的错误。要么头文件丢失;要么应用程序Makefiles 不知道如何找到它们;或者依赖链中的其他开发库和头文件也需要更新。

通过发布到 OpenCV 开发列表中,错误消息可能看起来更熟悉,您可能会获得更好的解决此问题的方法。

见:http://groups.yahoo.com/neo/groups/OpenCV/info

您可以尝试安装一些其他模块,看看是 perlXSgcc 还是您的 OpenCV 版本有问题。这是另一个使用 OpenCV 的模块:

https://github.com/shisful/Image-OpenCV

【讨论】:

  • 感谢您的回复。就像你提到的,这个问题可能与 opencv 和 image::obejctdetect 之间的版本差异有关。现在我通过编译最新版本的 opencv 并创建一个我使用 perl 调用的小型 python 脚本来解决它。它有点乱,但它(几乎)工作:)
猜你喜欢
  • 2012-07-30
  • 1970-01-01
  • 2016-03-06
  • 2021-04-22
  • 1970-01-01
  • 2016-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多