Ask Your Question
0

Photo capturing without imgproc rectangle

asked 2017-08-09 23:14:40 -0600

Junru gravatar image

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;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-10 00:26:40 -0600

berak gravatar image

this is a "shallow" copy (it will copy the Mat header & the data pointer, but NOT the pixels):

  mRgba = inputFrame.rgba();

same here:

  Mat mRgba2 = inputFrame.rgba();

so, both Mats point to the same data now !

if you draw something into mRgba2, it will show up in mRgba, too.

to avoid it, you need a "deep" copy:

  Mat mRgba2 = inputFrame.rgba().clone();
edit flag offensive delete link more

Comments

Hi, thank you for your helping. I get the output. :)

Junru gravatar imageJunru ( 2017-08-10 07:32:55 -0600 )edit

just curious, if you don't want to see it, why do all that drawing at all ?

berak gravatar imageberak ( 2017-08-10 07:36:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-09 23:14:40 -0600

Seen: 339 times

Last updated: Aug 10 '17