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?
I guess, No Camera Calibration matrix required, since camera is just looking from top view
My approach,
- Draw lines using CVAT
- 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