{"id":2523,"date":"2011-11-29T13:33:24","date_gmt":"2011-11-28T19:33:24","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/2523"},"modified":"2011-11-29T13:38:58","modified_gmt":"2011-11-29T04:38:58","slug":"%e7%9b%b8%e9%96%a2%e4%bf%82%e6%95%b0%e3%82%92%e8%a8%88%e7%ae%97%e3%82%92%e8%87%aa%e4%bd%9c%e3%81%99%e3%82%8b%e5%ae%8c%e6%88%90","status":"publish","type":"post","link":"https:\/\/www.moonmile.net\/blog\/archives\/2523","title":{"rendered":"\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3092\u81ea\u4f5c\u3059\u308b(\u5b8c\u6210)"},"content":{"rendered":"<p>\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30de\u30c3\u30c1\u306e\u95a2\u6570\u3092\u81ea\u4f5c\u3057\u307e\u3059\u3002<br \/>\ntemplmatch.cpp \u5185\u306e\u5143\u30cd\u30bf\u3092\u4f7f\u3063\u3066\u3082\u826f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u76f8\u52a0\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\u3068\u3053\u308d\u304c\u30011\/w*h \u3067\u56fa\u5b9a\u5024\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30de\u30b9\u30af\u753b\u50cf\u3092\u6e21\u3059\u3068\u5927\u5e45\u306b\u66f8\u304d\u63db\u3048\u306b\u306a\u3063\u3066\u3057\u307e\u3046&#8230;\u3068\u3044\u3046\u306e\u3068\u3001\u884c\u5217\u5168\u4f53\u3092\u30d5\u30fc\u30ea\u30a8\u6f14\u7b97\u5bfe\u8c61\u306b\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u3082\u305d\u3082\u30de\u30b9\u30af\u753b\u50cf\u3092\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u3002\u3063\u3066\u306e\u304c\u81ea\u4f5c\u306e\u7406\u7531\u3067\u3059\u3002<\/p>\n<p>\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3092\u81ea\u4f5c\u3059\u308b(\u9014\u4e2d) | Moonmile Solutions Blog<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/archives\/2509\">http:\/\/www.moonmile.net\/blog\/archives\/2509<\/a><\/p>\n<p>\u524d\u56de\u306f\u3001RGB \u30c1\u30e3\u30f3\u30cd\u30eb\u3092\u5e73\u5766\u306b\u52a0\u7b97\u3057\u3066\u3044\u305f\u306e\u3067\u8aa4\u691c\u51fa\u591a\u304f\u306a\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u5143\u306e\u95a2\u6570\u3068\u540c\u3058\u3088\u3046\u306b\u30c1\u30e3\u30f3\u30cd\u30eb\u6bce\u306b\u76f8\u52a0\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\u3068\u3044\u3046\u65b9\u5f0f\u306b\u5909\u3048\u307e\u3057\u305f\u3002\u3059\u308b\u3068\u3001cv::matchTemplate \u3068\u540c\u3058\u7d50\u679c\u304c\u5f97\u3089\u308c\u3066\u3044\u307e\u3059\uff08\u53b3\u5bc6\u306b\u30c1\u30a7\u30c3\u30af\u3057\u305f\u8a33\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u9055\u3044\u306f\u3067\u3066\u304f\u308b\u304b\u3082\uff09\u3002<\/p>\n<p>\u3053\u306e\u3042\u305f\u308a\u3001CV_TM_CCOEFF_NORMED \u3092\u6307\u5b9a\u3057\u305f\u3068\u304d\u306e\u691c\u8a3c\u7528\u306e\u95a2\u6570\u3092\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u306d&#8230;\u5148\u306f\u9577\u305d\u3046\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/ \u5b9f\u753b\u50cf\u306e\u4f4d\u7f6e(dx,dy)\u306b\u5bfe\u3057\u3066\u3001\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\r\ndouble crossCorr( const cv::Mat&amp; img, const cv::Mat&amp; templ, const cv::Mat&amp; mask, int dx, int dy )\r\n{\r\n\tint cnt = 0;\r\n\t\/\/ \u5bfe\u8c61\u30c9\u30c3\u30c8\u6570\u3092\u53d6\u5f97\u3059\u308b\r\n\tfor ( int y=0; y&lt;templ.rows; ++y ) {\r\n\t\tfor ( int x=0; x&lt;templ.cols; ++x ) {\r\n\t\t\tif ( mask.at&lt;char&gt;(y,x) == 0 )\r\n\t\t\t\tcontinue;\r\n\t\t\tcnt++;\r\n\t\t}\r\n\t}\r\n\r\n\t\/\/ \u5206\u5b50(numerator)\r\n\tdouble numerator = 0.0;\r\n\t\/\/ \u5206\u6bcd(denominator)\r\n\tdouble denominator_templ = 0.0;\r\n\tdouble denominator_img   = 0.0;\r\n\r\n\t\/\/ \u30c1\u30e3\u30f3\u30cd\u30eb\u6bce\uff08RGB\uff09\u306b\u8a08\u7b97\u3059\u308b\r\n\tfor ( int k=0; k&lt;3; ++k ) {\r\n\t\tdouble templMean = 0.0;\t\/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u76f8\u52a0\u5e73\u5747\r\n\t\tdouble imgMean = 0.0;\t\/\/ \u5b9f\u753b\u50cf\u306e\u76f8\u52a0\u5e73\u5747\r\n\r\n\t\tfor ( int y=0; y&lt;templ.rows; ++y ) {\r\n\t\t\tfor ( int x=0; x&lt;templ.cols; ++x ) {\r\n\t\t\t\tif ( mask.at&lt;char&gt;(y,x) == 0 )\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tcv::Vec3b v1 = templ.at&lt;cv::Vec3b&gt;(y,x);\r\n\t\t\t\tcv::Vec3b v2 = img.at&lt;cv::Vec3b&gt;(y+dy,x+dx);\r\n\t\t\t\ttemplMean += v1&#x5B;k];\r\n\t\t\t\timgMean += v2&#x5B;k];\r\n\t\t\t}\r\n\t\t}\r\n\t\ttemplMean \/= (double)cnt;\r\n\t\timgMean   \/= (double)cnt;\r\n\r\n\t\tfor ( int y=0; y&lt;templ.rows; ++y ) {\r\n\t\t\tfor ( int x=0; x&lt;templ.cols; ++x ) {\r\n\t\t\t\tif ( mask.at&lt;char&gt;(y,x) == 0 )\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tcv::Vec3b v1 = templ.at&lt;cv::Vec3b&gt;(y,x);\r\n\t\t\t\tcv::Vec3b v2 = img.at&lt;cv::Vec3b&gt;(y+dy,x+dx);\r\n\t\t\t\tnumerator += (v1&#x5B;k] - templMean)*(v2&#x5B;k] - imgMean);\r\n\t\t\t\tdenominator_templ += (v1&#x5B;k] - templMean)*(v1&#x5B;k] - templMean);\r\n\t\t\t\tdenominator_img += (v2&#x5B;k] - imgMean)*(v2&#x5B;k] - imgMean);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\/\/ \u5206\u6bcd\u3092\u8a08\u7b97\u3059\u308b\r\n\tdouble denominator = sqrt(denominator_templ)*sqrt(denominator_img);\r\n\t\/\/ \u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\r\n\tdouble corr = numerator\/denominator;\r\n\r\n\treturn corr;\r\n}\r\n\r\n\/\/ \u5b9f\u753b\u50cf\u306e\u3059\u3079\u3066\u306b\u5bfe\u3057\u3066\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\r\nvoid MatchTemplate( const cv::Mat&amp; img, const cv::Mat&amp; templ, cv::Mat&amp; result, const cv::Mat&amp; mask )\r\n{\r\n\tcv::Size corrsize(img.cols-templ.cols, img.rows-templ.rows);\r\n\tresult.create(corrsize, CV_64F);\r\n\r\n\tfor ( int y=0; y&lt;corrsize.height; ++y ) {\r\n\t\tfor ( int x=0; x&lt;corrsize.width; ++x ) {\r\n\t\t\tdouble corr = crossCorr( img, templ, mask,x,y );\r\n\t\t\tresult.at&lt;double&gt;(y,x) = corr ;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30de\u30c3\u30c1\u30f3\u30b0\u6cd5\u3092\u4f7f\u3046\u3068\u304d\u306b\u3001OpenCV \u306e cv::matchTemplate \u3067\u306f\u77e9\u5f62\u306b\u7e1b\u3089\u308c\u308b\u306e\u3067\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u305f\u3044\u753b\u50cf\u306e\u80cc\u666f\u306b\u3042\u308b\u3082\u306e\u306b\u5f71\u97ff\u3092\u53d7\u3051\u3066\u3057\u307e\u3046&#8230;\u3068\u8003\u3048\u308b\u308f\u3051\u3067\u3001\u6559\u5e2b\u753b\u50cf\u3092<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_01.jpg\" border=\"0\" \/><\/p>\n<p>\u306e\u3088\u3046\u306b\u3001\u80cc\u666f\u3092\u629c\u304f\u305f\u3081\u306e\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f5c\u308c\u3070\u3088\u3044\u306e\u3067\u306f\u306a\u3044\u304b\uff1f\u3068\u3044\u3046\u60f3\u5b9a\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u5b9f\u969b\u306b\u5b9f\u9a13\u3092\u3057\u3066\u307f\u308b\u3068\u3001<\/p>\n<p>\u25a0\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_02org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_02thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u25a0\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u3046\u5834\u5408<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_03org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_03thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306f\u3001\u3044\u3061\u3054\u306e\u99d2\u3092\u8aa4\u691c\u51fa\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u3063\u305f\u5834\u5408\u306f\u307f\u304b\u3093\u306e\u99d2\u3060\u3051\u3092\u691c\u51fa\u3057\u3066\u3044\u308b&#8230;\u3068\u3044\u3046\u304b\u3001\u5de6\u4e0b\u306e\u767d\u3044\u9818\u57df\u3092\u307c\u308d\u307c\u308d\u3068\u8aa4\u691c\u51fa\u3057\u3066\u3044\u307e\u3059\u306d orz \u3002<br \/>\n\u304a\u305d\u3089\u304f\u3001\u30de\u30c3\u30c1\u30f3\u30b0\u306e\u8a55\u4fa1\u95a2\u6570\u306b\u76f8\u95a2\u4fc2\u6570\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u306e\u767d\u3044\u9818\u57df\u306e\u8272\u30e0\u30e9\u304c\u3061\u3087\u3046\u3069\u307f\u304b\u3093\u306e\u6559\u5e2b\u753b\u50cf\u306e\u8272\u30e0\u30e9\u3068\u3042\u3063\u3066\u3044\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u3068\u60f3\u50cf\u3067\u304d\u307e\u3059\uff08\u76f8\u52a0\u5e73\u5747\u304b\u3089\u306e\u5dee\u306b\u306a\u308b\u306e\u3067\u3001\u5b9f\u753b\u50cf\u306e\u8272\u306e\u30e0\u30e9\u304c\u305f\u307e\u305f\u307e\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u3066\u3044\u308b\u3068\u3001\u3053\u3046\u3044\u3046\u5177\u5408\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u304b\u3068\uff09\u3002\u3053\u308c\u306f\u3001RGB \u5024\u306e\u76f8\u95a2\u4fc2\u6570\u3092\u4f7f\u3046\u3068\u304d\u306e\u6b20\u70b9\u3067\u306f\u306a\u304b\u3068\u3002<\/p>\n<p>\u3042\u3068\u3001\u8208\u5473\u6df1\u3044\u30de\u30c3\u30c1\u30f3\u30b0\u306e\u4ed5\u65b9\u3068\u3057\u3066\u3001<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_04org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_04thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u306e\u3088\u3046\u306b\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306a\u6559\u5e2b\u753b\u50cf\u306e\u8272\u304c\u3046\u307e\u304f\u80cc\u666f\u306e\u753b\u50cf\u306b\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u4f8b\u304c\u3042\u308a\u307e\u3059\u3002\u307f\u304b\u3093\u306e\u8272\u304c\u30aa\u30ec\u30f3\u30b8\u306a\u306e\u3067\u3001\u307e\u3093\u306a\u304b\u306b\u30aa\u30ec\u30f3\u30b8\u304c\u3042\u308b\u9818\u57df\u3092\u3055\u304c\u3057\u3066\u3057\u307e\u3046\u305f\u3081\u3067\u3059\u3002\u3053\u308c\u306f\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u3063\u305f\u3068\u304d\u306e\u6b20\u70b9\u3067\u3059\u306d\u3002<\/p>\n<p>\u540c\u3058\u753b\u50cf\u3067\u30de\u30b9\u30af\u3092\u4f7f\u308f\u306a\u3044\u3068\u6b21\u306e\u56f3\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_05org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_05thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u53f3\u4e0a\u306e\u307f\u304b\u3093\u306e\u99d2\u3060\u3051\u304c\u691c\u51fa\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f\u80cc\u666f\u753b\u50cf\u3092\u30de\u30c3\u30c1\u30f3\u30b0\u3055\u305b\u3066\u3044\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u3044\u305f\u3044\u306e\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u80cc\u666f\u304c\u5207\u308a\u66ff\u308f\u3063\u305f\u5834\u5408\u306b\u3082\u5bfe\u5fdc\u3055\u305b\u305f\u3044\u305f\u3081\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_06org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/11\/wpid-dworkblogimage20111129_06thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u80cc\u666f\u5dee\u5206\u3092\u53d6\u3063\u3066\u80cc\u666f\u753b\u50cf\u306e\u307b\u3046\u3092\u5207\u308a\u53d6\u308b\u306e\u3082\u3072\u3068\u3064\u306e\u65b9\u6cd5\u306a\u306e\u3067\u3059\u304c\u3001\u691c\u7d22\u5bfe\u8c61\u3068\u306a\u308b\u6559\u5e2b\u753b\u50cf\u306e\u307b\u3046\u306e\u80cc\u666f\u753b\u50cf\u3092\u5207\u308a\u53d6\u3063\u3066\u3057\u307e\u3046\u307b\u3046\u304c\u3088\u308a\u6709\u52b9\u3067\u306f\u306a\u3044\u304b\u306a\u3068\u3002<br \/>\n\u307e\u3042\u3001\u3053\u306e\u56f3\u306e\u5834\u5408\u3001\u307f\u304b\u3093\u3060\u3051\u3067\u306a\u304f\u30ad\u30a6\u30a4\uff08\u304b\u306a\uff1f\uff09\u3082\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u8a33\u3067\u3001\u3053\u308c\u3082\u8abf\u7bc0\u306b\u5fc5\u8981\u3042\u308a\u3067\u3059\u304c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30de\u30b9\u30af\u753b\u50cf\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30de\u30c3\u30c1\u306e\u95a2\u6570\u3092\u81ea\u4f5c\u3057\u307e\u3059\u3002 templmatch.cpp \u5185\u306e\u5143\u30cd\u30bf\u3092\u4f7f\u3063\u3066\u3082\u826f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u76f8\u52a0\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\u3068\u3053\u308d\u304c\u30011\/w*h \u3067\u56fa\u5b9a\u5024\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30de\u30b9\u30af\u753b\u50cf\u3092\u6e21\u3059\u3068\u5927 &hellip; <a href=\"https:\/\/www.moonmile.net\/blog\/archives\/2523\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,22,35],"tags":[],"class_list":["post-2523","post","type-post","status-publish","format-standard","hentry","category-dev","category-c","category-opencv"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=2523"}],"version-history":[{"count":2,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2523\/revisions"}],"predecessor-version":[{"id":2525,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/2523\/revisions\/2525"}],"wp:attachment":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=2523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=2523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=2523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}