使用 openCV 库时出现必需品错误

Posted

技术标签:

【中文标题】使用 openCV 库时出现必需品错误【英文标题】:error in necessitas while use openCV libs 【发布时间】:2012-01-15 08:49:08 【问题描述】:

我在 QT 中为 android 设备编程,需要使用 openCV 从相机捕获。我已经使用了 Qt creator 并链接了 openCV 并使用了相机,但是在 Qt for android (necessitas) 中构建程序时,显示此错误:

C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(cap_images.o): In function `CvCapture_Images::close()':
    cap_images.cpp:(.text._ZN16CvCapture_Images5closeEv+0x1c): undefined reference to `cvReleaseImage'
    C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(cap_images.o): In function `CvCapture_Images::grabFrame()':
    cap_images.cpp:(.text._ZN16CvCapture_Images9grabFrameEv+0x1e): undefined reference to `cvReleaseImage'
    C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(cap_ffmpeg.o): In function `CvCapture_FFMPEG_proxy::retrieveFrame(int)':
    cap_ffmpeg.cpp:(.text._ZN22CvCapture_FFMPEG_proxy13retrieveFrameEi[CvCapture_FFMPEG_proxy::retrieveFrame(int)]+0x50): undefined reference to `cvInitImageHeader'
    cap_ffmpeg.cpp:(.text._ZN22CvCapture_FFMPEG_proxy13retrieveFrameEi[CvCapture_FFMPEG_proxy::retrieveFrame(int)]+0x5a): undefined reference to `cvSetData'
    C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(cap_ffmpeg.o): In function `CvVideoWriter_FFMPEG_proxy::writeFrame(_IplImage const*)':
    cap_ffmpeg.cpp:(.text._ZN26CvVideoWriter_FFMPEG_proxy10writeFrameEPK9_IplImage[CvVideoWriter_FFMPEG_proxy::writeFrame(_IplImage const*)]+0x5e): undefined reference to `cv::Exception::Exception(int, std::string const&, std::string const&, std::string const&, int)'
    cap_ffmpeg.cpp:(.text._ZN26CvVideoWriter_FFMPEG_proxy10writeFrameEPK9_IplImage[CvVideoWriter_FFMPEG_proxy::writeFrame(_IplImage const*)]+0x64): undefined reference to `cv::error(cv::Exception const&)'
    cap_ffmpeg.cpp:(.text._ZN26CvVideoWriter_FFMPEG_proxy10writeFrameEPK9_IplImage[CvVideoWriter_FFMPEG_proxy::writeFrame(_IplImage const*)]+0x6a): undefined reference to `cv::Exception::~Exception()'
    cap_ffmpeg.cpp:(.text._ZN26CvVideoWriter_FFMPEG_proxy10writeFrameEPK9_IplImage[CvVideoWriter_FFMPEG_proxy::writeFrame(_IplImage const*)]+0x11c): undefined reference to `cv::Exception::~Exception()'
C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(grfmt_tiff.o): In function `cv::TiffEncoder::newEncoder() const':
grfmt_tiff.cpp:(.text._ZNK2cv11TiffEncoder10newEncoderEv+0x16): undefined reference to `cv::fastMalloc(unsigned int)'
C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(grfmt_tiff.o): In function `cv::TiffDecoder::newDecoder() const':
grfmt_tiff.cpp:(.text._ZNK2cv11TiffDecoder10newDecoderEv+0x16): undefined reference to `cv::fastMalloc(unsigned int)'
C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_highgui.a(grfmt_tiff.o): In function `cv::TiffDecoder::~TiffDecoder()':
grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoderD1Ev+0x48): undefined reference to `cv::fastFree(void*)'
grfmt_tiff.cpp:(.text._ZN2cv11TiffDecoderD1Ev+0x6e): undefined reference to `cv::Mat::deallocate()'
        .
        .
        .

首先我下载最新版本的 openCV 并构建它,然后使用库。也在

项目.pro

添加以下行:

INCLUDEPATH += "C:\OpenCV2.3.1\include\opencv" 
LIBS +="C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_androidcamera.a" \
"C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_calib3d.a" \
"C:/OpenCV2.3.1/libs/armeabi-v7a/libopencv_calib3d_pch_dephelp.a" \ .
...

necessitas 可以支持 openCV 吗?为什么显示这个错误?

对不起我的英语。

【问题讨论】:

How to integrate OpenCV into Qt Creator Android project的可能重复 【参考方案1】:

事实证明,.a 文件的顺序很重要。将它们按此顺序排列(将路径更改为路径)对我有用:

LIBS += \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_calib3d.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_flann.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_objdetect.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_contrib.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_video.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_ml.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_legacy.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_highgui.a \
    /media/Software/android/OpenCV-2.3.1/share/OpenCV/3rdparty/libs/armeabi-v7a/liblibjpeg.a \
    /media/Software/android/OpenCV-2.3.1/share/OpenCV/3rdparty/libs/armeabi-v7a/liblibpng.a \
    /media/Software/android/OpenCV-2.3.1/share/OpenCV/3rdparty/libs/armeabi-v7a/liblibtiff.a \
    /media/Software/android/OpenCV-2.3.1/share/OpenCV/3rdparty/libs/armeabi-v7a/liblibjasper.a \
    /media/Software/android/OpenCV-2.3.1/share/OpenCV/3rdparty/libs/armeabi-v7a/libzlib.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_ts.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_imgproc.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_core.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_androidcamera.a \
    /media/Software/android/OpenCV-2.3.1/libs/armeabi-v7a/libopencv_features2d.a

INCLUDEPATH += /media/Software/android/OpenCV-2.3.1/include/opencv/ \
               /media/Software/android/OpenCV-2.3.1/include/

【讨论】:

【参考方案2】:

找到并添加 libtiff.a,它可能在 opencv 3rd 方库目录中。

【讨论】:

以上是关于使用 openCV 库时出现必需品错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 MingW 运行 OpenCV 项目时出现入口点错误

在 Eclipse 上使用 opencv 3.0 时出现链接错误

使用 Contour Area-OpenCV 时出现断言错误

使用某些 OpenCV 函数“阈值”Eclipse 时出现链接错误

使用opencv进行人脸识别时出现属性错误

编译 opencv_contrib 时出现很多错误