2

I am trying the following in c# Unity3D.

I want to decode a QR Code, and if the identification is successful then draw a green square around the QR code. The square has to track the real object with the decoded text underneath. At the moment I am able to decode the QR, in this way.

ScanQRCodeVuforia is the file where vuforia scan the qr/bar code.

Using the code underneath I am able to detect X and Y which Debug.DrawLine on the screen, but what happens is that the line is parallel to the camera and not on the screen. Just to give you an idea. Do you know how can I represent the line on the canvas? Do you know any other method that I can use to draw a green box around the qr?

ResultPoint[] point = result.ResultPoints;
Debug.Log("X: " + point[0].X + " Y: " + point[1].Y);
Debug.DrawLine(new Vector3(point[0].X, 0), new Vector3(point[0].Y, 0), Color.green, 1000000000f);

I think that this is a good reference to use to detect the four angles points of the QR.

Thanks.


Update!

Using the following code, I am able to draw line on the canvas, but it does not result to be align with the image. This image gives a better idea

var rayX = Camera.main.ScreenPointToRay(new Vector3(point[0].X, point[1].Y));
var rayY = Camera.main.ScreenPointToRay(new Vector3(point[1].Y, point[0].X));
Debug.DrawLine(rayX.origin, rayY.origin, Color.green, 1000000000f);
Community
  • 1
  • 1

1 Answers1

1

First of all, you shouldn't use Debug.DrawLine for actually drawing a Line. Its is used for Debugging Purposes only. To do it the right way, use a LineRenderer

Since you don't seem to have a lot of experience in computer graphics, I'll give you a brief explanation:

What you are trying to achieve is basically visualising the bounding box of an object. According to some other question, the ResultPoint-Array contains 3 points: Bottom-Left, Top-Left and Top-Right. Calculating Bottom-Right is trivial, after that simple draw lines between the points. For example:

ResultPoint[] boundingBoxPoints = result.ResultPoints;
Debug.DrawLine(boundingBoxPoints[0], boundingBoxPoints[1], Color.green, 100f);

And so on.

Sudelnuppe
  • 11
  • 1