Drawing borders around an image using OpenCV

OpenCVPythonServer Side ProgrammingProgramming

In this program, we will draw borders around an image. We will use the copyMakeBorder() method in the openCV library. This function takes various parameters like image, top, bottom, left, right border values.

Original Image

Algorithm

Step 1: Import cv2.
Step 2: Read the image.
Step 3: Dall the cv2.copymakeborder() method.
Step 4: Display the output.

Example Code

import cv2

image = cv2.imread('testimage.jpg')
image = cv2.copyMakeBorder(image, 10,10,10,10, cv2.BORDER_CONSTANT)
cv2.imshow('Border', image)

Output

raja
Published on 17-Mar-2021 08:36:19
Advertisements