在基于OpenCV的项目中,实际开发过程会面临设备上存在多个摄像头,需要指定摄像头的pid和vid打开摄像头。在OpenCV通过MSMF打开摄像头时,需要传入摄像头的index,因此需要在打开该摄像头前需要找出摄像头的index,下面给出通过微软的MF API找出MSMF枚举摄像头index的代码:
#include <windows.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <string>
#include <vector>
#include <iostream>
#include <opencv2/opencv.hpp>
#pragma comment(lib, "mf.lib")
#pragma comment(lib, "mfplat.lib")
#pragma comment(lib, "mfreadwrite.lib")
#pragma comment(lib, "mfuuid.lib")
struct CameraInfo {
int index; // OpenCV 摄像头索引
int vid; // Vendor ID (e.g., 0x046D for Logitech)
int pid; // Product ID (e.g., 0x0825 for C920)
std::string symbolicLink; // 设备符号链接
};
// 获取所有 Media Foundation 摄像头的 PID/VID
std::vector<CameraInfo> getMFCameraList() {
std::vector<CameraInfo> cameras;
IMFAttributes* pAttributes = nullptr;
IMFActivate** ppDevices = nullptr;
UINT32 count
OpenCV指定摄像头PID和VID及找Index方法

最低0.47元/天 解锁文章
5774

被折叠的 条评论
为什么被折叠?



