私は写真を撮ったり保存したりできるJavaCameraViewサブクラスを持っています。問題は、onCameraFrame()で受信したプレビューフレームが、キャプチャされ保存された写真と同じディメンションを共有しないため、保存されたイメージがフレームに対してクロップして表示されることです。入力フレームは1080 * 1440(3:4)で、キャプチャは2988 * 5312(9:16)です。次のようにAndroid、OpenCv、取り込まれた写真の寸法がプレビューと一致しません
私のコードは次のとおりです。他のクラスにおいては
public void takePicture() {
Log.i(CaptureActivity.TAG, "MyCameraView, takePicture()");
// Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture.
// Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue
mCamera.setPreviewCallback(null);
// PictureTakenListener is implemented by the current class
mCamera.takePicture(null, null, this);
}
@Override
public void onPictureTaken(byte[] bytes, Camera camera) {
// The camera preview was automatically stopped. Start it again.
mCamera.startPreview();
mCamera.setPreviewCallback(this);
Mat mat = Imgcodecs.imdecode(new MatOfByte(bytes), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
Log.d(CaptureActivity.TAG, mat.toString());
//an interface method to be implemented by CaptureActivity
if (mPictureTakenListener != null)
mPictureTakenListener.receivePicture(mat);
}
を、私は絵を受け取り、それを保存...
@Override
public void receivePicture(Mat mat) {
File path = new File(Environment.getExternalStorageDirectory() + "/myCamera/");
path.mkdirs();
File file = new File(path, System.currentTimeMillis() + "recieved" + ".png");
String filename = file.toString();
Log.d(CaptureActivity.TAG, "was imwrite a success? "
+ Imgcodecs.imwrite(filename, mat));
}
また、このクラスは、CameraBridgeViewBase.CvCameraViewListener2を実装...
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Log.d(TAG, "frame info " + frame.toString());
return frame;
}