Aruco-Android icon indicating copy to clipboard operation
Aruco-Android copied to clipboard

Receiving info about 2D position

Open CGjungAtGitHub opened this issue 4 years ago • 14 comments

Hi, is there a method in OpenCV to fetch the 2D points, inside the image, where the markers were detected? Background of my question is: I want to sort the detected markers, by their position from left to right.

Thank you.

CGjungAtGitHub avatar Jan 07 '22 05:01 CGjungAtGitHub

Hi,

In this file ImageActivity.java, at the line 174, you have the 4 corners 3D positions of each marker, your can use them if you want to sort the detected markers.

Tell me if that doesn't help you.

RivoLink avatar Jan 07 '22 09:01 RivoLink

Hi, is there a method in OpenCV to fetch the 2D points, inside the image, where the markers were detected? Background of my question is: I want to sort the detected markers, by their position from left to right.

Thank you.

The coordinates are in the corners parameter in Aruco.detectMarkers(gray, dictionary, corners, ids, parameters) which is a List of Mat objects . There is an item in this list for every detected marker id. So, you can try accessing them like this,

Mat coordinates = corners.get(i); //get item in List
List<Point> corners_xy = new ArrayList<>(4);
for (int r = 0; r < coordinates.rows(); r++) {
    for (int c = 0; c < coordinates.cols(); c++) {
        corners_xy.add(new Point((int)coordinates.get(r,c)[0], (int)coordinates.get(r,c)[1])); // x,y point   
    }
}  
//Access the coordinates of 4 corners
Point top_left = corners_xy.get(0);
Point top_right = corners_xy.get(1);
Point bottom_right = corners_xy.get(2);
Point bottom_left = corners_xy.get(3);

And insert the above code here,

Aruco.detectMarkers(gray, dictionary, corners, ids, parameters);
if(corners.size()>0){
    Aruco.drawDetectedMarkers(rgb, corners, ids);
    for(int i = 0;i<ids.toArray().length;i++) {
        //insert code here

nitindf avatar Jan 29 '22 08:01 nitindf

how to display xyz cordinates of the detected markers on screen and when we change the position of marker then it will get updated.

Meett98 avatar Mar 03 '23 10:03 Meett98

With @nitindf codes

You can do :

Point top_left = corners_xy.get(0);

int x = (int)top_left.x;
int y = (int)top_left.y;

String text = String.format("(x: %d, y: %d)", x, y);

Point text_position = new Point(
	rgb.cols()/2,
	rgb.rows()/2
);

int font_face = Core.FONT_HERSHEY_SIMPLEX;
double font_scale = 1.0;
Scalar font_color = new Scalar(255, 255, 0);

Imgproc.putText(rgb, text, text_position, font_face, font_scale, font_color);

RivoLink avatar Mar 03 '23 13:03 RivoLink

How to get Z coordinate ??

Meett98 avatar Mar 04 '23 11:03 Meett98

For a marker, we have 2 positions :

  • The position in the real world which has 3d coordinates (x,y,z), and
  • The position in the screen which only has 2d coordinates (x, y)

For the 2d coordinates you can have it with above code

For the 3d coordinates, they are stored in tvec=[x,y,z], for more information you can refer here : Get the distance from camera to an OpenCV ArUco Marker

RivoLink avatar Mar 04 '23 17:03 RivoLink

Can you explain the whole project through a video??

Meett98 avatar Mar 14 '23 10:03 Meett98

Can you explain the whole project through a video??

+1 yes please ,it will useful to us.

Helidhimmar avatar Mar 14 '23 10:03 Helidhimmar

Hello

I don't know how to make videos, but I will write an article to explain the project and I will share the link with you.

Thank you for your interest in this project.

RivoLink avatar Mar 20 '23 05:03 RivoLink

It will helpful to us.

Thank You. @RivoLink

Meett98 avatar Mar 21 '23 09:03 Meett98

@RivoLink I want to display x,y,z cordinates of tvec on the graph, So how it can be done?

Meett98 avatar Apr 01 '23 06:04 Meett98

Hi @Meet98, sorry for delay.

I created a new branch feature/tvec-coords for your request.

Here's a gist: RivoLink/ImageActivity.java

Open an image containing a marker with the Aruco Android app to view tvec coordinates

May it help you, You can create a new issue if you have more questions.

RivoLink avatar Apr 05 '23 09:04 RivoLink

Hey @RivoLink Thanks for your efforts. The thing is app is working correctly but sometimes device gets hang or app crashes and i also added another activity in project in which i plot the graph of tvec , so the problem is sometimes app works perfectly but sometimes it gets crash, so is there any specific reason for this issue? and if you have any solution then tell me so that it will helpful for me.

Meett98 avatar Apr 10 '23 10:04 Meett98

Hi @Meett98 Can you create a new issue for this and and I will happy to help you.

RivoLink avatar Apr 10 '23 11:04 RivoLink