1

I have consumed the google cloud vision api to recognize a document with a table, but sometimes the image will be a little rotated, im triyng to get the value using the boundingPoly of the key i want, but how do i get it if it's not on the same 'y'.

I was thinking of making a 'line' above and below the boundingBox and finding if the point is between that, but i dont know how to do it.

[18] => Array
(
  [description] => Date
  [boundingPoly] => Array
  (
    [vertices] => Array
    (
      [0] => Array
      (
        [x] => 698
        [y] => 289
      )
      [1] => Array
      (
        [x] => 729
        [y] => 289
      )
      [2] => Array
      (
        [x] => 729
        [y] => 301
      )
      [3] => Array
      (
        [x] => 698
        [y] => 301
      )
    )
  )
)
[66] => Array
(
  [description] => 25/03/2019
  [boundingPoly] => Array
  (
    [vertices] => Array
    (
      [0] => Array
      (
        [x] => 1007
        [y] => 290
      )
      [1] => Array
      (
        [x] => 1131
        [y] => 290
      )
      [2] => Array
      (
        [x] => 1131
        [y] => 307
      )
      [3] => Array
      (
        [x] => 1007
        [y] => 307
      )
    )
  )
)
1

1 Answer 1

1

Given points (x1, y1) and (x2, y2), you can determine whether a third point (x3, y3) is collinear as follows.
First, compute the slope m1 = (y2 - y1) / (x2 - x1).
Next, compute the slope m2 = (y3 - y2) / (x3 - x2).
The lines are collinear if and only if m1 = m2. Collinear means they lie on the same line.
This fails only for vertical lines; those cases can be handled separately as follows: x1 = x2 = x3, then the points are collinear; if x1 = x2 or x2 = x3 but not x1 = x2 = x3, then the third point is not collinear with the first two.


Given lines (m1, h1) and (m2, h2), you can determine whether a point (x3, y3) is "between" these lines as follows.
Compute y1 = h1 + m1 * x3 and y2 = h2 + m2 * x3.
Then, the point is between the lines if and only if y1 <= y3 <= y2 or y2 <= y3 <= y1.
2. If both lines are vertical lines x = x1 and x = x2, then the point is between the lines if and only if x1 <= x3 <= x2 or x2 <= x3 <= x1.
If exactly one of the lines is vertical (assume it's the first one for ease of notation), then compute x2 = (y3 - h2) / m2; then the point is between the lines if and only if either x1 <= x3 <= x2 or x2 <= x3 <= x1.

(If one of your lines is vertical and the other is horizontal, I guess the only point in between them is their point of intersection).

2
  • Im sorry, im trying to understand the second formulae, but what is the (m1, h1) Apr 11, 2019 at 12:28
  • @WeslleyRocha m1 is the slope of the first line, and h1 is the first line's y-intercept. Those two things uniquely define any (non-vertical) line.
    – Patrick87
    Apr 11, 2019 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.