Hello everybody, I just got my open MV M7 and I'm getting the hang of it.

With that said, I'm using it to scan a 10x10 data matrix, it does this with ease, really great. I'm having a problem with I need to be able to tell how far from the center of the camera the matrix

is off center.

So far, I'm unable to solve this issue. I need to put out the serial port the values of x, y how far it's off, I looked at the find circles which does provide x, y, r values But I must admit I'm at a loss as how to go about adding this to my project.

#for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10):

# img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))

# print(c)

How can this be done in the 10x10 library?

I do write a lot of firmware for micro controllers and computers but it's all in basic, I'm not new to python but not great at it... I really need some help on this one,

Thanks for any help you can provide

## X, Y values

- robert_d1968
**Posts:**29**Joined:**Thu May 03, 2018 9:44 am

### Re: X, Y values

Hi, if you have a 10x10 data matrix then you should have a returned ROI for it. I.e. x/y/w/h.

So the center of that is:

cx = x + (w / 2)

cy = y + (h / 2)

Then if you want to know the difference from the center of the image...

Do:

xoff = (img.width() / 2) - cx

yoff = (img.height() / 2) - cy

This works as long as the image is not rotated. If it's rotated then you have to get the centroid of the 4 corners. This is easy though too. The centroid of the 4 corners is the sum of all x positions divided by 4 for x and the sum of all y positions divided by 4 for y. I believe the rotation of the data matrix is a returned attribute so you can use that to determine if it's not straight.

So the center of that is:

cx = x + (w / 2)

cy = y + (h / 2)

Then if you want to know the difference from the center of the image...

Do:

xoff = (img.width() / 2) - cx

yoff = (img.height() / 2) - cy

This works as long as the image is not rotated. If it's rotated then you have to get the centroid of the 4 corners. This is easy though too. The centroid of the 4 corners is the sum of all x positions divided by 4 for x and the sum of all y positions divided by 4 for y. I believe the rotation of the data matrix is a returned attribute so you can use that to determine if it's not straight.

Nyamekye,

- robert_d1968
**Posts:**29**Joined:**Thu May 03, 2018 9:44 am

### Re: X, Y values

Hello there,

Thank-you for the help, Now I know I'm a newbie when I ask this question.

What is a ROI, and where do I find it?

I ended up trying out : print("N",matrix.payload(),"X",matrix.x(),"Y",matrix.y(),"R",matrix.rotation())

So, this does show the returned information in the serial area, now I'll just do the math on it and it should be good to go.

Thank-you for the help, Now I know I'm a newbie when I ask this question.

What is a ROI, and where do I find it?

I ended up trying out : print("N",matrix.payload(),"X",matrix.x(),"Y",matrix.y(),"R",matrix.rotation())

So, this does show the returned information in the serial area, now I'll just do the math on it and it should be good to go.

- robert_d1968
**Posts:**29**Joined:**Thu May 03, 2018 9:44 am

### Re: X, Y values

Hey thank you for that link in the above post, that is a lot of unknown information that I did not know about

Also that link leads to a lot more information that I need.

My hats off to you kind sir,

Robert

Also that link leads to a lot more information that I need.

My hats off to you kind sir,

Robert

### Who is online

Users browsing this forum: No registered users and 4 guests