Opencv Python Crop Image Using Numpy Array

谁说胖子不能爱 提交于 2019-12-05 14:12:45

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!