Changing Colorspaces
lastmod 2026-11-10created 2023-01-103 edits
Changing Colorspaces is an official OpenCV tutorial on converting the color space of an image. It converts BGR images to grayscale or HSV by passing flags such as COLOR_BGR2GRAY and COLOR_BGR2HSV to the cv2.cvtColor function; a typical example converts to HSV and then uses cv2.inRange to extract only objects within a specific color range. Note that OpenCV uses BGR order by default rather than RGB.