Why is my JavaCameraView is squeezed vertically?
This is what the JavaCameraView looks like, my face is squeezed:
I use this code to achieve this effect:
/**
* Do processing after frame grabbing before rendering on screen
* @Param inputFrame
* @return
*/
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
//For background subtraction
mRgba = inputFrame.rgba();
Imgproc.cvtColor(mRgba, mRgb, Imgproc.COLOR_RGBA2RGB); //the apply function will throw the above error if you don't feed it an RGB image
sub.apply(mRgb, mFGMask, -1); //apply() exports a gray image by definition
Imgproc.cvtColor(mFGMask, mRgba, Imgproc.COLOR_GRAY2RGBA);
//transpose the matrix mRgba and put the result in trans
Core.transpose(mRgba,trans);
//flip trans about the x-axis
Core.flip(trans, trans, 0);
Core.flip(trans, trans, 1);
Imgproc.resize(trans, trans, mRgba.size());
//flip trans about the y-axis
return trans;
}
private BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(10, 25, false);
private Mat mRgb=new Mat();
private Mat mFGMask=new Mat();
private Mat mRgba=new Mat();
private Mat trans=new Mat();
Here is the interesting thing, I made the shutter button using:
Utils.matToBitmap(trans,previewBitmap);
to convert trans to a bitmap and display it. On most occasions, I was getting what is displayed in the live processing. But if I kept pressing "shutter", I was able to capture a snapshot like this( my face is NOT warped!):
Now the question is: How can I programmatically make my code so every photo I capture looks like the one above?