Controlling a drone mid flight using opencv

I am new to drone programming, so please excuse my lack of technical knowledge. I want to make a drone that flies using a dronekit script on a predefined path that is uploaded as a mission on the flight controller. But an opencv human detection script will also be running simultaneously with the camera feed from the onboard camera as its input. When the opencv script sees a human, I want the drone to pause the mission and change its mode from ‘AUTO’ to ‘LOITER’ and stay there till instructed to resume the mission where it was left.
How can I achieve this?
Any suggestions will be appreciated!!!
Thank you.