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.
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.
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.
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: