What opencv api is useful for me to detect is an object touched a drawed line in a image? Thanks

What opencv api or skill is useful for me to detect is an object touched the red line in a image?
I can use object detection to detect the rectangle of the ship, but i have only the yellow rectangle information, but even the yellow rect touched the red rect, it doesn’t mean the ship is touched the red line. so how could i detect the ship’s body touched the line?
Thanks
ship_line2

“semantic segmentation” or “instance segmentation”.

a deep learning technique that gives you a per-pixel mask for the object. OpenCV: samples/dnn/segmentation.cpp

you could also try background segmentation, which requires a video, and the object to move/change markedly over time. OpenCV: Tutorials for bgsegm module