How set Region of interes ROI on android studio using opencv?

asked 2017-09-01 12:51:37 -0600

Rakzorg gravatar image


Im trying to set a ROI on the videocapture to process the picture only on certain area inside the green lines

image description

heres the code on onCameraViewStarted

    String caption = Integer.valueOf(widthtemp).toString() + "x" + Integer.valueOf(heighttemp).toString();
    Toast.makeText(this, caption, Toast.LENGTH_SHORT).show();

    pt1 = new Point(0,heighttemp);
    pt2 = new Point(widthtemp, heighttemp);
    pt3 = new Point(widthtemp, heighttemp/1.3);
    pt4 = new Point(widthtemp/1.3, heighttemp/1.5);
    pt5 = new Point(widthtemp/4, heighttemp/1.5);
    pt6 = new Point(0, heighttemp/1.3);

    lanemask1 = new Rect(0, 0, (int)(widthtemp/1.3), (int)(heighttemp/1.3));
    lanemask2 = new Rect(0,0,100,100);
    lanemask3 = new Rect(100, 100, 100, 100);

    mRgba = new Mat(height, width, CvType.CV_8UC4);
    Prepos = new Mat(height, width, CvType.CV_8UC4);
    Pospos = new Mat(height, width, CvType.CV_8UC4);

    mGray = new Mat(height, width, CvType.CV_8UC1);
    PreSpos = new Mat(height, width, CvType.CV_8UC1);
    PosSpos = new Mat(height, width, CvType.CV_8UC1);

    mCanny = new Mat (height, width,CvType.CV_8UC4, new Scalar (255,255,255,255));

and heres the code on onCameraFrame

    mRgba = inputFrame.rgba();
    Core.transpose(mRgba, Prepos);
    Imgproc.resize(Prepos, Pospos, Pospos.size(), 0, 0, 0);
    Core.flip(Pospos, mRgba, 1);

    Imgproc.line(mRgba, pt1, pt2, new Scalar(0,255,0), 3);
    Imgproc.line(mRgba, pt2, pt3, new Scalar(0,255,0), 3);
    Imgproc.line(mRgba, pt3, pt4, new Scalar(0,255,0), 3);
    Imgproc.line(mRgba, pt4, pt5, new Scalar(0,255,0), 3);
    Imgproc.line(mRgba, pt5, pt6, new Scalar(0,255,0), 3);
    Imgproc.line(mRgba, pt6, pt1, new Scalar(0,255,0), 3);

i tried using submat to extract a rectangle but without result mRgba.copyTo(mCanny.submat(new Rect(100, 100, 100, 100)));

or maybe i can generate a mask and use bitwise_and but im not sure hoy can i generate a polygon mask using the width and heigth of the camera

i dont know if theres a method where i can filter the rows and columns using a "for" atleast thats how i filtered the matrix on linux but here on android i dont know hoy can i do it

edit retag flag offensive close merge delete