andreaschiavinato / python_grabber

Python tool to capture photo from camera and for doing simple image processing using DirectShow and OpenCV
MIT License
57 stars 27 forks source link

Add "get_current_format_index" function #6

Open Toussaic opened 4 years ago

Toussaic commented 4 years ago

Hi,

I modified "get_current_format" and added "get_current_format_index" to allow to know which is the current format listed with "get_formats".

Maybe, there should be a wrapper in FilterGraph to those functions instead of calling get_input_device each time.

```
def get_current_format(self):
    stream_config = self.get_out().QueryInterface(IAMStreamConfig)
    media_type = stream_config.GetFormat()
    p_video_info_header = cast(media_type.contents.pbFormat, POINTER(VIDEOINFOHEADER))
    bmp_header = p_video_info_header.contents.bmi_header
    return subtypes[str(media_type.contents.subtype)], bmp_header.biWidth, bmp_header.biHeight

def get_current_format_index(self):
    formats = self.get_formats()
    media_type, width, height = self.get_current_format()

    for i, cformat in enumerate(formats):
        if ((cformat["height"] == height) and
                (cformat["width"] == width) and
                (cformat["media_type_str"] == media_type)):
            return i
andreaschiavinato commented 4 years ago

Thank for reporting the issue. In this period I have a limited time where I can work on this, if you want to do the modification yourself and create a pull request you are welcome :-) Otherwise I'll look at the pending issues on the next weeks.