看看你的项目中是不是有个多个Mat?
追进Mat 看一下里面是不是有get() 方法 或者排查一下方法得访问修饰符
这是目前MainActivity的代码
package com.example.tt1;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.File;
import java.net.URL;
import org.bytedeco.javacv.*;
import org.bytedeco.opencv.opencv_core.*;
import org.opencv.imgproc.Imgproc;
import static org.bytedeco.opencv.global.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
Mat mat;
boolean clicked = false;
TextView txv1;
Bitmap bitmap;
Bitmap bitmap1;
AndroidFrameConverter converterToBitmap;
OpenCVFrameConverter.ToIplImage converterToIplImage;
OpenCVFrameConverter.ToMat converterToMat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imgV);
txv1=(TextView)findViewById(R.id.txv1);
imageView.invalidate();
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
bitmap = drawable.getBitmap();
IplImage iplImage = this.bitmapToIplImage(bitmap);
converterToBitmap = new AndroidFrameConverter();
converterToIplImage = new OpenCVFrameConverter.ToIplImage();
converterToMat = new OpenCVFrameConverter.ToMat();
Frame frame = converterToBitmap.convert(bitmap);
mat = converterToIplImage.convertToMat(frame);
cvtColor(mat, mat, Imgproc.COLOR_RGB2GRAY);
Frame frame1 = converterToMat.convert(mat);
bitmap1 = converterToBitmap.convert(frame1);
}
public Bitmap IplImageToBitmap(IplImage iplImage) {
Bitmap bitmap = null;
bitmap = Bitmap.createBitmap(iplImage.width(), iplImage.height(),
Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(iplImage.getByteBuffer());
return bitmap;
}
public IplImage bitmapToIplImage(Bitmap bitmap) {
IplImage iplImage;
iplImage = IplImage.create(bitmap.getWidth(), bitmap.getHeight(),
IPL_DEPTH_8U, 4);
bitmap.copyPixelsToBuffer(iplImage.getByteBuffer());
return iplImage;
}
public void trans(View view) {
if(!clicked){
imageView.setImageBitmap(bitmap1);
clicked = !clicked;
}else{
imageView.setImageBitmap(bitmap);
clicked = !clicked;
}
}
}