kyamagu / mexopencv

Collection and a development kit of matlab mex functions for OpenCV library
http://kyamagu.github.io/mexopencv
Other
661 stars 319 forks source link

problem with make in ubuntu #365

Closed eghbalhosseini closed 6 years ago

eghbalhosseini commented 7 years ago

I am building mexopencv in ubuntu 16.04 but get the following error during make process

Building with 'g++'.
/tmp/mex_1045233700939060_22757/DPMDetector_.o: In function `mexFunction':
DPMDetector_.cpp:(.text+0x1b8): undefined reference to `cv::dpm::DPMDetector::create(std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&)'
DPMDetector_.cpp:(.text+0x24e): undefined reference to `cv::dpm::DPMDetector::create(std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&)'
collect2: error: ld returned 1 exit status

Makefile:171: recipe for target 'opencv_contrib/+cv/private/DPMDetector_.mexa64' failed
make: *** [opencv_contrib/+cv/private/DPMDetector_.mexa64] Error 255

Please let me know if this a known problem and how it could be fixed.

Thanks, Eghbal

amroamroamro commented 7 years ago

Can you provide more info about your environment, like what opencv version you're using, how it was built, whether you've enabled opencv_contrib, etc..

The most important thing is to make sure you're using the correct version 3.3.0

You should start with the wiki, it has detailed installation instructions: https://github.com/kyamagu/mexopencv/wiki/Installation-%28Linux%2C-MATLAB%2C-OpenCV-3%29

eghbalhosseini commented 7 years ago

Thanks, I followed the link and mexopencv seems to install fine, however when I run the command cv.VideoCapture I get the following error

Invalid MEX-file '/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64':
Missing symbol '_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4findEcm' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5rfindEcm' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareEPKc' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_replaceEmmPKcm'
required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE14_M_replace_auxEmmmc'
required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6assignEPKc' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6resizeEmc' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7reserveEm' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE8_M_eraseEmm' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm' required
by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_assignERKS4_' required
by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm' required
by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol
'_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZTTNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZTVNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZTVNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE' required by
'/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4findEPKcmm' required by
'/usr/lib/x86_64-linux-gnu/libIex-2_2.so.12->/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_replaceEmmPKcm'
required by
'/usr/lib/x86_64-linux-gnu/libIex-2_2.so.12->/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm' required
by
'/usr/lib/x86_64-linux-gnu/libIex-2_2.so.12->/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_assignERKS4_' required
by
'/usr/lib/x86_64-linux-gnu/libIex-2_2.so.12->/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm' required
by
'/usr/lib/x86_64-linux-gnu/libIex-2_2.so.12->/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm' required
by
'/usr/lib/x86_64-linux-gnu/libIlmThread-2_2.so.12->/usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22->/usr/local/lib/libopencv_imgcodecs.so.3.3->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_add' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_add_tag' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_clear' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_init' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_query' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_query_count' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6resizeEmc' required by
'/usr/lib/x86_64-linux-gnu/libsnappy.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'
Missing symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm' required
by
'/usr/lib/x86_64-linux-gnu/libsnappy.so.1->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56->/usr/local/lib/libopencv_videoio.so.3.3->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'.
amroamroamro commented 7 years ago

See the troubleshooting section of the wiki:

https://github.com/kyamagu/mexopencv/wiki/Troubleshooting-(UNIX)#invalid-mex-file-or-segmentation-fault

Basically MATLAB bundles its own (often incompatible) version of some of the libraries that opencv also depends on, which explains the "missing symbol" errors. A possible solution is to force-load incompatible libraries, by preloading the system libs you built opencv against, rather than getting the (usually older) ones bundled with matlab.

As explained in the wiki link above, you would do something like:

$ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/lib/x86_64-linux-gnu/libgcc_s.so.1 matlab

(PS: MATLAB lists "GCC C/C++ 4.9.x" as compatible compilers for Linux, but Ubuntu 16.04 comes with gcc-5 by default I believe. That's likely to be a cause of problem too.)

To find out which libraries are conflicting, run ldd on the mex-file both inside MATLAB and outside in the Bash terminal, and look for differences:

# shell
$ ldd /home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64
% MATLAB
>> !ldd /home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64

Sometimes you might need to check second dependencies. For instance:

Missing symbol 'th_comment_add' required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1
->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56
->/usr/local/lib/libopencv_videoio.so.3.3
->/home/zebrafishbehavior/cv/mexopencv/+cv/private/VideoCapture_.mexa64'

The above error suggests to me some sort of conflict in the Theora lib required by FFmpeg, which in turn is used by the videoio module. You would confirm by comparing:

# shell
$ ldd /usr/local/lib/libopencv_videoio.so.3.3
% MATLAB
>> !ldd /usr/local/lib/libopencv_videoio.so.3.3

As a general tip, you can debug this sort of shared-libraries-loading-problems by using the LD_DEBUG environment variable. Used like:

$ LD_DEBUG_OUTPUT=debug.log LD_DEBUG=all matlab -nodesktop -r "cv.VideoCapture(0); quit;"
eghbalhosseini commented 7 years ago

Thanks, I added the Preload libraries and now the cv.VideoCapture seems to start the camera. However when I try to capture images I get the following error :

libdc1394 error: usb: Bulk transfer 5 failed with code 6

Would you have any suggestion on how to fix this?

amroamroamro commented 7 years ago

Is this the same camera you mentioned in your other post? If it is, I'm afraid I don't have experience with industrial cameras nor do I have access to one to test support. You should try asking help on an opencv forum...

What I can suggest is to directly test with C++ code, to see if opencv is capable of grabbing frames from your camera in the first place.

Like I explained before, assuming your camera is supported by OpenCV, you should pick the right backend in the open method, and actually have it enabled at build-time. For instance if your camera is connected using IEEE1394, opencv must be configured with cmake -DWITH_1394=ON ... (with the libdc1394 library installed of course).

Here is an example to get you started:

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

int main()
{
    // check the "Video I/O" section in the output, make sure your backend is enabled!
    cout << getBuildInformation() << endl;

    VideoCapture cap;
    cap.open(0, cv::CAP_ANY);  // try different backends here
    if (!cap.isOpened()) {
        cerr << "failed to initialize capturing" << endl;
        return 1;
    }
    cout << "Capturing... Press any key to terminate" << endl;
    Mat frame;
    while (true) {
        cap >> frame;
        if (frame.empty()) break;
        imshow("live", frame);
        if (waitKey(5) >= 0) break;
    }
    cap.release();
    return 0;
}

If it doesn't work in C++ either, I would say this an issue/limitation of OpenCV itself, out of control of mexopencv.

fybaft2012 commented 6 years ago

Hi eghbalhosseini, Did you solve the Missing symbol problem, I also met the similar errors (#395)

Could you give me help? Thanks!

thesidjway commented 6 years ago

https://github.com/vlfeat/matconvnet/issues/967#issuecomment-298167606 This issue has a solution that worked for me perfectly.