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

In OpenCV we first need to draw a bounding box around a certain area known as ‘region of interest (ROI)’. After
                 this we will extract the image of that ROI only which will help us to create a cropped image.

                 roi = img[135:365,115:350] #img[range of y, range of x]
                    • Let us now try this in getting the face of the dog:

                    [1]:  import cv2 # import OpenCV
                          from matplotlib import pyplot as plt # import matplotlib
                          import numpy as np # import numpy
                          img = cv2.imread('D:/Flower.jpg')
                          roi =img[135:365,115:350] #img[range of y, range of x]
                          plt.imshow(cv2.cvtColor(roi, cv2.COLOR_BGR2RGB))
                          plt.title('Flower') #Display this title on the top of the image
                          plt.axis('off')
                          plt.show()




















                 Shading a Portion of an Image

                 The pixel value of the image can be changed to shade the image, make it black or white to hide some portion
                 of the image.

                 img[200:270,200:275]=[0,0,0] #make black shade in given range
                 plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))#display image with given shade

                    [1]:  import cv2 # import OpenCV
                          from matplotlib import pyplot as plt # import matplotlib
                          import numpy as np # import numpy
                          img = cv2.imread('D:/Flower.jpg')
                          img[200:270,200:275]=[0,0,0] #make black shade in given range
                          plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))#display image with given shade
                          plt.title('Flower') #Display this title on the top of the image
                          plt.axis('off')
                          plt.show()


















                                                                                    Advance Python (Practical)  475
   472   473   474   475   476   477   478   479   480   481   482