введите описание изображения здесь
Вот моя попытка
Код: Выделить всё
import cv2
import numpy as np
img = cv2.imread("image1.jpg")
(B, G, R) = cv2.split(img)
img = cv2.Canny(B, 20, 100) # Blue channel gives the best box so far
# img = cv2.Canny(R, 20, 100)
# img = cv2.Canny(R, 20, 100)
ret,thresh = cv2.threshold(img,20,100,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
M = cv2.moments(cnt)
for c in contours:
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
box = np.intp(box)
img = cv2.drawContours(img,[box],0,(0,0,255),2)
# display the image with bounding rectangle drawn on it
# cv2.namedWindow('Bounding Rectangle', cv2.WINDOW_KEEPRATIO)
cv2.imshow('Bounding Rectangle', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
введите здесь описание изображения
и я ожидаю изображение, которое представляет собой что-то вот так:
введите здесь описание изображения
Подробнее здесь: https://stackoverflow.com/questions/783 ... unding-box