1

I'm creating a PapperSoccer project and I have a problem with finding the direction of movement/line. I'm using HoughLinesP to detect lines and it works as well as possible.

I use ROI, in which I am looking for a line, and then I move it accordingly.

So far, I used the difference to calculate the direction.

vector<Vec4i> lines;
HoughLinesP(dst, lines, 1, CV_PI / 180, 10, 5, 15);
Vec4i l = lines[i];

    roznicax1 = x - (l[0] + abs(xRoi));
    roznicax2 = x - (l[2] + abs(xRoi));
    roznicay1 = y - (l[1] + abs(yRoi));
    roznicay2 = y - (l[3] + abs(yRoi));

Then I have a few conditions which, based on the results, check the direction in which the line goes (north, north-east, south, etc.)

However, the problem arises when I leave the ROI out of the image range. Then these differences are incorrect, and thus - incorrectly determines the direction of the movement.

Can I do it in some other way?

https://imgur.com/a/BkSYyqw - a photo of how the program works

Mario Boss
  • 1,784
  • 3
  • 20
  • 43
  • Q: please tell more about context. e.g. why do you need OpenCV to detect the line of the ball ? You program does not know what move the papersoccer player has done when he moved it ? are you using real paper and a camera or something ? – Goodies Jan 13 '19 at 20:35
  • @Goodies Yes, im using Real paper and camera – Adrianna Tyszkiewicz Jan 13 '19 at 21:43

1 Answers1

0

Ok... assuming you have to recognize from a camera image: make sure the line you want to detect (current ball move) is always completely inside the ROI. maybe you could enlarge the ROI to always cover the complete playing field ? and change the color of your current line ? From the Hough result lines, you could pick lines and test the first point of each result line for your color of interest.

If there is only 1 result line, detection has succeeded and you can use an Arc tangens formula on its start point and end point, to find the direction angle (any angle, it should be a near grid angle, that fact could be used for final checkup..

If you can't change the color, you could still use the larger ROI and keep track of all the lines you have. Any new line should be the current move line.

Goodies
  • 1,951
  • 21
  • 26