本文整理汇总了Java中org.bytedeco.javacpp.Pointer类的典型用法代码示例。如果您正苦于以下问题:Java Pointer类的具体用法?Java Pointer怎么用?Java Pointer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pointer类属于org.bytedeco.javacpp包,在下文中一共展示了Pointer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressPointer
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Override
protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length,
int elementSize) {
BytePointer ptr = new BytePointer(length);
CompressionDescriptor descriptor = new CompressionDescriptor();
descriptor.setCompressedLength(length * 1);
descriptor.setOriginalLength(length * elementSize);
descriptor.setOriginalElementSize(elementSize);
descriptor.setNumberOfElements(length);
descriptor.setCompressionAlgorithm(getDescriptor());
descriptor.setCompressionType(getCompressionType());
CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor);
Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.UINT8, ptr, length);
return buffer;
}
示例2: main
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
public static void main(String[] args) {
int i;
for (i = 0; i < 100000; i++) {
try {
InputStream stream = PreprocessMemoryTest.class.getClassLoader().getResourceAsStream("1080_de_01.png");
OCR.getInstance().convertToStocks(stream, Locale.GERMAN, Device.ANDROID);
if (i % 100 == 0 || i == 0) {
long maxPhysicalBytes = Pointer.maxPhysicalBytes();
long physicalBytes = Pointer.physicalBytes();
Runtime runtime = Runtime.getRuntime();
long usedBytes = runtime.totalMemory() - runtime.freeMemory();
System.out.printf("%d %d %d %d\n", i, maxPhysicalBytes, physicalBytes, usedBytes);
}
} catch (Throwable e) {
Assert.fail("On Try: " + i);
}
}
Assert.assertTrue(true);
}
示例3: testConcatForever1
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Test
public void testConcatForever1() {
INDArray[] arr = new INDArray[3];
arr[0] = Nd4j.linspace(0,49,50).reshape('c',5,10);
arr[1] = Nd4j.linspace(50,59,10);
arr[2] = Nd4j.linspace(60,99,40).reshape('c',4,10);
INDArray expected = Nd4j.linspace(0,99,100).reshape('c',10,10);
for (int i = 0; i < RUN_LIMIT; i++ ) {
INDArray actual = Nd4j.vstack(arr);
assertEquals("Failed on [" + i + "] iteration",expected, actual);
if (i % 500 == 0) {
System.out.println("Iteration " + i + " passed, Mem: " + (Pointer.maxBytes() / 1024 / 1024));
}
}
}
示例4: compressPointer
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Override
protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length,
int elementSize) {
BytePointer ptr = new BytePointer(length);
CompressionDescriptor descriptor = new CompressionDescriptor();
descriptor.setCompressedLength(length * 1);
descriptor.setOriginalLength(length * elementSize);
descriptor.setOriginalElementSize(elementSize);
descriptor.setNumberOfElements(length);
descriptor.setCompressionAlgorithm(getDescriptor());
descriptor.setCompressionType(getCompressionType());
CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor);
Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.INT8, ptr, length);
return buffer;
}
示例5: compressPointer
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Override
protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length,
int elementSize) {
CompressionDescriptor descriptor = new CompressionDescriptor();
descriptor.setCompressionType(getCompressionType());
descriptor.setOriginalLength(length * elementSize);
descriptor.setCompressionAlgorithm(getDescriptor());
descriptor.setOriginalElementSize(elementSize);
descriptor.setCompressedLength(length * elementSize);
descriptor.setNumberOfElements(length);
BytePointer ptr = new BytePointer(length * elementSize);
// this Pointer.memcpy is used intentionally. This method operates on host memory ALWAYS
Pointer.memcpy(ptr, srcPointer, length * elementSize);
CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor);
return buffer;
}
示例6: endlessTest6
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Test
public void endlessTest6() throws Exception {
Nd4j.getMemoryManager().togglePeriodicGc(false);
WorkspaceConfiguration wsConf = WorkspaceConfiguration.builder().initialSize(10 * 1024L * 1024L)
.policyLearning(LearningPolicy.NONE).build();
final AtomicLong cnt = new AtomicLong(0);
while (true) {
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(wsConf, "PEW-PEW")) {
INDArray array = Nd4j.create(new float[] {1f, 2f, 3f, 4f, 5f});
}
if (cnt.incrementAndGet() % 1000000 == 0)
log.info("TotalBytes: {}", Pointer.totalBytes());
}
}
示例7: create
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
/**
* Create a data buffer based on the
* given pointer, data buffer opType,
* and length of the buffer
*
* @param pointer the pointer to use
* @param type the opType of buffer
* @param length the length of the buffer
* @param indexer
* @return the data buffer
* backed by this pointer with the given
* opType and length.
*/
@Override
public DataBuffer create(Pointer pointer, DataBuffer.Type type, long length, Indexer indexer) {
switch (type) {
case INT:
return new CudaIntDataBuffer(pointer, indexer, length);
case DOUBLE:
return new CudaDoubleDataBuffer(pointer, indexer, length);
case FLOAT:
return new CudaFloatDataBuffer(pointer, indexer, length);
case HALF:
return new CudaHalfDataBuffer(pointer, indexer, length);
}
throw new IllegalArgumentException("Illegal opType " + type);
}
示例8: compressPointer
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Override
protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length,
int elementSize) {
BytePointer ptr = new BytePointer(length * 2);
CompressionDescriptor descriptor = new CompressionDescriptor();
descriptor.setCompressedLength(length * 2);
descriptor.setOriginalLength(length * elementSize);
descriptor.setOriginalElementSize(elementSize);
descriptor.setNumberOfElements(length);
descriptor.setCompressionAlgorithm(getDescriptor());
descriptor.setCompressionType(getCompressionType());
CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor);
Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.INT16, ptr, length);
return buffer;
}
示例9: pushImage
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
public void pushImage(int width, int height, int depth, int channels, int stride, int pixelFormat, Buffer ... image) throws Exception {
int step = stride * Math.abs(depth) / 8;
BytePointer data = image[0] instanceof ByteBuffer
? new BytePointer((ByteBuffer)image[0].position(0))
: new BytePointer(new Pointer(image[0].position(0)));
if (pixelFormat == AV_PIX_FMT_NONE) {
if ((depth == Frame.DEPTH_UBYTE || depth == Frame.DEPTH_BYTE) && channels == 3) {
pixelFormat = AV_PIX_FMT_BGR24;
} else if ((depth == Frame.DEPTH_UBYTE || depth == Frame.DEPTH_BYTE) && channels == 1) {
pixelFormat = AV_PIX_FMT_GRAY8;
} else if ((depth == Frame.DEPTH_USHORT || depth == Frame.DEPTH_SHORT) && channels == 1) {
pixelFormat = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN) ?
AV_PIX_FMT_GRAY16BE : AV_PIX_FMT_GRAY16LE;
} else if ((depth == Frame.DEPTH_UBYTE || depth == Frame.DEPTH_BYTE) && channels == 4) {
pixelFormat = AV_PIX_FMT_RGBA;
} else if ((depth == Frame.DEPTH_UBYTE || depth == Frame.DEPTH_BYTE) && channels == 2) {
pixelFormat = AV_PIX_FMT_NV21; // Android's camera capture format
step = width;
} else {
throw new Exception("Could not guess pixel format of image: depth=" + depth + ", channels=" + channels);
}
}
avpicture_fill(new AVPicture(image_frame), data, pixelFormat, width, height);
image_frame.linesize(0, step);
image_frame.format(pixelFormat);
image_frame.width(width);
image_frame.height(height);
/* push the decoded frame into the filtergraph */
if (av_buffersrc_add_frame_flags(buffersrc_ctx, image_frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
throw new Exception("av_buffersrc_add_frame_flags(): Error while feeding the filtergraph.");
}
}
示例10: AutoCropper
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
public AutoCropper(Context context) throws IOException {
storage = CvMemStorage.create(); // Allocate the memory storage.
// Preload the opencv_objdetect module to work around a known bug.
Loader.load(opencv_objdetect.class);
InputStream in = context.getAssets().open("haarcascade_frontalface_alt.xml");
final File file = File.createTempFile("classifier", ".xml");
streamToFile(in, file);
in.close();
String path = file.getPath();
Pointer p = cvLoad(path);
file.delete();
classifier = new CvHaarClassifierCascade(p);
}
示例11: imageChanged
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Override
public void imageChanged(IplImage image) {
foreground = IplImage.create(image.width(), image.height(), IPL_DEPTH_8U, 1);
Pointer pointer = new Pointer();
//mog = new BackgroundSubtractorMOG2(history, threshold, shadowDetection);
// TODO: test this..
mog = new BackgroundSubtractorMOG2(pointer);
}
示例12: read
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
public static CameraDevice[] read(CvFileStorage fs) throws Exception {
CvFileNode node = cvGetFileNodeByName(fs, null, "Cameras");
CvSeq seq = node.data_seq();
int count = seq.total();
CameraDevice[] devices = new CameraDevice[count];
for (int i = 0; i < count; i++) {
Pointer p = cvGetSeqElem(seq, i);
if (p == null) continue;
String name = cvReadString(new CvFileNode(p), (String)null);
devices[i] = new CameraDevice(name, fs);
}
return devices;
}
示例13: read
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
public static ProjectorDevice[] read(CvFileStorage fs) throws Exception {
CvFileNode node = cvGetFileNodeByName(fs, null, "Projectors");
CvSeq seq = node.data_seq();
int count = seq.total();
ProjectorDevice[] devices = new ProjectorDevice[count];
for (int i = 0; i < count; i++) {
Pointer p = cvGetSeqElem(seq, i);
if (p == null) continue;
String name = cvReadString(new CvFileNode(p), (String)null);
devices[i] = new ProjectorDevice(name, fs);
}
return devices;
}
示例14: dup
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Override
public DataBuffer dup() {
Pointer nPtr = new BytePointer(compressionDescriptor.getCompressedLength());
Pointer.memcpy(nPtr, pointer, compressionDescriptor.getCompressedLength());
CompressionDescriptor nDesc = compressionDescriptor.clone();
CompressedDataBuffer nBuf = new CompressedDataBuffer(nPtr, nDesc);
return nBuf;
}
示例15: testBufferCreation
import org.bytedeco.javacpp.Pointer; //导入依赖的package包/类
@Test
public void testBufferCreation() {
DataBuffer dataBuffer = Nd4j.createBuffer(new double[] {1, 2});
Pointer pointer = dataBuffer.pointer();
FloatPointer floatPointer = new FloatPointer(pointer);
DataBuffer dataBuffer1 = Nd4j.createBuffer(floatPointer, 2);
assertEquals(2, dataBuffer1.length());
assertEquals(1.0, dataBuffer1.getDouble(0), 1e-1);
assertEquals(2.0, dataBuffer1.getDouble(1), 1e-1);
INDArray arr = Nd4j.create(dataBuffer1);
System.out.println(arr);
}