Practical - Computer Vision
Practical - Computer Vision
OpenCV
Step 1:
Upload file in session storage.
Step 2:
import cv2 # import OpenCV
from matplotlib import pyplot as plt # import pyplot
img = cv2.imread('/content/man.jpg')
plt.imshow(img)
plt.title('man')
plt.axis('off')
plt.show()
img = cv2.imread('/content/man.jpg')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('man')
plt.axis('off')
plt.show()
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())
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()
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()