Чтобы добавить белую рамку к изображению с помощью OpenCV, вы можете использовать различные методы. Вот несколько подходов, которые вы можете рассмотреть:
Метод 1: использование функции copyMakeBorder OpenCV
import cv2
import numpy as np
# Read the image
image = cv2.imread('your_image.jpg')
# Specify the border dimensions
top, bottom, left, right = 10, 10, 10, 10
# Add a white border
image_with_border = cv2.copyMakeBorder(image, top, bottom, left, right, cv2.BORDER_CONSTANT, value=[255, 255, 255])
# Display the image with the white border
cv2.imshow('Image with White Border', image_with_border)
cv2.waitKey(0)
cv2.destroyAllWindows()
Метод 2: использование функции панели Numpy
import cv2
import numpy as np
# Read the image
image = cv2.imread('your_image.jpg')
# Specify the border dimensions
top, bottom, left, right = 10, 10, 10, 10
# Add a white border
image_with_border = cv2.copyMakeBorder(image, top, bottom, left, right, cv2.BORDER_CONSTANT, value=[255, 255, 255])
# Display the image with the white border
cv2.imshow('Image with White Border', image_with_border)
cv2.waitKey(0)
cv2.destroyAllWindows()
Метод 3: использование функции прямоугольника OpenCV
import cv2
import numpy as np
# Read the image
image = cv2.imread('your_image.jpg')
# Get the image dimensions
height, width, _ = image.shape
# Specify the border dimensions
border_size = 10
# Create a new white image with the border dimensions
image_with_border = np.ones((height + 2 * border_size, width + 2 * border_size, 3), dtype=np.uint8) * 255
# Copy the original image to the center of the white image
image_with_border[border_size:border_size + height, border_size:border_size + width] = image
# Display the image with the white border
cv2.imshow('Image with White Border', image_with_border)
cv2.waitKey(0)
cv2.destroyAllWindows()