opencv — read,write,& show an image in 5 lines of code

Powerful learning
1 min readJul 4, 2022

--

hello all,

I am a Youtuber . Channel name = Powerful learning — click here

Opencv is a python library mainly used in artificial intelligence domain. It is used to deal with images and video. I have explained a very easy yet important basic concepts of opencv function in my video. To watch the process click here.

I didn’t download any python IDLE in my laptop. Instead I used google colaboratory to run python function. You need internet to run your code on this platform.

here is the code to read, write and show an image

import cv2

#importing opencv library

from google.colab.patches import cv2_imshow

#since google colab doesnt support cv2.imshow() function you have to import its own cv2_imshow() package

image = cv2.imread(“powerful learning (5).png”)

#upload an sample image in colab. I have uploaded an image name “powerful learning (5).png”.

#image variable just read the image which I uploaded in google colab.

cv2.imwrite(‘PL.png’,image)

#imwrite function is used to copy and save the existing image. Here I renamed my uploaded image as PL.png

cv2_imshow(image)

#since google colab doesnt support cv2.imshow(), type cv2_imshow()

Thanks for reading.

--

--

Powerful learning

Mini blog on Free certifications, internships and webinars