एक सरल लेकिन शायद नहीं सबसे कुशल (??) जिस तरह से drawContours
उपयोग करने के लिए दो चित्र बनाने के लिए किया जाएगा: एक कार की समोच्च और एक बाधा के समोच्च के साथ साथ।
फिर and
उन्हें एक साथ, और जो भी बिंदु अभी भी सकारात्मक है, वह चौराहे के बिंदु होंगे।
कुछ स्यूडोकोड (मैं अजगर इंटरफ़ेस उपयोग करती हैं इसलिए सी ++ वाक्य रचना सही नहीं मिलेगा, लेकिन यह काफी सरल आप कन्वर्ट करने के लिए होना चाहिए):
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
अगर मैं intersection
देखो मैं मिल जाएगा एक छवि जो 1 है जहां समोच्च छेड़छाड़ करते हैं और 0 हर जगह।
वैकल्पिक रूप से आप पूरे समोच्च में भरने (न केवल समोच्च लेकिन बहुत अंदर भरें) drawContours(blank.copy(), contours, 0, 1, thickness=-1)
साथ और फिर intersection
छवि आकृति के बीच चौराहे के क्षेत्र में शामिल होंगे सकता है।
स्रोत
2011-12-19 06:04:50
धन्यवाद! बहुत बढ़िया काम करने लगता है। – Madman