0% found this document useful (0 votes)
95 views5 pages

Practical - Computer Vision

Uploaded by

Abhiraj Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views5 pages

Practical - Computer Vision

Uploaded by

Abhiraj Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Class X (Artificial Intelligence)

Computer Vision – Practical

OpenCV
Step 1:
Upload file in session storage.
Step 2:
import cv2 # import OpenCV
from matplotlib import pyplot as plt # import pyplot

1 Program in python to view the image

img = cv2.imread('/content/man.jpg')
plt.imshow(img)
plt.title('man')
plt.axis('off')
plt.show()

Default colour mode – BGR


2 Program in python to convert BGR image to RGB image

img = cv2.imread('/content/man.jpg')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('man')
plt.axis('off')
plt.show()

3 Program in python to find shape of an image

img = cv2.imread('/content/man.jpg’)
print(plt.shape)
4 Program in python to find minimum and maximum value of a pixel.

img = cv2.imread('/content/man.jpg’)
print(plt.min())
print(plt.max())

5 Program in python load an image and focus on the man’s face.

img = cv2.imread('/content/man.jpg')
roi = img[10:100,130:210]
plt.imshow(cv2.cvtColor(roi,cv2.COLOR_BGR2RGB))
plt.show()
6 Program in python load an image and remove man’s face.

img = cv2.imread('/content/man.jpg')
img[10:100,130:210] = [255,255,255]
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.show()

7 Program in python load an image and change the man’s face.

img = cv2.imread('/content/man.jpg')
img[10:100,130:210] = img[110:200,130:210]
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.show()
8 Program in python load an image and resize it to 300 x 500 resolution.

• img = cv2.imread('/content/man.jpg')
• img2 = cv2.resize(img,(300,500))
• plt.imshow(cv2.cvtColor(img2,cv2.COLOR_BGR2RGB))
• plt.show()

9 Program in python load an image and resize it 4 times the original image.

img = cv2.imread('/content/man.jpg')
img2 = cv2.resize(img,(int(img.shape[1]*4),img.shape[0]*4))
plt.imshow(cv2.cvtColor(img2,cv2.COLOR_BGR2RGB))
plt.show()

You might also like