Guest User

Untitled

a guest
Dec 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public void takePicture() {
  2. Log.i(CaptureActivity.TAG, "MyCameraView, takePicture()");
  3. // Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture.
  4. // Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue
  5. mCamera.setPreviewCallback(null);
  6.  
  7. // PictureTakenListener is implemented by the current class
  8. mCamera.takePicture(null, null, this);
  9. }
  10.  
  11. @Override
  12. public void onPictureTaken(byte[] bytes, Camera camera) {
  13. // The camera preview was automatically stopped. Start it again.
  14. mCamera.startPreview();
  15. mCamera.setPreviewCallback(this);
  16.  
  17. Mat mat = Imgcodecs.imdecode(new MatOfByte(bytes), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
  18. Log.d(CaptureActivity.TAG, mat.toString());
  19.  
  20. //an interface method to be implemented by CaptureActivity
  21. if (mPictureTakenListener != null)
  22. mPictureTakenListener.receivePicture(mat);
  23. }
  24.  
  25. @Override
  26. public void receivePicture(Mat mat) {
  27. File path = new File(Environment.getExternalStorageDirectory() + "/myCamera/");
  28. path.mkdirs();
  29. File file = new File(path, System.currentTimeMillis() + "recieved" + ".png");
  30. String filename = file.toString();
  31. Log.d(CaptureActivity.TAG, "was imwrite a success? "
  32. + Imgcodecs.imwrite(filename, mat));
  33. }
  34.  
  35. public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
  36. Log.d(TAG, "frame info " + frame.toString());
  37. return frame;
  38. }
Add Comment
Please, Sign In to add comment