Package edu.wpi.grip.core
Class MatWrapper
- java.lang.Object
-
- edu.wpi.grip.core.MatWrapper
-
public final class MatWrapper extends java.lang.ObjectWraps a GPU mat and a CPU mat and allows device memory and host memory to be used semi-transparently. A wrapper may change between wrapping an image in host memory or an image in GPU memory. A wrapper is used to minimize copies between host and device memory, which may take longer than the time savings of using a CUDA-accelerated operation.Data is lazily copied between host and device memory when needed. Wrappers that are only accessed from CPU operations will never have their data stored in device memory. Accessing a wrapper from CUDA land with
getGpu()will first copy the existing data from host memory to device, if the wrapper was most recently accessed from CPU code (from eithergetCpu()orrawCpu()). This behavior also applies in the reverse, for wrappers accessed from CPU land when they have been most recently used from CUDA code.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intchannels()Gets the number of color channels in this image.intcols()Gets the number of columns in this image.voidcopyTo(MatWrapper wrapper)Copies the data of this wrapper into another.voidcopyTo(org.bytedeco.javacpp.opencv_core.GpuMat mat)Copies the data of this wrapper to a mat in GPU memory.voidcopyTo(org.bytedeco.javacpp.opencv_core.Mat mat)Copies the data of this wrapper to a mat in host memory.voidcreate(int rows, int cols, int type)Allocates new array data if needed.intdepth()Gets the channel depth of this image.booleanempty()Checks if this image is empty.static MatWrapperemptyWrapper()Creates an empty wrapper.org.bytedeco.javacpp.opencv_core.MatgetCpu()Gets this mat as a mat in host memory.org.bytedeco.javacpp.opencv_core.GpuMatgetGpu()Gets this mat as a mat in GPU memory.doublehighValue()Gets the maximum possible value able to be held as a single element in this image.booleanisCpu()Checks if this is a wrapper around a CPU mat.booleanisGpu()Checks if this is a wrapper around a GPU mat.MatWrapperput(org.bytedeco.javacpp.opencv_core.Scalar value)Sets all or some of the array elements to the specified value.org.bytedeco.javacpp.opencv_core.MatrawCpu()Gets the raw CPU mat.org.bytedeco.javacpp.opencv_core.GpuMatrawGpu()Gets the raw GPU mat.introws()Gets the number of rows in this image.voidset(MatWrapper wrapper)Sets this as being backed by the given wrapper.voidset(org.bytedeco.javacpp.opencv_core.GpuMat mat)Sets this as being backed by an image in GPU memory.voidset(org.bytedeco.javacpp.opencv_core.Mat mat)Sets this as being backed by an image in host memory.org.bytedeco.javacpp.opencv_core.Sizesize()Gets the size (width by height) of this image.inttype()Gets the type of the data format of this image.static MatWrapperusing(org.bytedeco.javacpp.opencv_core.Mat cpuMat, org.bytedeco.javacpp.opencv_core.GpuMat gpuMat)Creates a wrapper around existing mats in host and device memory.static MatWrapperwrap(org.bytedeco.javacpp.opencv_core.GpuMat gpuMat)Creates a wrapper around an existing mat in GPU memory.static MatWrapperwrap(org.bytedeco.javacpp.opencv_core.Mat cpuMat)Creates a wrapper around an existing mat in host memory.
-
-
-
Method Detail
-
emptyWrapper
public static MatWrapper emptyWrapper()
Creates an empty wrapper. Both mats are empty and the wrapper is treated as a CPU mat.
-
wrap
public static MatWrapper wrap(org.bytedeco.javacpp.opencv_core.Mat cpuMat)
Creates a wrapper around an existing mat in host memory.
-
wrap
public static MatWrapper wrap(org.bytedeco.javacpp.opencv_core.GpuMat gpuMat)
Creates a wrapper around an existing mat in GPU memory.
-
using
public static MatWrapper using(org.bytedeco.javacpp.opencv_core.Mat cpuMat, org.bytedeco.javacpp.opencv_core.GpuMat gpuMat)
Creates a wrapper around existing mats in host and device memory.- Parameters:
cpuMat- the mat in host memory to usegpuMat- the mat in device memory to use
-
isCpu
public boolean isCpu()
Checks if this is a wrapper around a CPU mat.
-
isGpu
public boolean isGpu()
Checks if this is a wrapper around a GPU mat.
-
rawCpu
public org.bytedeco.javacpp.opencv_core.Mat rawCpu()
Gets the raw CPU mat. This should only be used when this mat is used as adstparameter to an OpenCV function. If you want to get the current value as a mat in host memory, usegetCpu().
-
rawGpu
public org.bytedeco.javacpp.opencv_core.GpuMat rawGpu()
Gets the raw GPU mat. This should only be used when this mat is used as adstparameter to an OpenCV function. If you want to get the current value as a mat in GPU memory, usegetGpu().
-
getCpu
public org.bytedeco.javacpp.opencv_core.Mat getCpu()
Gets this mat as a mat in host memory. If this isbacked by GPU memory, the device memory will be copied into the CPU mat before being returned. This copy only happens afterset(GpuMat)is called, and only once between successive calls; invocations of this method after the first copy will not perform another.
-
getGpu
public org.bytedeco.javacpp.opencv_core.GpuMat getGpu()
Gets this mat as a mat in GPU memory. If this isbacked by host memory, the host memory will be copied into the GPU mat before being returned. This copy only happens afterset(Mat)is called, and only once between successive calls; invocations of this method after the first copy will not perform another.
-
set
public void set(org.bytedeco.javacpp.opencv_core.Mat mat)
Sets this as being backed by an image in host memory. The data in the given mat will be copied into the internal CPU mat, but not the GPU mat untilgetGpu()is called. This avoids unnecessary memory copies between GPU and host memory.
-
set
public void set(org.bytedeco.javacpp.opencv_core.GpuMat mat)
Sets this as being backed by an image in GPU memory. The data in the given mat will be copied into the internal GPU mat, but not the mat residing in host memory untilgetCpu()is called. This avoids unnecessary memory copies between GPU and host memory.
-
set
public void set(MatWrapper wrapper)
Sets this as being backed by the given wrapper. This wrapper will be functionally equivalent to the one given.
-
copyTo
public void copyTo(org.bytedeco.javacpp.opencv_core.Mat mat)
Copies the data of this wrapper to a mat in host memory.
-
copyTo
public void copyTo(org.bytedeco.javacpp.opencv_core.GpuMat mat)
Copies the data of this wrapper to a mat in GPU memory.
-
copyTo
public void copyTo(MatWrapper wrapper)
Copies the data of this wrapper into another. Equivalent towrapper.set(this)
-
cols
public int cols()
Gets the number of columns in this image.
-
rows
public int rows()
Gets the number of rows in this image.
-
type
public int type()
Gets the type of the data format of this image.
-
channels
public int channels()
Gets the number of color channels in this image.
-
depth
public int depth()
Gets the channel depth of this image.
-
empty
public boolean empty()
Checks if this image is empty.
-
size
public org.bytedeco.javacpp.opencv_core.Size size()
Gets the size (width by height) of this image.
-
highValue
public double highValue()
Gets the maximum possible value able to be held as a single element in this image.
-
create
public void create(int rows, int cols, int type)Allocates new array data if needed.- Parameters:
rows- New number of rows.cols- New number of columns.type- New matrix type.
-
put
public MatWrapper put(org.bytedeco.javacpp.opencv_core.Scalar value)
Sets all or some of the array elements to the specified value.- Parameters:
value- Assigned scalar converted to the actual array type.
-
-