All CV applications need to get images as input. Most also need to produce images as output. An interactive CV application might require a camera as an input source and a window as a output destination. However, other possible sources and destinations include image files, video files, and raw bytes. For example, raw bytes might be received/sent via a network connection or might be generated by an algorithm if we are incorporating procedural graphics into our application. Let's look at each of these possibilities.
OpenCV provides the
imread()
and imwrite()
functions that support various file formats for still images. The supported formats vary by system but should always include the BMP format. Typically, PNG, JPEG, and TIFF should be among the supported formats too. Images can
be loaded from one file format and saved to another. For example, let's convert an image from PNG to JPEG:
import cv2 image = cv2.imread('MyPic.png') cv2.imwrite('MyPic...