Ask Your Question

How to develop a model to detect a point crossed a line?

asked 2020-08-06 22:36:19 -0500

Ajay gravatar image

updated 2020-08-07 11:46:18 -0500

How to develop a system which detects if a object crosses a line.

I am developing a system, basically which tells a object crossed a line. Do I need to get the camera calibration matrix ? Do I need to understand camera calibration or we can use annotation line points(using CVAT) to calculate the math ? If yes and mandatory, I will go on that path. Please advice.

Camera calibration matrix is required(mandatory) for below use case?

enter image description here

I guess, No Camera Calibration matrix required, since camera is just looking from top view

enter image description here

My approach,

  1. Draw lines using CVAT
  2. Write a program using opencv which uses object bouding box center and trip line intersection to calculate the crossing.

I draw lines using CVAT

<polyline label="entry_out" occluded="0" source="manual" points="774.68,499.77;444.65,646.45"> </polyline>
<polyline label="boundary" occluded="0" source="manual" points="406.80,349.70;1031.37,720.00"> </polyline>

My code -

Now when to apply camera calibration ? and How to apply ? Is it required to apply?

def where_it_is(line, cX, cY):
    A, B = line
    aX = A[0]
    aY = A[1]
    bX = B[0]
    bY = B[1]

    val = ((bX - aX) * (cY - aY) - (bY - aY) * (cX - aX))
    thresh = 1e-9
    if val >= thresh:
        return -1
    elif val <= -thresh:
        return 1
        return 0

Please advise, what api and methods I need to use to calibrate the camera using opencv

Complex case

Here Trip line, and object never crosses.

complex case

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-08-07 02:16:24 -0500

berak gravatar image

you would only need calibration if

  • your images show heavy lens distortion
  • you need the coords in camera (3d) space.

as long as you can do it in pixel space, (like your example code above) -- no calibration needed.

please also note, that calibration would require physical access to the resp. camera, which is impossible, if you get a surveillance video from 3rd party

edit flag offensive delete link more


thank you - If I am not able to find the crossing of the object in pixel co-ordinate means. I need to convert each detected objects/tripline ROI to 3D co-ordinates ? Something like this

Ajay gravatar imageAjay ( 2020-08-07 10:07:33 -0500 )edit

@berek - added another complex case where camera is looking a hallway. I was not able to get math right on this. your advice will be very helpful

Ajay gravatar imageAjay ( 2020-08-07 11:45:02 -0500 )edit

Question Tools

1 follower


Asked: 2020-08-06 22:36:19 -0500

Seen: 439 times

Last updated: Aug 07 '20