Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 169 - 2615_KEC
P. 169

    and rows are always written before columns.
                     Program 4: To crop an image from y = 150 to 350 and x = 200 to 400

                         Program4.py
                      File  Edit  Format   Run    Options   Window    Help

                      import cv2
                      image = cv2.imread("Flower.jpg")
                      # Crop from y = 150 to 350 and x = 200 to 400
                      cropped = image[150:350, 200:400]
                      cv2.imshow("Cropped Image", cropped)

                         Output

                     SHADING A PORTION OF AN IMAGE IN OPENCV
                     Shading a portion of an image in OpenCV means modifying the brightness of a selected area. A

                     specific region of the image is chosen using its row and column coordinates, and the pixel values
                     in that region are adjusted to make it darker or lighter. This allows effects to be applied to only
                     part of the image instead of the entire image.

                     Program 5: To darken a portion of image.

                         Program5.py
                      File  Edit  Format   Run    Options   Window    Help

                      import cv2
                      image = cv2.imread("Flower.jpg")
                      # Select region (y1:y2, x1:x2)
                      y1, y2 = 100, 300
                      x1, x2 = 150, 400
                      # Darken the region (reduce brightness)
                      image[y1:y2, x1:x2] = image[y1:y2, x1:x2] * 0.5
                      cv2.imshow("Shaded Image", image)

                                                                                                            OpenCV    167

| 164 165 166 167 168 169 170 171 172 173 174 |