Receiving info about 2D position
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.
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.
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
how to display xyz cordinates of the detected markers on screen and when we change the position of marker then it will get updated.
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);
How to get Z coordinate ??
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
Can you explain the whole project through a video??
Can you explain the whole project through a video??
+1 yes please ,it will useful to us.
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.
It will helpful to us.
Thank You. @RivoLink
@RivoLink I want to display x,y,z cordinates of tvec on the graph, So how it can be done?
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.
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.
Hi @Meett98 Can you create a new issue for this and and I will happy to help you.