我想使用DirectShow的IAMVideoProcAmp获得对webcam properties的低级访问。在
有几个Python模块)pywin32
,pywintypes
,comtypes
,win32com
,pythoncom
),它们似乎以某种方式相关。但我不知道从哪里开始。在
我找到了一些示例(here,here,here),但我无法找到如何获得一个IID/CLSID来使用
import win32com.client
clsid='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
ShellWindows=win32com.client.Dispatch(clsid)
或者有一个明确的名字
^{pr2}$或者
from comtypes import client, GUID
graph = client.CreateObject(some_CLSID)
graph.QueryInterface(...)
有人能帮我吗?在
我找到了另一个例子(dshow.py),但它有一些我找不到的依赖项(interfaces
,uuids
)。在
来自Microsoft的This页将过程列出为
Call QueryInterface on the capture filter for the IAMVideoProcAmp interface.
或者
Query the capture filter for the IAMCameraControl.
并给出了一些C++代码:
// Query the capture filter for the IAMVideoProcAmp interface.
IAMVideoProcAmp *pProcAmp = 0;
hr = pCap->QueryInterface(IID_IAMVideoProcAmp, (void**)&pProcAmp);
hr = m_pProcAmp->GetRange(VideoProcAmp_Brightness, &Min, &Max, &Step,
&Default, &Flags);
编辑: 我终于找到了一些目前看来不错的代码:
它似乎完全符合我要写的东西,并使用了 DirectShow(see here):
from comtypes.gen.DirectShowLib import (FilterGraph, CaptureGraphBuilder2, ...)
在雅拉科视频声称是“纯Python中使用ctypes和comtypes的VideoCapture模块的端口。”
它使用^{
A type library (.tlb) is a binary file that stores information about a COM or DCOM object's properties and methods in a form that is accessible to other applications at runtime.
确定复制代码所需的值
再看一眼你文章末尾的代码节选,我意识到你只需要IID,而不需要
IAMVideoProcAmp
的CLSID来获取它的实例。在查看this source of strmif.h的第8733行,它是接口所需的头,我发现
IID_IAMVideoProcAmp
是C6E13360-30AC-11d0-A18C-00A0C9118956
。在在strmif.h的这一节之上,您可以确定哪些整数对应于}。在strmif.h的这一节下面,您可以确定哪些整数对应于}。我不熟悉如何在Python中与COM对象进行交互,但在爪哇中,您需要确定这些属性和函数索引,以便复制演示如何获取^ {CD10}}实例的C++代码摘录。在
tagVideoProcAmpProperty
枚举中的哪些属性,例如0
对应于{IAMVideoProcAmpVtbl
VTable中的哪些函数,例如3
表示{获取
IAMVideoProcAmp
的实例正如您可能注意到的,C++代码摘录在^ { < CD13>}上调用^ {< CD12>},并注意到您需要“查询IAMVIEW OPROAMP接口的捕获过滤器”。
现在您已经知道了如何获取
pCap
,您注意到您需要一个名为pMoniker
的东西,它在同一篇文章的前面已经定义。代码相当长,所以我在这里省略了它。在在Python中完成所有这些
正如我之前提到的,我从来没有使用任何Python COM库,所以我不能轻易地举一个例子,但是你的目标应该是用Python复制C++实例中的函数调用来获取一个^ {CD1>}的实例,并根据需要修改它们。在
我终于找到了一些有用的示例库:
jaraco
它正是我想要达到的效果,并使用了 DirectShow(see here):
在雅拉科视频声称是“纯Python中使用ctypes和comtypes的VideoCapture模块的端口。”
它使用一个^{} 文件(不管是什么)来获取定义
变成comtypes
导入是在
^{pr2}$__init__.py
中自动生成的,可以轻松使用:并且可以使用
然后您可以将这些函数与文档中声明的
enum
结合使用,例如相关问题 更多 >
编程相关推荐