Read image grayscale opencv 3.0.0-dev

elaRosca picture elaRosca · Apr 28, 2014 · Viewed 67.4k times · Source

I am trying to read images directly as black and white.

I recently updated my OpenCv version to 3.0.0-dev, and the code that I used before does not work anymore.

   img = cv2.imread(f, cv2.CV_LOAD_IMAGE_GRAYSCALE)

works fine for 2.4 but does not work for the new version, as there is no field CV_LOAD_IMAGE_GRAYSCALE.

Any suggestions?

Note: I know that cv2.imread(f,0) will work, but I do not like having unnamed constants in my code. Thanks!

Answer

Aurelius picture Aurelius · Apr 28, 2014

The flag has been renamed to cv2.IMREAD_GRAYSCALE. Generally speaking, flags now have names prefixed in a manner that relates to the function to which they refer. (e.g. imread flags start with IMREAD_, cvtColor flags start with COLOR_, etc.)