public static Mat vector_Rect2d_to_Mat(List<Rect2d> rs) { Mat res; int count = (rs != null) ? rs.size() : 0; if (count > 0) { res = new Mat(count, 1, CvType.CV_64FC4); double[] buff = new double[4 * count]; for (int i = 0; i < count; i++) { Rect2d r = rs.get(i); buff[4 * i] = r.x; buff[4 * i + 1] = r.y; buff[4 * i + 2] = r.width; buff[4 * i + 3] = r.height; } res.put(0, 0, buff); } else { res = new Mat(); } return res; }
public static void Mat_to_vector_Rect2d(Mat m, List<Rect2d> rs) { if (rs == null) throw new java.lang.IllegalArgumentException("rs == null"); int count = m.rows(); if (CvType.CV_64FC4 != m.type() || m.cols() != 1) throw new java.lang.IllegalArgumentException( "CvType.CV_64FC4 != m.type() || m.rows()!=1\n" + m); rs.clear(); double[] buff = new double[4 * count]; m.get(0, 0, buff); for (int i = 0; i < count; i++) { rs.add(new Rect2d(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3])); } }