Ask Your Question
0

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

asked 2020-05-27 12:57:04 -0500

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-05-28 03:47:25 -0500

supra56 gravatar image

Change this:

VideoCapture cap;

to:

VideoCapture cap(0);

Also this too:

if (!cap.open(0)) return 0;

to:

if (!cap.open(0)) return -1;
edit flag offensive delete link more

Comments

1

Thanks for the suggestion, but no improvement. I don't think it's a problem identifying the camera as the light comes on. These are the compile lines I'm using (both compile without problem)...

x86_64-w64-mingw32-g++ -g -IC:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\include t.cpp -L c:/cygwin64/usr/x86_64-w64-mingw32/sys-root/mingw/lib -lopencv_core.dll -lopencv_videoio.dll -lopencv_highgui.dll 

cl -EHsc -IC:\users\john\desktop\opencv\build\include t.cpp c:\users\john\desktop\opencv\build\x64\vc15\lib\opencv_world3410.lib
extravert gravatar imageextravert ( 2020-05-28 08:00:44 -0500 )edit
1

And another test that works, building the same code in Ubuntu running under virtual box hosted by the same windows 10 that the mingw gcc build doesn't work for. It's only the windows mingw build that doesn't work.

extravert gravatar imageextravert ( 2020-05-28 09:57:40 -0500 )edit
1

I think I'm talking to myself here, but here goes anyway. I changed from the Cygwin installation of gcc to msys2, and the test code works, I can see my ugly fizog on the screen. So then I tried to build my real code rather than the test code, and I get unresolved symbol for cv::resize. I've looked in the library, it's there, but nothing I can do can persuade the link to work with the msys2 release of the library. I'm on the verge of giving up on supporting gcc on windows for the project, it will have to be just gcc on linux and VC++ on windows.

extravert gravatar imageextravert ( 2020-05-29 14:53:18 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-05-27 12:57:04 -0500

Seen: 49 times

Last updated: May 28