X, Y values

General discussion about topics related to OpenMV.
User avatar
robert_d1968
Posts: 29
Joined: Thu May 03, 2018 9:44 am

X, Y values

Postby robert_d1968 » Thu May 03, 2018 10:10 am

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
User avatar
kwagyeman
Posts: 2275
Joined: Sun May 24, 2015 2:10 pm

Re: X, Y values

Postby kwagyeman » Thu May 03, 2018 8:01 pm

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.
Nyamekye,
User avatar
robert_d1968
Posts: 29
Joined: Thu May 03, 2018 9:44 am

Re: X, Y values

Postby robert_d1968 » Fri May 04, 2018 1:33 am

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.
User avatar
kwagyeman
Posts: 2275
Joined: Sun May 24, 2015 2:10 pm

Re: X, Y values

Postby kwagyeman » Fri May 04, 2018 2:43 am

matrix.rect()
Nyamekye,
User avatar
kwagyeman
Posts: 2275
Joined: Sun May 24, 2015 2:10 pm

Re: X, Y values

Postby kwagyeman » Fri May 04, 2018 2:44 am

Nyamekye,
User avatar
robert_d1968
Posts: 29
Joined: Thu May 03, 2018 9:44 am

Re: X, Y values

Postby robert_d1968 » Sat May 05, 2018 9:34 am

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

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 3 guests