I current имеет ArrayList<MatOfPoint>
, который сохраняет контуры изображения и извлекает самый большой контур, который является моей целью для warpPerspective.OpenCV getPspectiveTransform and 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
здесь есть ссылка на источник: https://github.com/abidrahmank/OpenCV2-Python/blob/master/OpenCV_Python_Blog/sudoku_v_0.0.6/sudoku.py