opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
78.94k stars 55.81k forks source link

OpenCV VCPKG build is giving me problems #19007

Closed SergioPrinci closed 3 years ago

SergioPrinci commented 3 years ago
System information (version)
Detailed description

Yesterday I downloaded VCPKG and then downloaded some libraries for a pretty simple project. After searched for OpenCV, I downloaded it and everything was working fine. But then, when I downloaded the contrib extra library, for the dnn_superres module, it stopped working. I thought it was a string problem because I was giving it paths and absolute paths, but nothing changed, and I still got the error that I describe here. I thought it was a video problem, maybe it was corrupted (even if I could still see it with Windows Media Player), so I downloaded a random video and tried with that, still not worked.

After that I added a fix I found on the internet, that is to add CAP_DSHOW or any other plugin for conversion. Something changed, but I wasn't still able to open the file, found out because of a (!video.isOpened) statement. Maybe I'm doing something wrong, I'm still new to the IDE and to vcpkg, I tried to build it myself, but it didn't work...

Steps to reproduce
#include <iostream>
#include <string>
#include <boost/filesystem.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/dnn_superres.hpp>

using namespace std;
using namespace cv;
using namespace dnn_superres;
using namespace boost::filesystem;

int main()
{   
    string filename;
    cout << "Drag the file here: "; 
    getline(cin, filename);
    VideoCapture video(filename, CAP_DSHOW);
    if (!video.isOpened())
    {
        cout << "Error reading the video" << endl;
        return -1;
    }
    double fps = video.get(CAP_PROP_FPS), frames = video.get(CAP_PROP_FRAME_COUNT), duration = (frames / fps) / 60;

    cout << "Source FPS: " << fps << endl;
    cout << "Total frames in the video: " << frames << endl;
    cout << "Video length in minutes: around " << round(duration) << " minutes" << endl;

    DnnSuperResImpl sr;
    sr.readModel("C:/Users/sergi/OneDrive/Desktop/Progetti/C++/AnimeEnhancer/ESPCN_x3.pb");
    sr.setModel("espcn", 3);

    create_directory("temp"); current_path("temp");

    for (int i=0; i<frames; i++)
    {
        Mat frame, upframe;

        if (!video.read(frame)) 
        {
            cout << "Error reading the frame" << endl;
            return -1;
        }
        sr.upsample(frame, upframe);
        upframe = frame;
        if (!upframe.empty())
        {
            cout << "Error upscaling the frame" << endl;
            return -1;
        }
        imwrite(to_string(i) + ".jpg", upframe);
        cout << "Elaborated frame " << i << " of " << frames << endl;
    }

    video.release();

    return 0;
}

The first error was the following:

[ WARN:0] global C:\Users\sergi\vcpkg-master\buildtrees\opencv4\src\4.3.0-8460981b10.clean\modules\videoio\src\cap_msmf.cpp (681) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (0x0 @ 1) MFVideoFormat_RGB32(unsupported media type)
Source FPS: 1
Total frames in the video: 5.01886e+09
Video length in minutes: around 8.36477e+07 minutes
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.3.0) Error: Unspecified error (FAILED: fs.is_open(). Can't open "ESPCN_ x3.pb") in cv::dnn::ReadProtoFromBinaryFile, file C:\Users\sergi\vcpkg-master\buildtrees\opencv4\src\4.3.0-8460981b10.clean\modules\dnn\src\caffe\caffe_io.cpp, line 1132

C:\Users\sergi\OneDrive\Desktop\Progetti\C++\AnimeEnhancer\Release\AnimeEnhancer.exe (processo 2052) terminato. Codice restituito: -1073740791.
Premere un tasto qualsiasi per chiudere questa finestra...

My build information:

General configuration for OpenCV 4.3.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            C:/Users/sergi/vcpkg-master/buildtrees/opencv4/src/4.3.0-795a2a992f.clean/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2020-12-03T22:01:22Z
    Host:                        Windows 10.0.19041 AMD64
    CMake:                       3.19.1
    CMake generator:             Ninja
    CMake build tool:            C:/Users/sergi/vcpkg-master/downloads/tools/ninja/1.10.1-windows/ninja.exe
    MSVC:                        1928
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2
      requested:                 SSE2
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX
      requested:                 SSE4_1 SSE4_2 AVX FP16
      SSE4_1 (13 files):         + SSE3 SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 AVX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x86/cl.exe  (ver 19.28.29334.0)
    C++ flags (Release):         /nologo /DWIN32 /D_WINDOWS /W4 /utf-8 /GR /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS  /arch:SSE /arch:SSE2 /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589  /MD /O2 /Oi /Gy /DNDEBUG /Z7
    C++ flags (Debug):           /nologo /DWIN32 /D_WINDOWS /W4 /utf-8 /GR /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS  /arch:SSE /arch:SSE2 /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x86/cl.exe
    C flags (Release):           /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS  /arch:SSE /arch:SSE2   /MD /O2 /Oi /Gy /DNDEBUG /Z7
    C flags (Debug):             /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS  /arch:SSE /arch:SSE2 /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:X86  /nologo /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF    /debug
    Linker flags (Debug):        /machine:X86  /nologo    /debug /INCREMENTAL
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          opengl32 glu32
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot quality rapid reg saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    rgbd world
    Disabled by dependency:      -
    Unavailable:                 alphamat cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype gapi java js matlab ovis python2 python3 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI:
    Win32 UI:                    YES
    OpenGL support:              YES (opengl32 glu32)

  Media I/O:
    ZLib:                        optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/zlib.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/zlibd.lib (ver 1.2.11)
    JPEG:                        optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/jpeg.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/jpegd.lib (ver 62)
    WEBP:                        optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/webp.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/webpd.lib (ver 1.1.0)
    PNG:                         optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/libpng16.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/libpng16d.lib (ver 1.6.37)
    TIFF:                        optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/tiff.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/tiffd.lib optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/lzma.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/lzmad.lib optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/jpeg.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/jpegd.lib optimized C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/zlib.lib debug C:/Users/sergi/vcpkg-master/installed/x86-windows/debug/lib/zlibd.lib (ver 42 / 4.1.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (built-in)

  Other third-party libraries:
    Custom HAL:                  NO
    Protobuf:                    C:/Users/sergi/vcpkg-master/installed/x86-windows/lib/libprotobuf.lib (3.14.0)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/Users/sergi/vcpkg-master/buildtrees/opencv4/src/4.3.0-8460981b10.clean/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            NO

  Install to:                    C:/Users/sergi/vcpkg-master/packages/opencv4_x86-windows
-----------------------------------------------------------------
Issue submission checklist
SergioPrinci commented 3 years ago

Solved by building it myself with version 4.5.0