예제 #1
0
    def initialize(self):
        self.filter_graph = CreateObject(FilterGraph)
        self.control = self.filter_graph.QueryInterface(IMediaControl)
        self.graph_builder = CreateObject(CaptureGraphBuilder2)
        self.graph_builder.SetFiltergraph(self.filter_graph)
        dev_enum = CreateObject(DeviceEnumerator)
        class_enum = dev_enum.CreateClassEnumerator(
            CLSID_VideoInputDeviceCategory, 0)
        #del dev_enum

        for iCount in six.moves.range(self.devnum):
            try:
                (moniker, fetched) = class_enum.RemoteNext(1)
            except ValueError:
                raise RuntimeError("Device not found")

        # del class_enum

        null_context = POINTER(IBindCtx)()
        null_moniker = POINTER(IMoniker)()
        self.source = moniker.RemoteBindToObject(null_context, null_moniker,
                                                 IBaseFilter._iid_)

        self.filter_graph.AddFilter(self.source, "VideoCapture")

        self.grabber = CreateObject(SampleGrabber)
        self.filter_graph.AddFilter(self.grabber, "Grabber")

        mt = tag_AMMediaType()
        mt.majortype = MEDIATYPE_Video
        mt.subtype = MEDIASUBTYPE_RGB24
        mt.formattype = FORMAT_VideoInfo

        self.grabber.SetMediaType(mt)

        self.graph_builder.RenderStream(
            PIN_CATEGORY_CAPTURE,
            MEDIATYPE_Video,
            self.source,
            self.grabber,
            None,
        )

        window = self.filter_graph.QueryInterface(IVideoWindow)
        window.AutoShow = [OA_FALSE, OA_TRUE][self.show_video_window]

        self.grabber.SetBufferSamples(True)
        self.grabber.SetOneShot(False)
        self.getImage = self.get_image
예제 #2
0
def get_video_devices():
    dev_enum = CreateObject(DeviceEnumerator)
    class_enum = dev_enum.CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
                                                0)
    fetched = True
    devices_info = {}
    index = 0
    while fetched:
        try:
            moniker, fetched = class_enum.RemoteNext(1)
            log("fetched=%s, moniker=%s", fetched, moniker)
            if fetched and moniker:
                info = get_device_information(moniker)
                devices_info[index] = info
                index += 1
        except ValueError:
            log("device %i not found", index)
            break
    return devices_info