Line / Image centering

General discussion about topics related to OpenMV.
Steve472
Posts: 5
Joined: Tue Mar 05, 2019 10:52 am

Line / Image centering

Postby Steve472 » Sat Mar 09, 2019 9:41 am

Hi all,
I am new to Openmv, have bought 2 cameras and played around a bit with the code, but I cant get to understand how to code the system to do what I want.

I have a glue head moving forward (+) along the Y axis (not controlled) and then just move left or right on the X Axis to keep the glue dispenser on the seam (no PWM, just outputs for left and right with a hysteresis.
1)I have tried linear regression, but that does not just move left or right, so then
2)I tried absolute and differential translation and then just used green LED for left indication and red LED for right, I also could not get this to work correctly.
3)The other option is to have a picture of the seam in the middle to compare to and then move left or right to get the 2 images the same.
4)To simplify this, the easiest would be use the camera as a line scan camera and only sample a few lines on the x axis (maybe in the center of the image) and see where the gray scale values change and then move the head left or right to keep this in the middle.

Any advice will be greatly appreciated. :-) , this is really something i have wanted to do for a couple of years now.

Regards

Steve
User avatar
kwagyeman
Posts: 3259
Joined: Sun May 24, 2015 2:10 pm

Re: Line / Image centering

Postby kwagyeman » Sat Mar 09, 2019 12:01 pm

Hi, thanks for the explanation. Um, so, is the camera in a fixed position or is it moving along with the head?

Linear regression is what you want to use. However, you should split the image up into different ROIs (regions of interest) that go up vertically on the image. This assumes however that the ROI is larger than 1 pixel.

If you want to do everything at one pixel per left and right movement then you basically should just write python code to look at the image pixels directly. This will be very slow but maybe it's okay if the head is moving slowly too.

This would basically start with you using linear regression on the whole. Image to find the line and then you start from the bottom of the image and walk up/down. You'd only need to compare the neighborhood of about 5x5 pixels around the current pixel you are at and you'd go towards where the line is. To make this easier you can filter the image first using the lapacian which basically makes edges very strong and everything else 0. Then you just find the max pixel in a 5x5 neighborhood moving up one line each time and you'd move the actuator too.
Nyamekye,
Steve472
Posts: 5
Joined: Tue Mar 05, 2019 10:52 am

Re: Line / Image centering

Postby Steve472 » Sun Mar 10, 2019 4:48 am

The camera moves along the y axis with the glue head. I will have a look at the linear regression code again.

Thank you for pointing me in the right direction :) ,As you saw I had a lot of options to try out.
Steve472
Posts: 5
Joined: Tue Mar 05, 2019 10:52 am

Re: Line / Image centering

Postby Steve472 » Sun Mar 10, 2019 1:03 pm

Hi again Nyamekye,

I have played around a bit today and the linear regression does not seem to work the way I would like. I did however discover that the find lines alogorithm was helpful. What I would like to do is to get the top of the line in the center of the screen. Please help me to understand how I get the x coordinates of a point on the line ( it can be the top or bottom), then compare them to a number ( the center of the screen, screen width/2). If it is greater than x + hysteresis value, turn on green LED, if less than, turn on red LED.
I really have limited computer programming knowledge, I program PLC's so am used to that kind of logic.
Thank you,

Regards

Steve
User avatar
kwagyeman
Posts: 3259
Joined: Sun May 24, 2015 2:10 pm

Re: Line / Image centering

Postby kwagyeman » Sun Mar 10, 2019 5:10 pm

Hi, the line objects returned have a .x1() value or a .y1() value which is the top of the line. They also have a .x2() and .y2() value which is the bottom of the line.

If you want the center of the line from the center of the window I recommend using instead the .rho() and .theta() values the lines have too. This is the location of the line projected away from the top left corner of the image in polar coordinate form. It's far easier to do math on the polar form since you don't run into vertical line singularities.

I.e. is theta() is not 0 then you know the line is rotated in some way. So, it's not straight. If the line is straight then .rho() tells you how far away from the edge of the image the line is. Anyway, so use this formula for following the line:

https://github.com/openmv/openmv-projec ... in.py#L152
Nyamekye,
Steve472
Posts: 5
Joined: Tue Mar 05, 2019 10:52 am

Re: Line / Image centering

Postby Steve472 » Fri May 17, 2019 4:39 am

Hi Nyamekye,

Thank you for your help, it is working well :D

Regards

Steve

Return to “General Topics”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests