Ask Your Question
0

Detect the center of a tag

asked 2020-02-19 11:00:40 -0500

Pigeon gravatar image

Hello,

How would I go about getting the position of the center of a tag (QR Code, AprilTag...) using opencv ? I only find stuff about decoding the tag or the centroid of a shape. The idea is that i track this tag in a 2d plane, and with the center of the tag position, i get the x and y that I can then use as parameters on an electronics project.

Thanks for any input,

edit retag flag offensive close merge delete

Comments

1

I honestly dont want to troll - maybe its so easy - assuming you do this on an image
1) get bounding box of the object(in your case the tag) as a rectangle
2)
centerX = x + w/2
centerY = y + h/2

holger gravatar imageholger ( 2020-02-19 12:45:01 -0500 )edit

i'v thought of this, just trasnform the tag into a shape, and get centroid of the shape, but if the image captured as another similar shape on it, it could give me bad info. I made a small matlab version of it using the shadow through semi transparent glass, basically i would binarize the image (pure black and white) and calculate the centroid of the shape. But just having an arm creating shadow would mess up with the xy position. Thats why I wanted to use a tag, so that only 1 thing gets recognized

Pigeon gravatar imagePigeon ( 2020-02-19 14:01:45 -0500 )edit
1

@Pigeon unless I am not understanding your question, you probably just have to run a QR code detector first then find the center of the returned bounding box using @holger suggestion. No need to transform it into a shape and so forth. The correctness of the center coordinates will be heavily dependent of the results of the detector.

eshirima gravatar imageeshirima ( 2020-02-19 14:11:21 -0500 )edit

oh right, i'll give this a try, i had in my mind the shape centroid, but yeah no need to transform it, thx

Pigeon gravatar imagePigeon ( 2020-02-19 16:59:12 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-02-20 07:02:59 -0500

updated 2020-02-20 07:03:57 -0500

You just need to run a QR code detector and find the center of the returned bounding box. OpenCV already has a QRCodeDetector class just for this exact function. You can use the method detectAndDecode() to search for a QR code and it returns a bounding box with the QR code region. From this box compute its center as suggested by @holger and voila, you have attained the centroid. Refer to this tutorial having both C++ and Python implementations.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-02-19 10:59:59 -0500

Seen: 250 times

Last updated: Feb 20 '20