Ask Your Question

Revision history [back]

Video camera -Windows Visual C++ build works, gcc doesn't

I'm compiling the standard sample code for sending video captured by the camera to a window, this sort of thing...

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char** argv)
{
    VideoCapture cap;
    if (!cap.open(0)) return 0;
    for (;;)
    {
        Mat frame;
        cap >> frame;
        if (frame.empty()) break; 
        imshow("title", frame);
        if (waitKey(10) == 27) break; 
    }
    return 0;
}

For the Visual C++ build I'm linking to the X64 VC15 pre-built library opencv_world3410d.lib, and it all works fine. However, when I build exactly the same code using gcc (x86_64-w64-mingw32-g++) and link it to the pre-built libraries opencv_core.dll, opencv_videoio.dll & opencv_highgui.dll it builds fine, runs up, the camera light comes on, but the display is black.

The only thing I can find is if I go to Windows 10 privacy/camera settings my Visual C++ built application is there in the list but my gcc built one is not. This doesn't seem to be a useful list - it can't be added to, just a list of what applications have used the camera recently from what I can see.

Anyone any idea? I am working on a project that needs to be buildable with both Visual C++ and gcc.