Page 309 - Ai_C10_Flipbook
P. 309
9. Write a program to read an image and display using Python library: import cv2, matplotlib
Upload an image of your favourite city in the world on the screen and give a proper title to it.
Ans. [1]: import cv2
from matplotlib import pyplot as plt
import numpy as np
img = cv2.imread('D:/london.jpg')
plt.imshow(img)
plt.title('My Favourite City')
plt.axis('off')
plt.show
My Favourite City
10. Write a program to read an image and identify its shape using Python.
Ans. [1]: import cv2
from matplotlib import pyplot as plt
import numpy as np
image = cv2.imread('D:/london.jpg')
height, width, channels = image.shape
print("Image shape:")
print("Height:", height)
print("Width:", width)
print("Number of channels:", channels)
Image shape:
Height: 245
Width: 1200
Number of channels: 3
11. Write a program to input a string and display the count of vowels and consonants in the string.
Ans. [1]: str = input("Please enter a string as you wish: ")
vowels = 0
consonants = 0
for i in str:
if i in 'aeiouAEIOU':
vowels += 1
else:
consonants += 1
print("The number of vowels:", vowels)
print("The number of consonants:", consonants)
Please enter a string as you wish: Orange Education
The number of vowels: 8
The number of consonants: 8
Python Practical Questions 307

