Lec 3
Lec 3
Lecture 3
OpencV Library Installation
• Pip install open-python
Topic Cover
• What is imread function in OpenCV?
• What is imshow function in OpenCV?
• What is Gray scale image and BGR image?
• Save image using imwrite fucntion
OVERVIEW
• OpenCV Python Tutorial For Beginners:
• To Read, Write, Show Images in OpenCV.
• we will se how to use cv2.imread('lena.jpg', -1) to read
and image,
• cv2.imshow('image', img) to show an image in a
window,
• cv2.waitKey(0) to wait for a key event,
• cv2.destroyAllWindows() to destroy all windows,
• cv2.imwrite('imagename.png', img) to write images to
file.
Read Image
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ")
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
Functions for Images
• IMAGE READ
• WRITE
&
• SHOW
Resize the Image
• import cv2 #openCV use as cv2 in python
• img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ")
• img1 = cv2 .resize(img1,(640,350))#width, height
• cv2.imshow("Original", img1)
• cv2.waitKey()
• cv2.destroyAllWindows()
Print(img1)
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ")
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
Imread(location, number)
• function accpets only two parameters
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",1)
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.waitKey()
import cv2 #openCV use as cv2 in python
img1 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",1)
img1 = cv2 .resize(img1,(640,350))#width,
height
print(img1)
cv2.imshow("Original", img1)
cv2.destroyAllWindows()
#cv2.IMREAD_GRAYSCALE : Loads Image in
grayscale
img2 = cv2.imread("F:\\First Semester 2024\\
Computer Vision\\Aahil.jpg ",0)
img2 = cv2 .resize(img2,(1280,700))#width,
height
cv2.imshow("Image in gray scale ", img2)
print("Image in gray scale ==\n")
cv2.destroyAllWindows()
cv2.waitKey(3000)
Three Vs Single Channels
• runfile('C:/Users/S.TECH/untitled0.py', wdir='C:/Users/S.TECH')
• [[[243 245 239]
• [243 245 240]
• [243 244 239]
• ...
• [192 195 199]
• [192 195 199]
• [192 195 199]]
• ...