Java Code Examples for org.bytedeco.javacpp.indexer.FloatIndexer#put()
The following examples show how to use
org.bytedeco.javacpp.indexer.FloatIndexer#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerspectiveTransformRunner.java From konduit-serving with Apache License 2.0 | 6 votes |
private Mat getPerspectiveTransform(Mat sourceMat, Mat targetMat, int refWidth, int refHeight) { Mat initialTransform = opencv_imgproc.getPerspectiveTransform(sourceMat, targetMat); if(refWidth == -1 || refHeight == -1) { return initialTransform; } // Calculate where edges will end up in this case double[] extremes = calculateExtremes(initialTransform, refWidth, refHeight); FloatIndexer tIdx = targetMat.createIndexer(); long rows = tIdx.size(0); for (long i = 0; i < rows; i++) { tIdx.put(i, 0, (float)(tIdx.get(i, 0) - extremes[0])); tIdx.put(i, 1, (float)(tIdx.get(i, 1) - extremes[1])); } return opencv_imgproc.getPerspectiveTransform(sourceMat, targetMat); }
Example 2
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
private void initNativeIntrinsic() { if (intrinsicsMat == null) { intrinsicsMat = new Mat(3, 3, CV_32FC1); FloatIndexer intrinsicIdx = intrinsicsMat.createIndexer(true); // init to 0 int k = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { intrinsicIdx.put(k++, 0); } } // set the values intrinsicIdx.put(0, 0, intrinsics.m00); intrinsicIdx.put(1, 1, intrinsics.m11); intrinsicIdx.put(0, 2, intrinsics.m02); intrinsicIdx.put(1, 2, intrinsics.m12); intrinsicIdx.put(2, 2, 1); } }
Example 3
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
private void fillNative(PVector[] objectPoints, PVector[] imagePoints, Mat op, Mat ip) { FloatIndexer opIdx = op.createIndexer(); FloatIndexer ipIdx = ip.createIndexer(); // Fill the object and image matrices. for (int i = 0; i < objectPoints.length; i++) { opIdx.put(i, 0, objectPoints[i].x); opIdx.put(i, 1, objectPoints[i].y); opIdx.put(i, 2, objectPoints[i].z); ipIdx.put(i, 0, imagePoints[i].x); ipIdx.put(i, 1, imagePoints[i].y); } }
Example 4
Source File: PerspectiveTransformRunner.java From konduit-serving with Apache License 2.0 | 5 votes |
private Mat pointsToMat(List<Point> points){ int rows = points.size(); int cols = points.get(1).dimensions(); Mat mat = new Mat(rows, cols, CvType.CV_32F); FloatIndexer idx = mat.createIndexer(); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { idx.put(i, j, (float)points.get(i).get(j)); } } return mat; }
Example 5
Source File: OnnxTest.java From konduit-serving with Apache License 2.0 | 5 votes |
@Test public void runSqueezenet(TestContext testContext) throws Exception { long inputTensorSize = 224 * 224 * 3; FloatPointer inputTensorValues = new FloatPointer(inputTensorSize); FloatIndexer idx = FloatIndexer.create(inputTensorValues); for (long i = 0; i < inputTensorSize; i++) idx.put(i, (float) i / (inputTensorSize + 1)); DataBuffer buffer = Nd4j.createBuffer(inputTensorValues, DataType.FLOAT, inputTensorSize, idx); INDArray contents = Nd4j.create(buffer); byte[] npyContents = Nd4j.toNpyByteArray(contents); File inputFile = temporary.newFile(); FileUtils.writeByteArrayToFile(inputFile, npyContents); for (int i = 0; i < 5; i++) { Response response = given().port(port) .multiPart("data_0", inputFile) .post("nd4j/numpy") .andReturn(); //TODO: report memory leak in DNNL execution provider to ORT assertEquals("Response failed", 200, response.getStatusCode()); INDArray bodyResult = Nd4j.createNpyFromByteArray(response.getBody().asByteArray()); assertEquals(1.99018, bodyResult.getFloat(0), 1e-4); assertArrayEquals(new long[]{1, 1000}, bodyResult.shape()); } }
Example 6
Source File: CoreFunc.java From vlpr4j with Apache License 2.0 | 5 votes |
/** * Assign values to feature * <p> * 样本特征为水平、垂直直方图和低分辨率图像所组成的矢量 * * @param in * @param sizeData - 低分辨率图像size = sizeData*sizeData, 可以为0 * @return */ public static Mat features(final Mat in, final int sizeData) { float[] vhist = projectedHistogram(in, Direction.VERTICAL); float[] hhist = projectedHistogram(in, Direction.HORIZONTAL); Mat lowData = new Mat(); if (sizeData > 0) { resize(in, lowData, new Size(sizeData, sizeData)); } int numCols = vhist.length + hhist.length + lowData.cols() * lowData.rows(); Mat out = Mat.zeros(1, numCols, CV_32F).asMat(); FloatIndexer idx = out.createIndexer(); int j = 0; for (int i = 0; i < vhist.length; ++i, ++j) { idx.put(0, j, vhist[i]); } for (int i = 0; i < hhist.length; ++i, ++j) { idx.put(0, j, hhist[i]); } for (int x = 0; x < lowData.cols(); x++) { for (int y = 0; y < lowData.rows(); y++, ++j) { float val = lowData.ptr(x, y).get() & 0xFF; idx.put(0, j, val); } } return out; }
Example 7
Source File: CoreFunc.java From EasyPR-Java with Apache License 2.0 | 5 votes |
/** * Assign values to feature * <p> * 样本特征为水平、垂直直方图和低分辨率图像所组成的矢量 * * @param in * @param sizeData * 低分辨率图像size = sizeData*sizeData, 可以为0 * @return */ public static Mat features(final Mat in, final int sizeData) { float[] vhist = projectedHistogram(in, Direction.VERTICAL); float[] hhist = projectedHistogram(in, Direction.HORIZONTAL); Mat lowData = new Mat(); if (sizeData > 0) { resize(in, lowData, new Size(sizeData, sizeData)); } int numCols = vhist.length + hhist.length + lowData.cols() * lowData.rows(); Mat out = Mat.zeros(1, numCols, CV_32F).asMat(); FloatIndexer idx = out.createIndexer(); int j = 0; for (int i = 0; i < vhist.length; ++i, ++j) { idx.put(0, j, vhist[i]); } for (int i = 0; i < hhist.length; ++i, ++j) { idx.put(0, j, hhist[i]); } for (int x = 0; x < lowData.cols(); x++) { for (int y = 0; y < lowData.rows(); y++, ++j) { float val = lowData.ptr(x, y).get() & 0xFF; idx.put(0, j, val); } } return out; }
Example 8
Source File: OnnxMultipleInputsTest.java From konduit-serving with Apache License 2.0 | 3 votes |
@Test public void runAdd(TestContext testContext) throws Exception { long inputTensorSize = 3 * 4 * 5; FloatPointer inputTensorValues = new FloatPointer(inputTensorSize); FloatIndexer idx = FloatIndexer.create(inputTensorValues); for (long i = 0; i < inputTensorSize; i++) idx.put(i, (float) i / (inputTensorSize + 1)); DataBuffer buffer = Nd4j.createBuffer(inputTensorValues, DataType.FLOAT, inputTensorSize, idx); INDArray contents = Nd4j.create(buffer); byte[] npyContents = Nd4j.toNpyByteArray(contents); File inputFile = temporary.newFile(); FileUtils.writeByteArrayToFile(inputFile, npyContents); Response response = given().port(port) .multiPart("x", inputFile) .multiPart("y", inputFile) .post("nd4j/numpy") .andReturn(); assertEquals("Response failed", 200, response.getStatusCode()); INDArray bodyResult = Nd4j.createNpyFromByteArray(response.getBody().asByteArray()); assertEquals(0.032786883, bodyResult.getFloat(1), 1e-6); assertArrayEquals(new long[]{1, 60}, bodyResult.shape()); }