List of usage examples for org.opencv.android Utils matToBitmap
public static void matToBitmap(Mat mat, Bitmap bmp)
From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java
License:Apache License
@Override public CalibrationData findCalibrationPattern(byte[] frame) { if (ocvOn) {/*from w w w. jav a 2 s. c om*/ 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 byte[] undistortFrame(byte[] frame) { if (ocvOn) {/*from w w w. jav a 2 s . com*/ if (cameraCalibrated) { byte undistortedFrame[]; Bitmap tFrame, mFrame; Mat inImg = new Mat(), outImg = new Mat(); // Decode the input frame and convert it to an OpenCV Matrix. tFrame = BitmapFactory.decodeByteArray(frame, 0, frame.length); Utils.bitmapToMat(tFrame, inImg); // Apply the undistort correction to the input frame. Imgproc.undistort(inImg, outImg, cameraMatrix, distortionCoeffs); // 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 return frame. undistortedFrame = outputStream.toByteArray(); // Clean up memory. tFrame.recycle(); mFrame.recycle(); outputStream.reset(); return undistortedFrame; } else { Gdx.app.debug(TAG, CLASS_NAME + ".undistortFrame(): Camera has not been calibrated."); return null; } } else { Gdx.app.debug(TAG, CLASS_NAME + ".undistortFrame(): OpenCV is not ready or failed to load."); return null; } }