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.

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.

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

edit retag close merge delete

Sort by ยป oldest newest most voted

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

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 https://www.scratchapixel.com/lessons...

( 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

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