diff --git a/CHANGELOG.md b/CHANGELOG.md index a7308fcbfe5..d15af25a5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Add new array constructors to `opencv_core.Mat` that copy data for convenience ([pull #1002](https://github.com/bytedeco/javacpp-presets/pull/1002)) * Rebase `PrimitiveScalar` on `PrimitiveScalarBase` in presets for Arrow for easy access to `data()` ([issue #998](https://github.com/bytedeco/javacpp-presets/issues/998)) * Add `NamedMetadataOperations.h` implementing data retrieval operations for LLVM nodes ([pull #995](https://github.com/bytedeco/javacpp-presets/pull/995)) * Enable OpenMP for ONNX Runtime on Mac once again ([issue #917](https://github.com/bytedeco/javacpp-presets/issues/917)) diff --git a/opencv/src/gen/java/org/bytedeco/opencv/opencv_core/Mat.java b/opencv/src/gen/java/org/bytedeco/opencv/opencv_core/Mat.java index 89a6855008c..8203d1cfb87 100644 --- a/opencv/src/gen/java/org/bytedeco/opencv/opencv_core/Mat.java +++ b/opencv/src/gen/java/org/bytedeco/opencv/opencv_core/Mat.java @@ -220,7 +220,7 @@ public class Mat extends AbstractMat { return (Mat)super.position(position); } @Override public Mat getPointer(long i) { - return new Mat(this).position(position + i); + return new Mat((Pointer)this).position(position + i); } /** @@ -358,31 +358,52 @@ the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no public Mat(int rows, int cols, int type, Pointer data, @Cast("size_t") long step/*=AUTO_STEP*/) { super((Pointer)null); allocate(rows, cols, type, data, step); this.pointer = data; } private native void allocate(int rows, int cols, int type, Pointer data, @Cast("size_t") long step/*=AUTO_STEP*/); private Pointer pointer; // a reference to prevent deallocation + /** Calls {@link #Mat(int, int, int, Pointer, long) Mat(rows, cols, type, data, AUTO_STEP)} as with {@link #Mat(int, int, int, Pointer, boolean) Mat(rows, cols, type, data, false)}. */ public Mat(int rows, int cols, int type, Pointer data) { this(rows, cols, type, data, AUTO_STEP); } public Mat(CvArr arr) { super(cvarrToMat(arr)); this.pointer = arr; } - public Mat(Point points) { this(1, Math.max(1, points.limit() - points.position()), CV_32SC2, points); this.pointer = points; } - public Mat(Point2f points) { this(1, Math.max(1, points.limit() - points.position()), CV_32FC2, points); this.pointer = points; } - public Mat(Point2d points) { this(1, Math.max(1, points.limit() - points.position()), CV_64FC2, points); this.pointer = points; } - public Mat(Point3i points) { this(1, Math.max(1, points.limit() - points.position()), CV_32SC3, points); this.pointer = points; } - public Mat(Point3f points) { this(1, Math.max(1, points.limit() - points.position()), CV_32FC3, points); this.pointer = points; } - public Mat(Point3d points) { this(1, Math.max(1, points.limit() - points.position()), CV_64FC3, points); this.pointer = points; } - public Mat(Scalar scalar) { this(1, Math.max(1, scalar.limit() - scalar.position()), CV_64FC4, scalar); this.pointer = scalar; } - public Mat(Scalar4i scalar) { this(1, Math.max(1, scalar.limit() - scalar.position()), CV_32SC4, scalar); this.pointer = scalar; } + /** Warning: If {@code copyData} is false, the data of the OpenCV Mat returned by this constructor is externally allocated from OpenCV point of view, + * and will not benefit from OpenCV reference counting feature. One must ensure that the data does not get implicitly or explicitly deallocated when + * another Mat has been created pointing to the same data with, e.g., reshape(), rowRange(), etc... */ + public Mat(int rows, int cols, int type, Pointer data, boolean copyData) { super((Pointer)null); + if (copyData) { allocate(rows, cols, type); data().put(data); } else { allocate(rows, cols, type, data, AUTO_STEP); this.pointer = data; } + } + /** Calls {@link #Mat(int, int, int, Pointer, boolean) Mat(1, (int)Math.min(data.limit() - data.position(), Integer.MAX_VALUE), type, data, copyData)}. */ + public Mat(int type, Pointer data, boolean copyData) { this(1, (int)Math.min(data.limit() - data.position(), Integer.MAX_VALUE), type, data, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC2, points, copyData)}. */ public Mat(Point points, boolean copyData) { this(CV_32SC2, points, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32FC2, points, copyData)}. */ public Mat(Point2f points, boolean copyData) { this(CV_32FC2, points, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC2, points, copyData)}. */ public Mat(Point2d points, boolean copyData) { this(CV_64FC2, points, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC3, points, copyData)}. */ public Mat(Point3i points, boolean copyData) { this(CV_32SC3, points, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32FC3, points, copyData)}. */ public Mat(Point3f points, boolean copyData) { this(CV_32FC3, points, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC3, points, copyData)}. */ public Mat(Point3d points, boolean copyData) { this(CV_64FC3, points, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC4, scalar, copyData)}. */ public Mat(Scalar scalar, boolean copyData) { this(CV_64FC4, scalar, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC4, scalar, copyData)}. */ public Mat(Scalar4i scalar, boolean copyData) { this(CV_32SC4, scalar, copyData); } + /** Calls {@link #Mat(Point, boolean) Mat(points, false)}. */ public Mat(Point points) { this(points, false); } + /** Calls {@link #Mat(Point2f, boolean) Mat(points, false)}. */ public Mat(Point2f points) { this(points, false); } + /** Calls {@link #Mat(Point2d, boolean) Mat(points, false)}. */ public Mat(Point2d points) { this(points, false); } + /** Calls {@link #Mat(Point3i, boolean) Mat(points, false)}. */ public Mat(Point3i points) { this(points, false); } + /** Calls {@link #Mat(Point3f, boolean) Mat(points, false)}. */ public Mat(Point3f points) { this(points, false); } + /** Calls {@link #Mat(Point3d, boolean) Mat(points, false)}. */ public Mat(Point3d points) { this(points, false); } + /** Calls {@link #Mat(Scalar, boolean) Mat(scalar, false)}. */ public Mat(Scalar scalar) { this(scalar, false); } + /** Calls {@link #Mat(Scalar4i, boolean) Mat(scalar, false)}. */ public Mat(Scalar4i scalar) { this(scalar, false); } public Mat(byte ... b) { this(b, false); } - public Mat(byte[] b, boolean signed) { this(new BytePointer(b), signed); } - public Mat(short ... s) { this(s, true); } - public Mat(short[] s, boolean signed) { this(new ShortPointer(s), signed); } - public Mat(int ... n) { this(new IntPointer(n)); } - public Mat(double ... d) { this(new DoublePointer(d)); } - public Mat(float ... f) { this(new FloatPointer(f)); } - private Mat(long rows, long cols, int type, Pointer data) { this((int)Math.min(rows, Integer.MAX_VALUE), (int)Math.min(cols, Integer.MAX_VALUE), type, data, AUTO_STEP); } - public Mat(BytePointer p) { this(p, false); } - public Mat(BytePointer p, boolean signed) { this(1, Math.max(1, p.limit() - p.position()), signed ? CV_8SC1 : CV_8UC1, p); } - public Mat(ShortPointer p) { this(p, false); } - public Mat(ShortPointer p, boolean signed) { this(1, Math.max(1, p.limit() - p.position()), signed ? CV_16SC1 : CV_16UC1, p); } - public Mat(IntPointer p) { this(1, Math.max(1, p.limit() - p.position()), CV_32SC1, p); } - public Mat(FloatPointer p) { this(1, Math.max(1, p.limit() - p.position()), CV_32FC1, p); } - public Mat(DoublePointer p) { this(1, Math.max(1, p.limit() - p.position()), CV_64FC1, p); } + public Mat(short ... s) { this(s, false); } + public Mat(byte[] b, boolean signed) { this(1, b.length, signed ? CV_8SC1 : CV_8UC1); data().put(b); } + public Mat(short[] s, boolean signed) { this(1, s.length, signed ? CV_16SC1 : CV_16UC1); new ShortPointer(data()).put(s); } + public Mat(int ... n) { this(1, n.length, CV_32SC1); new IntPointer(data()).put(n); } + public Mat(double ... d) { this(1, d.length, CV_64FC1); new DoublePointer(data()).put(d); } + public Mat(float ... f) { this(1, f.length, CV_32FC1); new FloatPointer(data()).put(f); } + /** Calls {@link #Mat(BytePointer, boolean) Mat(p, false)}. */ public Mat(BytePointer p) { this(p, false); } + /** Calls {@link #Mat(ShortPointer, boolean) Mat(p, false)}. */ public Mat(ShortPointer p) { this(p, false); } + /** Calls {@link #Mat(BytePointer, boolean, boolean) Mat(p, signed, false)}. */ public Mat(BytePointer p, boolean signed) { this(p, signed, false); } + /** Calls {@link #Mat(ShortPointer, boolean, boolean) Mat(p, signed, false)}. */ public Mat(ShortPointer p, boolean signed) { this(p, signed, false); } + /** Calls {@link #Mat(IntPointer, boolean) Mat(p, false)}. */ public Mat(IntPointer p) { this(p, false); } + /** Calls {@link #Mat(FloatPointer, boolean) Mat(p, false)}. */ public Mat(FloatPointer p) { this(p, false); } + /** Calls {@link #Mat(DoublePointer, boolean) Mat(p, false)}. */ public Mat(DoublePointer p) { this(p, false); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(signed ? CV_8SC1 : CV_8UC1, p, copyData)}. */ public Mat(BytePointer p, boolean signed, boolean copyData) { this(signed ? CV_8SC1 : CV_8UC1, p, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(signed ? CV_16SC1 : CV_16UC1, p, copyData)}. */ public Mat(ShortPointer p, boolean signed, boolean copyData) { this(signed ? CV_16SC1 : CV_16UC1, p, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC1, p, copyData)}. */ public Mat(IntPointer p, boolean copyData) { this(CV_32SC1, p, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32FC1, p, copyData)}. */ public Mat(FloatPointer p, boolean copyData) { this(CV_32FC1, p, copyData); } + /** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC1, p, copyData)}. */ public Mat(DoublePointer p, boolean copyData) { this(CV_64FC1, p, copyData); } /** \overload @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the diff --git a/opencv/src/main/java/org/bytedeco/opencv/presets/opencv_core.java b/opencv/src/main/java/org/bytedeco/opencv/presets/opencv_core.java index ca855e3f7f1..c6b4b73078d 100644 --- a/opencv/src/main/java/org/bytedeco/opencv/presets/opencv_core.java +++ b/opencv/src/main/java/org/bytedeco/opencv/presets/opencv_core.java @@ -280,31 +280,56 @@ public void map(InfoMap infoMap) { "public Mat(int rows, int cols, int type, Pointer data, @Cast(\"size_t\") long step/*=AUTO_STEP*/) { super((Pointer)null); allocate(rows, cols, type, data, step); this.pointer = data; }\n" + "private native void allocate(int rows, int cols, int type, Pointer data, @Cast(\"size_t\") long step/*=AUTO_STEP*/);\n" + "private Pointer pointer; // a reference to prevent deallocation\n" + + "/** Calls {@link #Mat(int, int, int, Pointer, long) Mat(rows, cols, type, data, AUTO_STEP)} as with {@link #Mat(int, int, int, Pointer, boolean) Mat(rows, cols, type, data, false)}. */\n" + "public Mat(int rows, int cols, int type, Pointer data) { this(rows, cols, type, data, AUTO_STEP); }\n" + + "public Mat(CvArr arr) { super(cvarrToMat(arr)); this.pointer = arr; }\n" - + "public Mat(Point points) { this(1, Math.max(1, points.limit() - points.position()), CV_32SC2, points); this.pointer = points; }\n" - + "public Mat(Point2f points) { this(1, Math.max(1, points.limit() - points.position()), CV_32FC2, points); this.pointer = points; }\n" - + "public Mat(Point2d points) { this(1, Math.max(1, points.limit() - points.position()), CV_64FC2, points); this.pointer = points; }\n" - + "public Mat(Point3i points) { this(1, Math.max(1, points.limit() - points.position()), CV_32SC3, points); this.pointer = points; }\n" - + "public Mat(Point3f points) { this(1, Math.max(1, points.limit() - points.position()), CV_32FC3, points); this.pointer = points; }\n" - + "public Mat(Point3d points) { this(1, Math.max(1, points.limit() - points.position()), CV_64FC3, points); this.pointer = points; }\n" - + "public Mat(Scalar scalar) { this(1, Math.max(1, scalar.limit() - scalar.position()), CV_64FC4, scalar); this.pointer = scalar; }\n" - + "public Mat(Scalar4i scalar) { this(1, Math.max(1, scalar.limit() - scalar.position()), CV_32SC4, scalar); this.pointer = scalar; }\n" + + "/** Warning: If {@code copyData} is false, the data of the OpenCV Mat returned by this constructor is externally allocated from OpenCV point of view,\n" + + " * and will not benefit from OpenCV reference counting feature. One must ensure that the data does not get implicitly or explicitly deallocated when\n" + + " * another Mat has been created pointing to the same data with, e.g., reshape(), rowRange(), etc... */\n" + + "public Mat(int rows, int cols, int type, Pointer data, boolean copyData) { super((Pointer)null);\n" + + " if (copyData) { allocate(rows, cols, type); data().put(data); } else { allocate(rows, cols, type, data, AUTO_STEP); this.pointer = data; }\n" + + "}\n" + + "/** Calls {@link #Mat(int, int, int, Pointer, boolean) Mat(1, (int)Math.min(data.limit() - data.position(), Integer.MAX_VALUE), type, data, copyData)}. */\n" + + "public Mat(int type, Pointer data, boolean copyData) { this(1, (int)Math.min(data.limit() - data.position(), Integer.MAX_VALUE), type, data, copyData); }\n" + + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC2, points, copyData)}. */ public Mat(Point points, boolean copyData) { this(CV_32SC2, points, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32FC2, points, copyData)}. */ public Mat(Point2f points, boolean copyData) { this(CV_32FC2, points, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC2, points, copyData)}. */ public Mat(Point2d points, boolean copyData) { this(CV_64FC2, points, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC3, points, copyData)}. */ public Mat(Point3i points, boolean copyData) { this(CV_32SC3, points, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32FC3, points, copyData)}. */ public Mat(Point3f points, boolean copyData) { this(CV_32FC3, points, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC3, points, copyData)}. */ public Mat(Point3d points, boolean copyData) { this(CV_64FC3, points, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC4, scalar, copyData)}. */ public Mat(Scalar scalar, boolean copyData) { this(CV_64FC4, scalar, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC4, scalar, copyData)}. */ public Mat(Scalar4i scalar, boolean copyData) { this(CV_32SC4, scalar, copyData); }\n" + + "/** Calls {@link #Mat(Point, boolean) Mat(points, false)}. */ public Mat(Point points) { this(points, false); }\n" + + "/** Calls {@link #Mat(Point2f, boolean) Mat(points, false)}. */ public Mat(Point2f points) { this(points, false); }\n" + + "/** Calls {@link #Mat(Point2d, boolean) Mat(points, false)}. */ public Mat(Point2d points) { this(points, false); }\n" + + "/** Calls {@link #Mat(Point3i, boolean) Mat(points, false)}. */ public Mat(Point3i points) { this(points, false); }\n" + + "/** Calls {@link #Mat(Point3f, boolean) Mat(points, false)}. */ public Mat(Point3f points) { this(points, false); }\n" + + "/** Calls {@link #Mat(Point3d, boolean) Mat(points, false)}. */ public Mat(Point3d points) { this(points, false); }\n" + + "/** Calls {@link #Mat(Scalar, boolean) Mat(scalar, false)}. */ public Mat(Scalar scalar) { this(scalar, false); }\n" + + "/** Calls {@link #Mat(Scalar4i, boolean) Mat(scalar, false)}. */ public Mat(Scalar4i scalar) { this(scalar, false); }\n" + + "public Mat(byte ... b) { this(b, false); }\n" - + "public Mat(byte[] b, boolean signed) { this(new BytePointer(b), signed); }\n" - + "public Mat(short ... s) { this(s, true); }\n" - + "public Mat(short[] s, boolean signed) { this(new ShortPointer(s), signed); }\n" - + "public Mat(int ... n) { this(new IntPointer(n)); }\n" - + "public Mat(double ... d) { this(new DoublePointer(d)); }\n" - + "public Mat(float ... f) { this(new FloatPointer(f)); }\n" - + "private Mat(long rows, long cols, int type, Pointer data) { this((int)Math.min(rows, Integer.MAX_VALUE), (int)Math.min(cols, Integer.MAX_VALUE), type, data, AUTO_STEP); }\n" - + "public Mat(BytePointer p) { this(p, false); }\n" - + "public Mat(BytePointer p, boolean signed) { this(1, Math.max(1, p.limit() - p.position()), signed ? CV_8SC1 : CV_8UC1, p); }\n" - + "public Mat(ShortPointer p) { this(p, false); }\n" - + "public Mat(ShortPointer p, boolean signed) { this(1, Math.max(1, p.limit() - p.position()), signed ? CV_16SC1 : CV_16UC1, p); }\n" - + "public Mat(IntPointer p) { this(1, Math.max(1, p.limit() - p.position()), CV_32SC1, p); }\n" - + "public Mat(FloatPointer p) { this(1, Math.max(1, p.limit() - p.position()), CV_32FC1, p); }\n" - + "public Mat(DoublePointer p) { this(1, Math.max(1, p.limit() - p.position()), CV_64FC1, p); }\n")) + + "public Mat(short ... s) { this(s, false); }\n" + + "public Mat(byte[] b, boolean signed) { this(1, b.length, signed ? CV_8SC1 : CV_8UC1); data().put(b); }\n" + + "public Mat(short[] s, boolean signed) { this(1, s.length, signed ? CV_16SC1 : CV_16UC1); new ShortPointer(data()).put(s); }\n" + + "public Mat(int ... n) { this(1, n.length, CV_32SC1); new IntPointer(data()).put(n); }\n" + + "public Mat(double ... d) { this(1, d.length, CV_64FC1); new DoublePointer(data()).put(d); }\n" + + "public Mat(float ... f) { this(1, f.length, CV_32FC1); new FloatPointer(data()).put(f); }\n" + + "/** Calls {@link #Mat(BytePointer, boolean) Mat(p, false)}. */ public Mat(BytePointer p) { this(p, false); }\n" + + "/** Calls {@link #Mat(ShortPointer, boolean) Mat(p, false)}. */ public Mat(ShortPointer p) { this(p, false); }\n" + + "/** Calls {@link #Mat(BytePointer, boolean, boolean) Mat(p, signed, false)}. */ public Mat(BytePointer p, boolean signed) { this(p, signed, false); }\n" + + "/** Calls {@link #Mat(ShortPointer, boolean, boolean) Mat(p, signed, false)}. */ public Mat(ShortPointer p, boolean signed) { this(p, signed, false); }\n" + + "/** Calls {@link #Mat(IntPointer, boolean) Mat(p, false)}. */ public Mat(IntPointer p) { this(p, false); }\n" + + "/** Calls {@link #Mat(FloatPointer, boolean) Mat(p, false)}. */ public Mat(FloatPointer p) { this(p, false); }\n" + + "/** Calls {@link #Mat(DoublePointer, boolean) Mat(p, false)}. */ public Mat(DoublePointer p) { this(p, false); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(signed ? CV_8SC1 : CV_8UC1, p, copyData)}. */ public Mat(BytePointer p, boolean signed, boolean copyData) { this(signed ? CV_8SC1 : CV_8UC1, p, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(signed ? CV_16SC1 : CV_16UC1, p, copyData)}. */ public Mat(ShortPointer p, boolean signed, boolean copyData) { this(signed ? CV_16SC1 : CV_16UC1, p, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32SC1, p, copyData)}. */ public Mat(IntPointer p, boolean copyData) { this(CV_32SC1, p, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_32FC1, p, copyData)}. */ public Mat(FloatPointer p, boolean copyData) { this(CV_32FC1, p, copyData); }\n" + + "/** Calls {@link #Mat(int, Pointer, boolean) Mat(CV_64FC1, p, copyData)}. */ public Mat(DoublePointer p, boolean copyData) { this(CV_64FC1, p, copyData); }\n")) + .put(new Info("cv::Mat::zeros(int, int*, int)", "cv::Mat::ones(int, int*, int)").skip()) .put(new Info("cv::Mat::size").javaText("public native @ByVal Size size();\n@MemberGetter public native int size(int i);")) .put(new Info("cv::Mat::step").javaText("@MemberGetter public native long step();\n@MemberGetter public native long step(int i);"))