¿Cómo usar la correlación normalizada de OpenCV?

How do I use OpenCV's normalized correlation? Could anyone provide a code sample?

Mi problema: I have a screw head image and need to find the center of the screw. So I am thinking of using OpenCV correlation, is that a good idea?

You can find an example image under the link below:


Please provide me with a code sample for correlation in OpenCV. How is it used? What is the output of the correlation function? Will the correlation function provide the screw location?

preguntado el 04 de julio de 12 a las 02:07

1 Respuestas

Creo que estas buscando cv::matchTemplate función:

cv::Mat image;  // Your input image
cv::Mat templ;  // Your template image of the screw 
cv::Mat result; // Result correlation will be placed here

// Do template matching across whole image
cv::matchTemplate(image, templ, result, CV_TM_CCORR_NORMED);

// Find a best match:
double minVal, maxVal;
cv::Point minLoc, maxLoc;
cv::minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc);

// Regards to documentation the best match is in maxima location
// (http://opencv.willowgarage.com/documentation/cpp/object_detection.html)

// Move center of detected screw to the correct position:  
cv::Point screwCenter = maxLoc + cv::Point(templ.cols/2, templ.rows/2);

respondido 15 nov., 15:20

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.