Un simple pero quizás no sea el (??) forma más eficiente sería utilizar drawContours
para crear dos imágenes: una con el contorno del coche y una con el contorno del obstáculo.
Luego, and
juntos, y cualquier punto que siga siendo positivo serán los puntos de intersección.
Algunos pseudocódigo (yo uso la interfaz de Python por lo que no sería obtener el derecho de sintaxis de C++, pero debe ser lo suficientemente simple para que usted pueda convertir):
import numpy as np # just for matrix manipulation, C/C++ use cv::Mat
# find contours.
contours,h = findContours(img, mode=RETR_LIST, method=CHAIN_APPROX_SIMPLE)
# Suppose this has the contours of just the car and the obstacle.
# create an image filled with zeros, single-channel, same size as img.
blank = np.zeros(img.shape[0:2])
# copy each of the contours (assuming there's just two) to its own image.
# Just fill with a '1'.
img1 = drawContours(blank.copy(), contours, 0, 1)
img2 = drawContours(blank.copy(), contours, 1, 1)
# now AND the two together
intersection = np.logical_and(img1, img2)
# OR we could just add img1 to img2 and pick all points that sum to 2 (1+1=2):
intersection2 = (img1+img2)==2
Si miro intersection
que recibirá imagen que es 1 donde los contornos se cruzan y 0 en cualquier otro lado.
Si lo prefiere puede rellenar el contorno de toda (no sólo el contorno, pero rellenar el interior también) con drawContours(blank.copy(), contours, 0, 1, thickness=-1)
y luego la imagen intersection
contendrá el área de intersección entre las curvas de nivel.
¡Gracias! Parece que funciona bastante bien. – Madman