Ask Your Question
0

Aruco java, trying to get marker IDs [solved]

asked 2019-04-11 17:23:47 -0600

Agus gravatar image

updated 2019-04-13 04:02:04 -0600

Hi all, first of all thanks for this amazing library. I´m working on my final degree project, using a Lego Mindstorm EV3 that uses my Android phone camera as its eyes. I´ve implemented an android app wich uses the Aruco module (openCVLibrary 3.4.0 dev), everything works perfectly, the app detects and draws all the Aruco markers, but I´m trying to get the IDs from the IDs Mat, how can I get those IDs stored in the Mat?

public void drawDetectedMarkers(Mat mRgba) {
    Aruco.drawDetectedMarkers(mRgba, corners, arucoIDs, new Scalar(0, 255, 0));
    Imgproc.putText(mRgba, "Aruco:"+ **arucoIDs.get(1,1)**, new Point(30, 30), 3, 1, new Scalar(255, 0, 0, 255), 1);   
}

I´ve tried using arucoIDs.get() function, but it doesn´t give me the marker ID that I need, depending on the ID, the robot will move to the left or right side. Thanks so much and regards

edit retag flag offensive close merge delete

Comments

we need to see the type of arucoIDs. how do you declare it ?

also, c++, java, python all start indexing at 0,not 1. if you only have 1 marker, (1,1) is probably invalid

berak gravatar imageberak ( 2019-04-12 01:40:32 -0600 )edit

Hi @berak,thanks for your answer. "arucoIDs" is a Mat type, declared at onCameraViewStarted as:

public Mat arucoIDs = new Mat();

First the app detect the Aruco markers using: Aruco.detectMarkers(imageAruco, dictionary, corners, arucoIDs);

Then it draws the detected markers using:

Aruco.drawDetectedMarkers(mRgba, corners, arucoIDs, new Scalar(0, 255, 0));
Agus gravatar imageAgus ( 2019-04-12 06:23:44 -0600 )edit

This is the Aruco.java code called from drawDetectedMarkers function:

//javadoc: drawDetectedMarkers(image, corners, ids, borderColor)
    public static void drawDetectedMarkers(Mat image, List<Mat> corners, Mat ids, Scalar borderColor)
    {
        Mat corners_mat = Converters.vector_Mat_to_Mat(corners);
        drawDetectedMarkers_0(image.nativeObj, corners_mat.nativeObj, ids.nativeObj, borderColor.val[0], borderColor.val[1], borderColor.val[2], borderColor.val[3]);

        return;
    }
Agus gravatar imageAgus ( 2019-04-12 06:24:11 -0600 )edit

please try to print out the shape/size of your arucoIDs

berak gravatar imageberak ( 2019-04-12 06:27:57 -0600 )edit

Using "putText" function I get these info:

Imgproc.putText(mRgba, "Aruco:"+ arucoIDs.get(0,0), new Point(30, 80), 3, 0.5, new Scalar(255, 0, 0, 255), 1);

image description

 Imgproc.putText(mRgba, "Aruco:"+ arucoIDs.size(), new Point(30, 80), 3, 0.5, new Scalar(255, 0, 0, 255), 1);

image description

That Aruco marker comes from the DICT_4X4_50 dictionary.

Agus gravatar imageAgus ( 2019-04-12 06:43:06 -0600 )edit

i bet with 2 markers, the next is at ids.get(0,1);, 0,2...0,3... etc.

berak gravatar imageberak ( 2019-04-12 07:07:22 -0600 )edit

I´ve solved the problem, I´ve got a String value using toString() function:

public void drawDetectedMarkers(Mat mRgba) {
        Aruco.drawDetectedMarkers(mRgba, corners, arucoIDs, new Scalar(0, 255, 0));

        Imgproc.putText(mRgba, "Aruco:"+ Arrays.toString(arucoIDs.get(0,0)), new Point(30, 80), 3, 0.5, new Scalar(255, 0, 0, 255), 1);
    }

Now I got this:

image description

So from now, the robot can "decide" depending on the marker ID if it should turn left or right.

Maybe there is a way to get an integer value (5) instead of a double value (5.0?

Thanks berak.

Agus gravatar imageAgus ( 2019-04-12 09:31:11 -0600 )edit

Mat.get() returns a double[], whatever is in it. you're safe here to simply cast it like

int id = (int)(ids.get(i, 0)[0]);
berak gravatar imageberak ( 2019-04-13 02:02:09 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2019-04-13 03:58:55 -0600

Agus gravatar image

Yeah, that´s what I was looking for, thanks a lot berak!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-04-11 17:23:47 -0600

Seen: 2,340 times

Last updated: Apr 13 '19