Page 494 - AI Ver 3.0 class 10_Flipbook
P. 494

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


                    492     Touchpad Artificial Intelligence (Ver. 3.0)-X
   489   490   491   492   493   494   495   496   497   498   499