jcmellado / js-aruco

JavaScript library for Augmented Reality applications
Other
598 stars 132 forks source link

Reference #18

Closed CosmicChild closed 7 years ago

CosmicChild commented 7 years ago

Hi, I find your work really interesting, but I was wondering if you have a reference to this library. I cannot really understand how it works just by reading the sample codes.

I'm trying to recognize one (or ideally two) markers, all I would need to retrieve is their position and size on the canvas and, if possible, rotation.

Any help will be appreciated,

Thanks!

jcmellado commented 7 years ago

The main page of the project has a detailed explanation: https://github.com/jcmellado/js-aruco

In short, create an AR.Detector object, invoke the detect method on it, and you'll get an array of detected markers. Each marker is an JavaScript object with its id and corners on the canvas. Corners are points (x, y), so from there you should be able to calculate the size and rotation on the canvas.

CosmicChild commented 7 years ago

Thank you for your answer. I have now implemented this, but I'm always getting a zero count for markers (markers.length is always 0).

Could it be that the marker is not perfect? I made it by hand so the squares are not quite squared. I imagine there is sort of a tolerance margin, but I don't know how much it is.

Thanks again. marker

jcmellado commented 7 years ago

Only the following combinations per row are valid: white - black - black - black - black white - black - white - white - white black - white - black - black - white black - white - white - white - black

In your marker the first row is invalid: white black black white white

This is clearly explained in the main page of the project: https://github.com/jcmellado/js-aruco

CosmicChild commented 7 years ago

Sorry, it's actually because the picture is rotated. But I think I'm following the right pattern. I'm going to try with a different one in any case, just to make sure.

I do get the contours from detector.candidates, but not the marker corners from detector.detect

Thanks.

marker

jcmellado commented 7 years ago

Ops, yes, silly me, sorry about that.

I cut the marker from your image, take the camera, and pointed it to the monitor:

image

The marker is ok, but the background is very dark in your original image and the library can not isolate the marker.

The "debug" demo could be useful here for a better understanding of the issue: https://jcmellado.github.io/js-aruco/debug/debug.html

CosmicChild commented 7 years ago

Thank you! it was really a matter of contrast with the background. I added another layer of all-white cells around the all-black cells. It actually became a 9x9 grid instead of 7x7, but it seems to work fine like this.