I'm currently working on a program that should draw a small image onto the camera frame. With Android OpenCV, you do have the following function to process a frame:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat rgba = inputFrame.rgba();
mDetector.setFrame(rgba);
mDetector.processFrame();
return rgba;
}
Where the Mat rgba then gets displayed on the screen. My Detector should now process the frame rgba (change it). Here is the relevant code:
public void processFrame() {
// (1) Doesn't work
Rect roi = new Rect(0, 0, 100, 100);
Mat submat = mOutputFrame.submat(roi);
Mat image = new Mat(100, 100, CvType.CV_8UC3, new Scalar(0,0,0));
image.copyTo(submat);
// (2) Does work
// --- mComparatorImage is the same size as mOutputFrame.
// --- mComparatorImage is 8bit greyscale, mOutputFrame is the rgba CameraFrame
mComparatorImage = mComparatorHolder.getCurrentImage();
mComparatorImage.copyTo(mOutputFrame);
// (3) Should work (but doesn't)
Imgproc.resize(mComparatorImage, mResizedImageClone, new Size (200, 100));
Mat bSubmat = mOutputFrame.submat(new Rect(0, 0, 200, 100));
mResizedImageClone.copyTo(bSubmat);
}
What I'm trying to do is to copy a resized version of mComparatorImage into the camera frame that is referenced by mOutputFrame (mOutputFrame = rgba).
So I tried doing (3). FYI: mResizedImageClone is of type Mat and is initialized as a new Mat()
Doing (3) doesn't change the mOutputFrame.
(2) Then I tried copying the whole mComparatorImage (type Mat and same size as mOutputFrame) to mOutputFrame. This worked suprisingly.
(1) Then I thought the problem has to be something with submat, because copying the big image works, but copying a small version of it into mOutputFrame doesnt. So I tried copying a little black image into mOutputFrame. This doesn't work either, although I followed other answers here.
What could be the problem? There is no error, but the camera frame stays the same in (1) and (3)
If you need any additional info, let me know.
Isa