Konvertieren Sie Matte zu Bitmap und Bitmap zu Matte. Ich habe schwarze Szene. Was könnte Grund sein, jemand mir bitte helfenWie mat in Bitmap und Bitmap in Mat konvertieren?
package com.example.alper.myapplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import org.opencv.android.Utils;
import org.opencv.core.CvException;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import static org.opencv.imgproc.Imgproc.cvtColor;
public class Main2Activity extends AppCompatActivity {
ImageView iv;
Bitmap bmpInput, bmpOutput;
Mat matInput , matOutput;
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
iv = (ImageView) findViewById(R.id.imageView2);
bt= (Button) findViewById(R.id.button2);
String photoPath = Environment.getExternalStorageDirectory()+"/frames/frame.png";
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bmpInput = BitmapFactory.decodeFile(photoPath,options);
iv.setImageBitmap(bmpInput);
matInput = convertBitMap2Mat(bmpInput);
matOutput = new Mat(matInput.rows(), matInput.cols(), CvType.CV_8UC3);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bmpOutput = converMat2Bitmat(matOutput);
iv.setImageBitmap(bmpOutput);
}
});
}
Bitmap converMat2Bitmat (Mat img) {
int width = img.width();
int hight = img.height();
Bitmap bmp;
bmp = Bitmap.createBitmap(width, hight, Bitmap.Config.ARGB_8888);
Mat tmp;
tmp = img.channels()==1? new Mat(width, hight, CvType.CV_8UC1, new Scalar(1)): new Mat(width, hight, CvType.CV_8UC3, new Scalar(3));
try {
if (img.channels()==3)
cvtColor(img, tmp, Imgproc.COLOR_RGB2BGRA);
else if (img.channels()==1)
cvtColor(img, tmp, Imgproc.COLOR_GRAY2RGBA);
Utils.matToBitmap(tmp, bmp);
}
catch (CvException e){
Log.d("Expection",e.getMessage());
}
return bmp;
}
Mat convertBitMap2Mat (Bitmap rgbaImage){
Mat rgbaMat = new Mat(rgbaImage.getHeight(), rgbaImage.getWidth(),CvType.CV_8UC4);
Bitmap bmp32 = rgbaImage.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmp32, rgbaMat);
Mat rgbMat = new Mat(rgbaImage.getHeight(), rgbaImage.getWidth(), CvType.CV_8UC3);
cvtColor(rgbaMat,rgbMat,Imgproc.COLOR_RGBA2BGR, 3);
return rgbMat;
}
Ich habe ein Bitmap-Bild. Ich möchte aus Bitmap zu Matte konvertieren und dann ein Bildprozess erneut anwenden, um Bitmap von Matte zu konvertieren und dann in der Bildansicht zu zeigen, aber ich habe eine schwarze Szene. Du denkst, was Grund sein könnte? Hilf mir.