OpenCV functions use argument to modify their behavior. These arguments are integers which have special meaning, also called enums. These enums share the same integer space.
You can sometimes see this in the wild and in docs that people use nondescript numbers as options when calling a function (even without keywords) eg. cv2.putText(img, "yolo", (10, 20), 0, 1, (255, 255, 255), 1, 2)
.
Due to this it is possible to set the wrong option to the wrong funciton and OpenCV he no way to check for this (not that it does much checking).
For example the following example unexpectedly opens the image in grayscale mode because cv2.ROTATE_180
is int(0)
and that is interpreted in this function as cv2.IMREAD_GRAYSCALE
(sometimes the prefix of the option is not obvious):
img = cv2.imread('myimage.jpg', cv2.ROTATE_180)
(Sometimes, options can be combined by for more "fun" just like bitmasks - by adding them up)