Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV debug mode VideoCapture with file is broken #2613

Closed
patrikhuber opened this issue Jan 19, 2018 · 7 comments
Closed

OpenCV debug mode VideoCapture with file is broken #2613

patrikhuber opened this issue Jan 19, 2018 · 7 comments
Assignees

Comments

@patrikhuber
Copy link
Contributor

I've installed OpenCV 3.4.0 from vcpkg with opencv[ffmpeg] (without ffmpeg, it doesn't work either).

In Release and RelWithDebInfo mode, both camera and reading from files (e.g. an .avi file) is fine.
In Debug mode however, reading from the camera works, but not reading from the avi file.

    std::string inputvideo("vid.avi)";
    cv::VideoCapture cap;
    if (inputvideo.empty()) {
        cap.open(0); // no file given, open the default camera
    }
    else {
        cap.open(inputvideo);
    }
    if (!cap.isOpened()) {
        std::cout << "Couldn't open the given file or camera 0." << std::endl;
        return EXIT_FAILURE;
    }

cap.isOpened() fails in this scenario.

The problem also does not occur if I build OpenCV by myself (outside of vcpkg) and also not with the binary package from opencv.org.
It also occured on OpenCV 3.3.x in vcpkg.

@patrikhuber
Copy link
Contributor Author

patrikhuber commented Jan 19, 2018

In RelWithDebInfo mode, cv::VideoCapture cap gets assigned an ffmpegCapture and it works successfully.
However in Debug mode, I can't even step into the cap.open(inputvideo); function call to see what's happening, it says cap <Information not available, no symbols loaded for opencv_videoio340d.dll> cv::VideoCapture. This might be presumably because there is on pdb built for ffmpeg - vcpkg's build outputs this warning at the end:

-- Warning: Could not find a matching pdb file for:
    vcpkg/packages/opencv_x64-windows/bin/opencv_ffmpeg340_64.dll
    vcpkg/packages/opencv_x64-windows/debug/bin/opencv_ffmpeg340_64.dll

But still this should not cause the video to fail to load completely.
(And as mentioned, self-built & opencv.org packages are fine).

Adding vcpkg\installed\x64-windows\debug\bin to VS's symbol file locations doesn't help.

@sirexeclp
Copy link

Im having the same issue.
Have you found any workaround yet ?

@patrikhuber
Copy link
Contributor Author

No I haven't, I went back to using my self-compiled version of OpenCV.
I am waiting for a magical fix from the package maintainers to fix this so I can go back to using vcpkg ;-)

@patrikhuber
Copy link
Contributor Author

@ras0219-msft, is there anything we can do? I don't seem to be the only one with this issue, pointing to a problem in the vcpkg OpenCV package. And the camera input not working is quite a big issue.

@ras0219-msft ras0219-msft self-assigned this Feb 12, 2018
@ras0219-msft
Copy link
Contributor

Ok, so I am actually unable to reproduce this issue (it works in debug for me). Let me share my setup:

// main.cpp
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <cstdio>
#include <opencv2/opencv.hpp>

int main(int argc, char** argv)
{
    if (argc < 2)
        return -1;

    std::string inputvideo(argv[1]);

    cv::VideoCapture cap;

    if (inputvideo.empty()) {
        cap.open(0); // no file given, open the default camera
    }
    else {
        cap.open(inputvideo);
    }
    if (!cap.isOpened()) {
        std::cout << "Couldn't open the given file or camera 0." << std::endl;
        return EXIT_FAILURE;
    }

    getchar();
    return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)

project(main CXX)

add_executable(main main.cpp)

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${OpenCV_LIBS})

I installed opencv:x64-windows, built my program above with the vcpkg toolchain, and tried to load the SAMPLE.avi from [1]. This fails in debug and release, because it needs ffmpeg.

I then installed opencv[ffmpeg]:x64-windows and rebuilt the program. It still didn't deploy the ffmpeg dll (this is a bug we need to fix!) but that caused failures in both debug and release. Once I manually deployed the opencv_ffmpeg340_64.dll to the output folder for my application (found via vcpkg owns _ffmpeg), both debug and release ran correctly.

I suspect you might have some other OpenCV DLLs available elsewhere in your path, which are getting loaded and cause issues only in debug mode, but that's just a guess.

[1] http://www.technical-recipes.com/2011/displaying-avi-video-using-opencv/

@patrikhuber
Copy link
Contributor Author

@ras0219-msft: Riiight. So the key is:

Once I manually deployed the opencv_ffmpeg340_64.dll to the output folder for my application (found via vcpkg owns _ffmpeg), both debug and release ran correctly.

I was able to reproduce what you did in a simple toy project (msbuild, not cmake), and it seems to work in Release and Debug mode. I haven't tested it in my production setup and with CMake yet, I will do so shortly.
I remember that I did check the PATHs before (I fiddled with them quite a lot) and was careful to not have an OpenCV location other than that from vcpkg in there. I didn't know that vcpkg doesn't even need to be in the PATH and still works. So you copy the dll's to the build folder for app-local deployment - right. That's actually kind of nice. :-)
I'll check my production setup and update the issue here. Thank you very much for having a look at this.

It still didn't deploy the ffmpeg dll (this is a bug we need to fix!)

I can't find an Issue for this yet - shall I open one?

@patrikhuber
Copy link
Contributor Author

I can confirm that it now works in all three modes - Release, Debug and RelWithDebInfo, and for camera as well as video files.
The key was indeed to copy & paste opencv_ffmpeg340_64.dll over to the build folder. I did not do that before, which caused it to fail.

Thank you very much again for helping to investigate. Finally back to using vcpkg :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants