我現在有一個ArrayList<MatOfPoint>
存儲圖像的輪廓,並取回這是我的目標warpPerspective最大的輪廓。OpenCV的getPerspectiveTransform和warpPerspective的Java
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(matOut, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
sort(contours);
MatOfPoint2f m2f = MatOfPoint2f(contours.get(0).toArray());
double arc = Imgproc.arcLength(m2f, true);
MatOfPoint2f approx = new MatOfPoint2f();
Imgproc.approxPolyDP(m2f, approx, arc*0.02, true);
我有關於如何使用getPerspectiveTransform麻煩,然後應用warpPerspective改變形象,使其一個450x450的圖像內適應。
我發現這個在python的相當不錯的例子,但我不是很熟悉的話可以有人解釋我怎麼會在java中不糾正?
def rectify(h):
''' this function put vertices of square we got, in clockwise order '''
h = h.reshape((4,2))
hnew = np.zeros((4,2),dtype = np.float32)
add = h.sum(1)
hnew[0] = h[np.argmin(add)]
hnew[2] = h[np.argmax(add)]
diff = np.diff(h,axis = 1)
hnew[1] = h[np.argmin(diff)]
hnew[3] = h[np.argmax(diff)]
return hnew