Мне нужно обнаружить черную рамку на изображении. Я пытался обнаружить их с помощью OpenCV, но результаты оказались неудовлетворительными.
Код здесь:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.filters import threshold_local
image = cv2.imread("image.jpg")
V = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2HSV))[2]
T = threshold_local(V, 15, offset=5, method="gaussian")
thresh = (V > T).astype("uint8") * 255
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(image, contours, -1, (0, 255, 0), 2)
plt.imshow(thresh, cmap='gray')
введите здесь описание изображения
Другой код:
def find_threshold_img(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# # apply thresholding to convert grayscale to binary image
# ret,thresh = cv2.threshold(gray,100,200,0)
thresh = cv2.threshold(gray, 0, 30, cv2.THRESH_BINARY|cv2.THRESH_OTSU)[1]
return thresh
thresh = find_threshold_img(image)
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(image, contours, -1, (0, 255, 0), 2)
plt.imshow(image, cmap='gray')
Подробнее здесь: https://stackoverflow.com/questions/789 ... his-border
Как определить черную рамку фотографии и удалить эту рамку? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение