Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Eventually I used the setTo() method to set the color, and then the copyTo() method to copy that color back to the original Mat:

 public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    Mat rgba = inputFrame.rgba();
    org.opencv.core.Size sizeRgba = rgba.size();

    int rows = (int) sizeRgba.height;
    int cols = (int) sizeRgba.width;

    int left = cols / 8;
    int top = rows / 8;
    int width = cols * 3 / 4;
    int height = rows * 3 / 4;

    //get sub-image
    Mat rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);

    //create edgesMat from sub-image
    Imgproc.Canny(rgbaInnerWindow, edgesMat, 100, 100);

    Mat colorEdges = new Mat();
    Mat killMe = colorEdges;
    edgesMat.copyTo(colorEdges);
    Imgproc.cvtColor(colorEdges, colorEdges, Imgproc.COLOR_GRAY2BGRA);

    colorEdges = colorEdges.setTo(greenScalar, edgesMat);
    colorEdges.copyTo(rgbaInnerWindow, edgesMat);

    killMe.release();
    colorEdges.release();
    rgbaInnerWindow.release();

    return rgba;
}