Приведенный ниже Java-код используется для предварительной обработки изображения, обнаружения маркеров и, наконец, выделения и отображения их в ImageView на экран телефона.
Код: Выделить всё
//Rotate to correct orientation
Mat frame = rotateMat(imageProxyToMat(imageProxy), 270);
List markerCorners = new ArrayList();
Mat markerIds = new Mat();
Mat greyImage = new Mat();
//Convert to greyscale
Imgproc.cvtColor(frame, greyImage, Imgproc.COLOR_BGR2GRAY);
//Increase contrast
Mat contrastGreyImage = new Mat();
Core.normalize(greyImage, contrastGreyImage, 0, 255, Core.NORM_MINMAX);
//Apply gaussian blur
Mat gaussianBlurImage = new Mat();
Imgproc.GaussianBlur(contrastGreyImage, gaussianBlurImage, new Size(5, 5), 0);
//Apply binary threshold to better find markers
Mat thresholdedFrame = new Mat();
Imgproc.adaptiveThreshold(contrastGreyImage, thresholdedFrame, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 15, 5);
Mat imageToDetect = gaussianBlurImage;
Imgcodecs.imwrite(getFilesDir() + "/imageToDetect.jpg", imageToDetect);
//Detect markers in the current frame
arucoDetector.detectMarkers(imageToDetect, markerCorners, markerIds);
Objdetect.drawDetectedMarkers(frame, markerCorners, markerIds);
//Convert to bitmap
Bitmap bitmap = Bitmap.createBitmap(frame.cols(), frame.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(frame, bitmap);
//Display on the ImageView
liveImageView.setImageBitmap(bitmap);
Код макета ImageView:
Код: Выделить всё

Подробнее здесь: https://stackoverflow.com/questions/793 ... d-studio-j