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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay