4

OpenCVの正規化された相関関係を使用するにはどうすればよいですか?誰かがコードサンプルを提供できますか?

私の問題: ネジ頭の画像があり、ネジの中心を見つける必要があります。だから私はOpenCV相関を使用することを考えています、それは良い考えですか?

以下のリンクの下にサンプル画像があります。

http://imageshack.us/photo/my-images/685/screw1.png/

OpenCVでの相関関係のコードサンプルを提供してください。どのように使用されますか?相関関数の出力は何ですか?相関関数はネジの位置を提供しますか?

4

1 に答える 1

13

関数を探していると思いますcv::matchTemplate

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);
于 2012-07-04T06:35:43.023 に答える