Skip to content

Commit

Permalink
* Add for CvMat and IplImage, helper create(..., Pointer data)
Browse files Browse the repository at this point in the history
… factory methods that prevent premature deallocation (issue bytedeco/javacv#1101)
  • Loading branch information
saudet committed Dec 5, 2018
1 parent 26de6ef commit bc42822
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

* Include `ucrtbase.dll` when bundling the runtime for Visual Studio 2015 on Windows ([issue bytedeco/javacv#1098](https://github.com/bytedeco/javacv/issues/1098))
* Add support for N-dimensional arrays to `opencv_core.Mat.createIndexer()` ([pull #647](https://github.com/bytedeco/javacpp-presets/pull/647))
* Add a `PIX.create(..., Pointer data)` helper factory method that prevents premature deallocation ([issue bytedeco/javacpp#272](https://github.com/bytedeco/javacpp/issues/272))
* Add for `CvMat`, `IplImage`, and `PIX`, helper `create(..., Pointer data)` factory methods that prevent premature deallocation ([issue bytedeco/javacpp#272](https://github.com/bytedeco/javacpp/issues/272) and [issue bytedeco/javacv#1101](https://github.com/bytedeco/javacv/issues/1101))
* Enable x265 multilib depth support at 8, 10, and 12 bits for FFmpeg ([pull #619](https://github.com/bytedeco/javacpp-presets/pull/619))
* Include all header files from `Python.h` in presets for CPython
* Fix mapping of `initCameraMatrix2D`, `calibrateCamera`, and `stereoCalibrate` functions from `opencv_calib3d`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 Samuel Audet
* Copyright (C) 2014-2018 Samuel Audet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -338,6 +338,8 @@ public static class IplImageArray extends CvArrArray {
}

public static abstract class AbstractIplImage extends CvArr {
protected BytePointer pointer; // a reference to prevent deallocation

public AbstractIplImage(Pointer p) { super(p); }

/**
Expand Down Expand Up @@ -422,6 +424,16 @@ public static IplImage createHeader(int width, int height, int depth, int channe
return i;
}

/**
* Calls createHeader(), and initializes data, keeping a reference to prevent deallocation.
* @return IplImage created. Do not call cvReleaseImageHeader() on it.
*/
public static IplImage create(int width, int height, int depth, int channels, Pointer data) {
IplImage i = createHeader(width, height, depth, channels);
i.imageData(i.pointer = new BytePointer(data));
return i;
}

/**
* Creates an IplImage based on another IplImage.
* @return IplImage created. Do not call cvReleaseImage() on it.
Expand Down Expand Up @@ -499,6 +511,8 @@ public CvMat asCvMat() {
}

public static abstract class AbstractCvMat extends CvArr {
protected BytePointer pointer; // a reference to prevent deallocation

public AbstractCvMat(Pointer p) { super(p); }

/**
Expand Down Expand Up @@ -555,6 +569,16 @@ public static CvMat createHeader(int rows, int cols) {
return createHeader(rows, cols, CV_64F, 1);
}

/**
* Calls createHeader(), and initializes data, keeping a reference to prevent deallocation.
* @return CvMat created. Do not call cvReleaseMat() on it.
*/
public static CvMat create(int rows, int cols, int depth, int channels, Pointer data) {
CvMat m = createHeader(rows, cols, depth, channels);
m.data_ptr(m.pointer = new BytePointer(data));
return m;
}

public static ThreadLocal<CvMat> createThreadLocal(final int rows, final int cols, final int type) {
return new ThreadLocal<CvMat>() { @Override protected CvMat initialValue() {
return AbstractCvMat.create(rows, cols, type);
Expand Down

0 comments on commit bc42822

Please sign in to comment.