Windows:如何获得相机支持的分辨率? [英] Windows: how to get cameras supported resolutions?

查看:465
本文介绍了Windows:如何获得相机支持的分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了得到相机列表,并让用户选择一个(C ++,Boost,dshow,windows)我使用这样的代码:

So to get cameras list and let user select one (C++, Boost, dshow, windows) I use such code:

#include "StdAfx.h"
#include "list.h"
#include <windows.h>
#include <dshow.h>
#include <boost/lexical_cast.hpp>

HRESULT CamerasList::EnumerateDevices( REFGUID category, IEnumMoniker **ppEnum )
{
    // Create the System Device Enumerator.
    ICreateDevEnum *pDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,  
        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));

    if (SUCCEEDED(hr))
    {
        // Create an enumerator for the category.
        hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
        if (hr == S_FALSE)
        {
            hr = VFW_E_NOT_FOUND;  // The category is empty. Treat as an error.
        }
        pDevEnum->Release();
    }
    return hr;
}

int CamerasList::SelectFromList()
{   int i = 0;
    int SelectedIndex;
    IEnumMoniker *pEnum;
    printf("\nLet us select video device\n");
    printf("Available Capture Devices are:\n");
    HRESULT hr;
    hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
    if (SUCCEEDED(hr))
    {
        IMoniker *pMoniker = NULL;

        while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
        {
            IPropertyBag *pPropBag;
            HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
            if (FAILED(hr))
            {
                pMoniker->Release();
                continue;  
            } 

            VARIANT var;
            VariantInit(&var);

            // Get description or friendly name.
            hr = pPropBag->Read(L"Description", &var, 0);
            if (FAILED(hr))
            {
                hr = pPropBag->Read(L"FriendlyName", &var, 0);
            }
            if (SUCCEEDED(hr))
            {
                std::cout << i;
                printf(") %S\n", var.bstrVal);
                i++;
                VariantClear(&var); 
            }

            hr = pPropBag->Write(L"FriendlyName", &var);

            pPropBag->Release();
            pMoniker->Release();

        }
        SelectedIndex = 999;
    if (i <= 0)
    {
        cout <<"No devices found. \n " << endl;
        //cout <<"Please restart application."  << endl;
        //cin.get();
        //Sleep(999999);
    return 999;

    }else if(i == 1){
            cout <<"Default device will be used\n" << std::endl;
            SelectedIndex = 0;
        }else{
        while(SelectedIndex > i-1 || SelectedIndex < 0)
        {
            try{        
            std::string s;
            std::getline( cin, s, '\n' );
            SelectedIndex =  boost::lexical_cast<int>(s);
            }
            catch(std::exception& e){
                std::cout <<"please input index from 0 to " << i-1 << std::endl;
                SelectedIndex = 999;
            }
        }}
        pEnum->Release();
    }else
    {
        printf("no Video Devices found. \n") ;
        //cout <<"Please restart application."  << endl;
        //cin.get();
        //Sleep(999999);
        return 999;
    }
    return SelectedIndex;
}



我需要以某种方式获得所选摄像机支持的摄像机分辨率列表。如何做这样的事情?

I need to somehow get list of camera supported resolutions for selected camera. How to do such thing?

推荐答案

假设您已经将捕获源过滤器添加到图形:
One方法是获取 IAMStreamConfig 界面的捕获过滤器的输出引脚,然后调用IAMStreamConfig :: GetNumberOfCapabilities来获取设备支持的格式化能力的数量。您可以通过调用具有适当索引的IAMStreamConfig :: GetStreamCaps来遍历所有格式。

Assuming that you've added the capture source filter to the graph: One method is to get the IAMStreamConfig interface of the capture filter's output pin and then call the IAMStreamConfig::GetNumberOfCapabilities to get the number of format capabilities supported by the device. You can iterate over all formats by calling the IAMStreamConfig::GetStreamCaps with the appropriate indices.

这篇关于Windows:如何获得相机支持的分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆