derenlei / Unity_Detection2AR

Localize 2D image object detection in 3D Scene with Yolo in Unity Barracuda and ARFoundation.
https://derenlei.medium.com/object-detection-with-localization-using-unity-barracuda-and-arfoundation-794b4eff02f8
MIT License
222 stars 61 forks source link

How to place 3d model on bounding box position #21

Closed syedali1621 closed 3 years ago

syedali1621 commented 3 years ago

I am using yolov2tiny and showing 3d model at center of camera but when i start the app from left or right position and detect object then it show the 3d model on left or right position but i want to change the 3d model position to show on the same place where bounding box is visible. How can i get bounding box position ? I can change it using transform.position but i want to know how to get bounding box position?

Thank you

derenlei commented 3 years ago

Hello. I didn't get your question.

If you want to convert a 2d position on the screen to a 3d position in AR scene, you can call this method: https://github.com/derenlei/Unity_Detection2AR/blob/main/Assets/Scripts/AnchorCreator.cs#L36-L70.

It performs raycast based on given (x,y) and uses the closest hit as the AR scene position. Then pair the hit position with the given bounding box. I assume you want to use the hit position to create a 3d model anchor.

The default 2d position of bounding box is the center of it, as raycast has a higher chance to actually hit the object. You could try something else.