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

VideoCapture MSMF plugin won't open using camera/device index. #23937

Closed
4 tasks done
pdy opened this issue Jul 6, 2023 · 0 comments · Fixed by #24133
Closed
4 tasks done

VideoCapture MSMF plugin won't open using camera/device index. #23937

pdy opened this issue Jul 6, 2023 · 0 comments · Fixed by #24133
Assignees
Milestone

Comments

@pdy
Copy link

pdy commented Jul 6, 2023

System Information

OpenCV version: at least from 4.5.5 to master
Operating System / Platform: Windows 10/11
Compiler & compiler version: Visual Studio 2022

Detailed description

It looks like unnecessary nullptr check of optional argument https://github.com/opencv/opencv/blob/4.8.0/modules/videoio/src/cap_msmf.cpp#L2722
Below linked fragment with my comments. By commenting out pointed filename check I was able to open camera on my local machine.

static
CvResult CV_API_CALL cv_capture_open_with_params(
    const char* filename, int camera_index,
    int* params, unsigned n_params,
    CV_OUT CvPluginCapture* handle
)
{
    if (!handle)
        return CV_ERROR_FAIL;
    *handle = NULL;
    if (!filename)                           // <--- filename is optional, see below
        return CV_ERROR_FAIL;      
    CaptureT* cap = 0;
    try
    {
        cv::VideoCaptureParameters parameters(params, n_params);
        cap = new CaptureT();
        bool res;
        if (filename)                                                    // if filename is true then we use
            res = cap->open(std::string(filename), &parameters);         //
        else                                                             // however if it's nullptr
            res = cap->open(camera_index, &parameters);                  // then we use index to search device
        if (res)
        {
            *handle = (CvPluginCapture)cap;
            return CV_ERROR_OK;
        }
    }
    catch (const std::exception& e)
    {
        CV_LOG_WARNING(NULL, "MSMF: Exception is raised: " << e.what());
    }
    catch (...)
    {
        CV_LOG_WARNING(NULL, "MSMF: Unknown C++ exception is raised");
    }
    if (cap)
        delete cap;
    return CV_ERROR_FAIL;
}

Steps to reproduce

Open video capture from camera (for example, laptop's built-in camera) using MSMF backend cv::VideoCapture vc(0, cv::CAP_MSMF); built as a plugin.

It's also very likely, that it's the same issue as #23056

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants