List of usage examples for org.opencv.core Mat getNativeObjAddr
public long getNativeObjAddr()
From source file:ph.edu.dlsu.mhealth.vision.DetectionBasedTracker.java
License:Open Source License
public void detect(Mat imageGray, MatOfRect faces) { nativeDetect(mNativeAddr, imageGray.getNativeObjAddr(), faces.getNativeObjAddr()); }
From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java
License:Apache License
@Override public MarkerData findMarkersInFrame(byte[] frame) { if (ocvOn) {// w w w. j a va 2 s . c o m if (cameraCalibrated) { int[] codes = new int[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS]; float[] translations = new float[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS * 3]; float[] rotations = new float[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS * 9]; MarkerData data; Bitmap tFrame, mFrame; Mat inImg = new Mat(); Mat outImg = new Mat(); // Fill the codes array with -1 to indicate markers that were not found; for (int i : codes) codes[i] = -1; // Decode the input image and convert it to an OpenCV matrix. tFrame = BitmapFactory.decodeByteArray(frame, 0, frame.length); Utils.bitmapToMat(tFrame, inImg); // Find the markers in the input image. getMarkerCodesAndLocations(inImg.getNativeObjAddr(), outImg.getNativeObjAddr(), codes, cameraMatrix.getNativeObjAddr(), distortionCoeffs.getNativeObjAddr(), translations, rotations); // Encode the output image as a JPEG image. mFrame = Bitmap.createBitmap(outImg.cols(), outImg.rows(), Bitmap.Config.RGB_565); Utils.matToBitmap(outImg, mFrame); mFrame.compress(CompressFormat.JPEG, 100, outputStream); // Create and fill the output data structure. data = new MarkerData(); data.outFrame = outputStream.toByteArray(); data.markerCodes = codes; data.rotationMatrices = new Matrix3[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS]; data.translationVectors = new Vector3[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS]; for (int i = 0, p = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++, p += 3) { data.translationVectors[i] = new Vector3(translations[p], translations[p + 1], translations[p + 2]); } for (int k = 0; k < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; k++) { data.rotationMatrices[k] = new Matrix3(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { data.rotationMatrices[k].val[col + (row * 3)] = rotations[col + (row * 3) + (9 * k)]; } } } // Clean up memory. tFrame.recycle(); mFrame.recycle(); outputStream.reset(); return data; } else { Gdx.app.debug(TAG, CLASS_NAME + ".findMarkersInFrame(): The camera has not been calibrated."); return null; } } else { Gdx.app.debug(TAG, CLASS_NAME + ".findMarkersInFrame(): OpenCV is not ready or failed to load."); return null; } }
From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java
License:Apache License
@Override public CalibrationData findCalibrationPattern(byte[] frame) { if (ocvOn) {/*from w ww . j a v a 2 s . co m*/ boolean found; float points[] = new float[ProjectConstants.CALIBRATION_PATTERN_POINTS * 2]; Bitmap tFrame, mFrame; Mat inImg = new Mat(), outImg = new Mat(); CalibrationData data = new CalibrationData(); // Decode the input frame and convert it to an OpenCV Matrix. tFrame = BitmapFactory.decodeByteArray(frame, 0, frame.length); Utils.bitmapToMat(tFrame, inImg); // Attempt to find the calibration pattern in the input frame. found = findCalibrationPattern(inImg.getNativeObjAddr(), outImg.getNativeObjAddr(), points); // Encode the output image as a JPEG image. mFrame = Bitmap.createBitmap(outImg.cols(), outImg.rows(), Bitmap.Config.RGB_565); Utils.matToBitmap(outImg, mFrame); mFrame.compress(CompressFormat.JPEG, 100, outputStream); // Prepare the output data structure. data.outFrame = outputStream.toByteArray(); data.calibrationPoints = found ? points : null; // Clean up memory. tFrame.recycle(); mFrame.recycle(); outputStream.reset(); return data; } else { Gdx.app.debug(TAG, CLASS_NAME + ".findCalibrationPattern(): OpenCV is not ready or failed to load."); return null; } }
From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java
License:Apache License
@Override public void calibrateCamera(float[][] calibrationSamples, byte[] frame) { if (ocvOn) {/*w w w .ja v a 2s.c om*/ float[] calibrationPoints = new float[ProjectConstants.CALIBRATION_PATTERN_POINTS * 2 * ProjectConstants.CALIBRATION_SAMPLES]; int w = ProjectConstants.CALIBRATION_PATTERN_POINTS * 2; Bitmap tFrame; Mat inImg = new Mat(); // Save the calibration points on a one dimensional array for easier parameter passing // to the native code. for (int i = 0; i < ProjectConstants.CALIBRATION_SAMPLES; i++) { for (int j = 0, p = 0; j < ProjectConstants.CALIBRATION_PATTERN_POINTS; j++, p += 2) { calibrationPoints[p + (w * i)] = calibrationSamples[i][p]; calibrationPoints[(p + 1) + (w * i)] = calibrationSamples[i][p + 1]; } } // Decode the input image and convert it to an OpenCV matrix. tFrame = BitmapFactory.decodeByteArray(frame, 0, frame.length); Utils.bitmapToMat(tFrame, inImg); // Attempt to obtain the camera parameters. double error = calibrateCameraParameters(cameraMatrix.getNativeObjAddr(), distortionCoeffs.getNativeObjAddr(), inImg.getNativeObjAddr(), calibrationPoints); Gdx.app.log(TAG, CLASS_NAME + "calibrateCamera(): calibrateCameraParameters retured " + Double.toString(error)); cameraCalibrated = true; } else { Gdx.app.debug(TAG, CLASS_NAME + ".calibrateCamera(): OpenCV is not ready or failed to load."); } }