list file extensions supported by OpenCV

前端 未结 3 1814

In OpenCV, I see imread() and VideoCapture() both take a string to a file path of multiple extensions. Is there a way to get a list of extensions that are supported by them?

相关标签:
3条回答
  • 2021-01-05 22:57

    Use the method cv::VideoCapture::isOpened() to make sure that the constructor was successful in initializing the VideoCapture object.

    Note that even if it was possible to get a list of supported container formats from OpenCV (AVI, MKV for instance) with their typical filename extensions, you would still need to know the exact list of supported codecs (and even then the exact file you want to open might be corrupted, etc...). So a list of filename extensions is not enough to accurately describe what is internally supported by OpenCV, and the simplest solution at the OpenCV API level is this isOpened() method.

    0 讨论(0)
  • 2021-01-05 23:03

    For imread() (more info here):

    • Windows bitmaps - *.bmp, *.dib (always supported)
    • JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
    • JPEG 2000 files - *.jp2 (see the Notes section)
    • Portable Network Graphics - *.png (see the Notes section)
    • Portable image format - *.pbm, *.pgm, *.ppm (always supported)
    • Sun rasters - *.sr, *.ras (always supported)
    • TIFF files - *.tiff, *.tif (see the Notes section)

    For VideoCapture():

    • AVI files - *.avi

      It seems that AVI is the only format with decent cross-platform support. See here for more info.

    0 讨论(0)
  • 2021-01-05 23:04

    Just update:

    cv::VideoCapture cap("D:\\test.mp4")
    

    works for me.

    0 讨论(0)
提交回复
热议问题