Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving info about 2D position #8

Open
CGjungAtGitHub opened this issue Jan 7, 2022 · 14 comments
Open

Receiving info about 2D position #8

CGjungAtGitHub opened this issue Jan 7, 2022 · 14 comments

Comments

@CGjungAtGitHub
Copy link

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.

@RivoLink
Copy link
Owner

RivoLink commented Jan 7, 2022

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.

@nitindf
Copy link

nitindf commented Jan 29, 2022

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

@Meett98
Copy link

Meett98 commented Mar 3, 2023

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

@RivoLink
Copy link
Owner

RivoLink commented Mar 3, 2023

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);

@Meett98
Copy link

Meett98 commented Mar 4, 2023

How to get Z coordinate ??

@RivoLink
Copy link
Owner

RivoLink commented Mar 4, 2023

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

@Meett98
Copy link

Meett98 commented Mar 14, 2023

Can you explain the whole project through a video??

@Helidhimmar
Copy link

Can you explain the whole project through a video??

+1 yes please ,it will useful to us.

@RivoLink
Copy link
Owner

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.

@Meett98
Copy link

Meett98 commented Mar 21, 2023

It will helpful to us.

Thank You. @RivoLink

@Meett98
Copy link

Meett98 commented Apr 1, 2023

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

@RivoLink
Copy link
Owner

RivoLink commented Apr 5, 2023

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.

@Meett98
Copy link

Meett98 commented Apr 10, 2023

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.

@RivoLink
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants