我正在使用OPENCV检测银行支票,同时相机开始预览并且工作正常。 每当检测到矩形时我都会从Mat数据中获取位图值,但我想只有文档图像而不是整个帧位图(以矩形形式检测到的部分),请指导我的配偶。
先谢谢,如果某些格式错误,请致歉。
参考:https://github.com/iyotetsuya/RectangleDetection
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CameraPreview cameraPreview = (CameraPreview) findViewById(R.id.camera_preview);
cameraPreview.setCallback((data, camera) -> {
CameraData cameraData = new CameraData();
cameraData.data = data;
cameraData.camera = camera;
subject.onNext(cameraData);
});
cameraPreview.setOnClickListener(v -> cameraPreview.focus());
DrawView drawView = (DrawView) findViewById(R.id.draw_layout);
subject.concatMap(cameraData ->
OpenCVHelper.getRgbMat(new MatData(), cameraData.data, cameraData.camera))
.concatMap(matData -> OpenCVHelper.resize(matData, 400, 400))
.map(matData -> {
matData.resizeRatio = (float) matData.oriMat.height() / matData.resizeMat.height();
matData.cameraRatio = (float) cameraPreview.getHeight() / matData.oriMat.height();
return matData;
})
.concatMap(this::detectRect)
.compose(mainAsync())
.subscribe(matData -> {
if (drawView != null) {
if (matData.cameraPath != null) {
drawView.setPath(matData.cameraPath);
mat = matData.oriMat;
bitmap = Bitmap.createBitmap(mat.width(), mat.height(), Bitmap.Config.ARGB_8888);
} else {
drawView.setPath(null);
}
drawView.invalidate();
}
});
}