DEV Community

Cover image for Reading, Displaying and Saving Images using OpenCv
es404020
es404020

Posted on

Reading, Displaying and Saving Images using OpenCv

  • OpenCv is an advance library used for image detection and manipulation .It was instrumental in the development the first self driving car.

In this tutorial we would explore some of the building block of image manipulation using the python OpenCv library.

Images are just numpy array with which has a given row and columns .Each row/columns contains a number ranging from o-255 for single channel and RGB for three channels .

A one channel image is called grayscale because it two colour are just black and white ranging for 0 to 255.

A three channel image is also called coloured image because it uses the RGB for colours meaning RED,GREEN,BLUE

  • Read image

`
import cv2
import numpy as np
import matplotlib.pyplot as plt

retval = cv2.imread('files/img_bw_18x18.png',cv2.IMREAD_GRAYSCALE)
print(retval)`

OpenCv image

OpenCv image

original Image

original Image

  • To save image


cv2.imwrite('new_mage.png',retval)

Thanks for reading

Top comments (0)