use of org.bytedeco.javacpp.Pointer in project nd4j by deeplearning4j.
the class CompressedDataBuffer method dup.
@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;
}
use of org.bytedeco.javacpp.Pointer in project nd4j by deeplearning4j.
the class CompressedDataBuffer method readUnknown.
/**
* Drop-in replacement wrapper for BaseDataBuffer.read() method, aware of CompressedDataBuffer
* @param s
* @return
*/
public static DataBuffer readUnknown(DataInputStream s, long length) {
DataBuffer buffer = Nd4j.createBuffer(length);
buffer.read(s);
// if buffer is uncompressed, it'll be valid buffer, so we'll just return it
if (buffer.dataType() != Type.COMPRESSED)
return buffer;
else {
try {
// if buffer is compressed one, we''ll restore and decompress it here
String compressionAlgorithm = s.readUTF();
long compressedLength = s.readLong();
long originalLength = s.readLong();
long numberOfElements = s.readLong();
byte[] temp = new byte[(int) compressedLength];
for (int i = 0; i < compressedLength; i++) {
temp[i] = s.readByte();
}
try (Pointer pointer = new BytePointer(temp)) {
CompressionDescriptor descriptor = new CompressionDescriptor();
descriptor.setCompressedLength(compressedLength);
descriptor.setCompressionAlgorithm(compressionAlgorithm);
descriptor.setOriginalLength(originalLength);
descriptor.setNumberOfElements(numberOfElements);
CompressedDataBuffer compressedBuffer = new CompressedDataBuffer(pointer, descriptor);
return Nd4j.getCompressor().decompress(compressedBuffer);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
use of org.bytedeco.javacpp.Pointer in project javacv by bytedeco.
the class CameraDevice method read.
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;
}
use of org.bytedeco.javacpp.Pointer in project javacv by bytedeco.
the class ProjectiveDevice method readParameters.
public void readParameters(CvFileStorage fs) throws Exception {
if (fs == null) {
throw new Exception("Error: CvFileStorage is null, cannot read parameters for device " + getSettings().getName() + ". Is the parametersFile correct?");
}
CvAttrList a = cvAttrList();
CvFileNode fn = cvGetFileNodeByName(fs, null, getSettings().getName());
if (fn == null) {
throw new Exception("Error: CvFileNode is null, cannot read parameters for device " + getSettings().getName() + ". Is the name correct?");
}
imageWidth = cvReadIntByName(fs, fn, "imageWidth", imageWidth);
imageHeight = cvReadIntByName(fs, fn, "imageHeight", imageHeight);
getSettings().setResponseGamma(cvReadRealByName(fs, fn, "gamma", getSettings().getResponseGamma()));
// getSettings().initAspectRatio = cvReadRealByName(fs, fn, "initAspectRatio", getSettings().initAspectRatio);
// getSettings().flags = cvReadIntByName(fs, fn, "flags", getSettings().flags);
Pointer p = cvReadByName(fs, fn, "cameraMatrix", a);
cameraMatrix = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "distortionCoeffs", a);
distortionCoeffs = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "extrParams", a);
extrParams = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "reprojErrs", a);
reprojErrs = p == null ? null : new CvMat(p);
avgReprojErr = cvReadRealByName(fs, fn, "avgReprojErr", avgReprojErr);
maxReprojErr = cvReadRealByName(fs, fn, "maxReprojErr", maxReprojErr);
// nominalDistance = cvReadRealByName(fs, fn, "nominalDistance", nominalDistance);
p = cvReadByName(fs, fn, "R", a);
R = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "T", a);
T = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "E", a);
E = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "F", a);
F = p == null ? null : new CvMat(p);
avgEpipolarErr = cvReadRealByName(fs, fn, "avgEpipolarErr", avgEpipolarErr);
maxEpipolarErr = cvReadRealByName(fs, fn, "maxEpipolarErr", maxEpipolarErr);
colorOrder = cvReadStringByName(fs, fn, "colorOrder", colorOrder);
p = cvReadByName(fs, fn, "colorMixingMatrix", a);
colorMixingMatrix = p == null ? null : new CvMat(p);
p = cvReadByName(fs, fn, "additiveLight", a);
additiveLight = p == null ? null : new CvMat(p);
avgColorErr = cvReadRealByName(fs, fn, "avgColorErr", avgColorErr);
colorR2 = cvReadRealByName(fs, fn, "colorR2", colorR2);
}
use of org.bytedeco.javacpp.Pointer in project javacv by bytedeco.
the class ProjectorDevice method read.
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;
}
Aggregations