OpenCV Read and Save ImageOpenCV Reading ImagesOpenCV allows us to perform multiple operations on the image, but to do that it is necessary to read an image file as input, and then we can perform the various operations on it. OpenCV provides following functions which are used to read and write the images. OpenCV imread functionThe imread() function loads image from the specified file and returns it. The syntax is: Parameters:filename: Name of the file to be loaded flag: The flag specifies the color type of a loaded image:
The imread() function returns a matrix, if the image cannot be read because of unsupported file format, missing file, unsupported or invalid format. Currently, the following file formats are supported. Window bitmaps - *.bmp, *.dib Note: The color images, the decoded images will have the channels stored in the BGR order.Let's consider the following example: Output: it will display the following image. OpenCV Save ImagesOpenCV imwrite() function is used to save an image to a specified file. The file extension defines the image format. The syntax is the following: Parameters:filename- Name of the file to be loaded image- Image to be saved. params- The following parameters are currently supported:
Let's consider the following example: Output: Image written to file-system : True If the imwrite() function returns the True, which means the file is successfully written in the specified file. Next TopicBasic Operation On images |