In the App I am developing I open the Camera using OpenCV4Android
using CameraBridgeViewBase.CvCameraViewListener2
and when I touch the screen I set that frame as an image inside an ImageView
as shown below in the code.
the problem is the image set to the imageview
is always of different color than the preview on the camera as shown in the picture. I believe that this issue has something to do with the conversion I made which is stated in the code below
My question is how to convert the Mat object to a Bitmap
preserving the same color?
pic
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Log.w(TAG, "onCameraFrame");
if (mRGBT != null) {
mRGBT.release();
}
mRGBT = inputFrame.rgba().t();
Core.flip(mRGBT, mRGBT, 1);
Imgproc.resize(mRGBT, mRGBT, inputFrame.rgba().size());
if (touched) {
touched = false;
Imgproc.cvtColor(mRGBT, mRGBT, CvType.CV_8U);
final Bitmap bitmap = Bitmap.createBitmap(mRGBT.cols(), mRGBT.rows(), Bitmap.Config.RGB_565);
Utils.matToBitmap(mRGBT, bitmap);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mIV.setImageBitmap(bitmap);
}
});
}
return mRGBT;
}