我问了一个类似的问题,但是对于使用numpy数组Opencv Python Crop Image Using Numpy Array的python来说。我正在寻找一个基于它的角落图像裁剪。这里展示的是一张照片。
我有Python代码,但需要转换成C++。下面是我的工作Python代码和部分C++代码。在
def crop(self,image):
grayed = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
(_,thresh) = cv2.threshold(grayed,1,255,cv2.THRESH_BINARY)
result, contours, _= cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
x, y = [], []
for i in range(len(contours)):
for j in range(len(contours[i])):
x.append(contours[i][j][0][0])
y.append(contours[i][j][0][1])
x1, x2, y1, y2 = min(x), max(x), min(y), max(y)
cropped = image[y1:y2, x1:x2]
return cropped
C++代码:
^{pr2}$
试试这个
}
相关问题 更多 >
编程相关推荐