Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Photo capturing without imgproc rectangle

image description

As the image shown the pink rectangle support box is in the photo. May I know that is possible to remove the rectangle box after I capture the image?

This is my onCameraFrame code

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();
    Mat mRgba2 = inputFrame.rgba();

    Point point = new Point((double) (mRgba2.width() / 4), (double) (mRgba2.height() / 5));
    Point point2 = new Point((double) (mRgba2.width() / 4 * 3), (double) (mRgba2.height() / 5 * 4));
    Imgproc.rectangle(mRgba2, point, point2, new Scalar(255, 0, 255, 255), 4);
    MatOfPoint2f approxCurve = new MatOfPoint2f();
    if (this.mIsColorSelected) {
        this.mColorDetector.process(mRgba2);
        List<MatOfPoint> contours = this.mColorDetector.getContours();
        for (int i = 0; i < contours.size(); i++) {
            MatOfPoint2f contour2f = new MatOfPoint2f((contours.get(i)).toArray());
            Imgproc.approxPolyDP(contour2f, approxCurve, Imgproc.arcLength(contour2f, true) * 0.02, true);
            Rect rect = Imgproc.boundingRect(new MatOfPoint(approxCurve.toArray()));

            if (rect.tl().y <= point.y || rect.tl().y >= point2.y || rect.tl().x <= point.x || rect.tl().x >= point2.x || rect.br().y <= point.y || rect.br().y >= point2.y || rect.br().x <= point.x || rect.br().x >= point2.x) {
                Imgproc.rectangle(mRgba2, rect.tl(), rect.br(), this.CONTOUR_COLOR, 3, 8, 0);
            } else {
                Imgproc.putText(mRgba2, "Captured!", new Point(rect.tl().x, rect.tl().y - 10), 1, 2, new Scalar(255, 0, 0, 255), 2);
                Imgproc.rectangle(mRgba2, rect.tl(), rect.br(), new Scalar(255, 0, 0, 255), 3, 8, 0);
            }
        }
    }

    return mRgba;
}