Does giving imread function a second parameter work on every image type?

img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

this is my code. Whatever the extension of image is, such a PNG, JPG or GIF, and regardless on whether the original image is grayscale or color image, does that code work well without errors in every cases?

  • the value of second parameter doesn’t need to be cv2.IMREAD_GRAYSCALE
  • I considered an original image as only image, not video or python file.
  • It’s my first question, so probably i did something wrong.

yes, it does.
(why would you think, it’s not so ?)

((and, btw, the default (if you omit the flag) is IMREAD_COLOR, which will convert any image to 3 channels, whether it was so, originally, or not))

not supported, still a patent issue

1 Like

if you encounter GIF files, read them with VideoCapture.

1 Like

I was just wondering if it would work in these cases:

  • The given image is already grayscle.
  • The given image extension is so unique and so different to handle that it is processed different way in cv2 library. Therefore it won’t allow to give a second parameter.
  • Or Some else cases i missed.

Anyway, thank you for your precious comment!