I am using OpenCV 3.1.0-dev and python 2.7.
I am trying to crop out the black exterior of an image I have stitched. The struggle is that there are other pixels in t
Once you have the contours
, you can do a list of the x
and the y
of them and then find the maximum and minimum:
x, y = [], []
for contour_line in contours:
for contour in contour_line:
x.append(contour[0][0])
y.append(contour[0][1])
x1, x2, y1, y2 = min(x), max(x), min(y), max(y)
cropped = img[y1:y2, x1:x2]
The (x1, y1)
would be the top left corner and the (x2, y2)
the bottom right.
Hope this helped!