{"id":1928,"date":"2022-01-13T15:12:57","date_gmt":"2022-01-13T07:12:57","guid":{"rendered":"http:\/\/139.9.1.231\/?p=1928"},"modified":"2022-01-13T17:20:45","modified_gmt":"2022-01-13T09:20:45","slug":"calcbackproject","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/13\/calcbackproject\/","title":{"rendered":"\u56fe\u50cf\u76f4\u65b9\u56fe\u53cd\u5411\u6295\u5f71"},"content":{"rendered":"\n<h3 id=\"_2\">\u7406\u8bba<a href=\"http:\/\/woshicver.com\/FifthSection\/4_10_4_%E7%9B%B4%E6%96%B9%E5%9B%BE-4%EF%BC%9A%E7%9B%B4%E6%96%B9%E5%9B%BE%E5%8F%8D%E6%8A%95%E5%BD%B1\/#_2\"><\/a><\/h3>\n\n\n\n<p>\u8fd9\u662f\u7531**Michael J. Swain**\u548c**Dana H. Ballard**\u5728\u4ed6\u4eec\u7684\u8bba\u6587\u300a<strong>\u901a\u8fc7\u989c\u8272\u76f4\u65b9\u56fe\u7d22\u5f15<\/strong>\u300b\u4e2d\u63d0\u51fa\u7684\u3002<\/p>\n\n\n\n<p><strong>\u7528\u7b80\u5355\u7684\u8bdd\u8bf4\u662f\u4ec0\u4e48\u610f\u601d<\/strong>\uff1f\u5b83\u7528\u4e8e\u56fe\u50cf\u5206\u5272\u6216\u5728\u56fe\u50cf\u4e2d\u67e5\u627e\u611f\u5174\u8da3\u7684\u5bf9\u8c61\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u5b83\u521b\u5efa\u7684\u56fe\u50cf\u5927\u5c0f\u4e0e\u8f93\u5165\u56fe\u50cf\u76f8\u540c\uff08\u4f46\u53ea\u6709\u4e00\u4e2a\u901a\u9053\uff09\uff0c\u5176\u4e2d\u6bcf\u4e2a\u50cf\u7d20\u5bf9\u5e94\u4e8e\u8be5\u50cf\u7d20\u5c5e\u4e8e\u6211\u4eec\u7269\u4f53\u7684\u6982\u7387\u3002\u7528\u66f4\u7b80\u5355\u7684\u8bdd\u6765\u8bf4\uff0c\u4e0e\u5176\u4f59\u90e8\u5206\u76f8\u6bd4\uff0c\u8f93\u51fa\u56fe\u50cf\u5c06\u5728\u53ef\u80fd\u6709\u5bf9\u8c61\u7684\u533a\u57df\u5177\u6709\u66f4\u591a\u7684\u767d\u8272\u503c\u3002\u597d\u5427\uff0c\u8fd9\u662f\u4e00\u4e2a\u76f4\u89c2\u7684\u89e3\u91ca\u3002\uff08\u6211\u65e0\u6cd5\u4f7f\u5176\u66f4\u7b80\u5355\uff09\u3002\u76f4\u65b9\u56fe\u53cd\u6295\u5f71\u4e0ecamshift\u7b97\u6cd5\u7b49\u914d\u5408\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>\u6211\u4eec\u8be5\u600e\u4e48\u505a\u5462<\/strong>\uff1f\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u56fe\u50cf\u7684\u76f4\u65b9\u56fe\uff0c\u5176\u4e2d\u5305\u542b\u6211\u4eec\u611f\u5174\u8da3\u7684\u5bf9\u8c61\uff08\u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\u662f\u80cc\u666f\uff0c\u79bb\u5f00\u64ad\u653e\u5668\u7b49\uff09\u3002\u5bf9\u8c61\u5e94\u5c3d\u53ef\u80fd\u586b\u5145\u56fe\u50cf\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6548\u679c\u3002\u800c\u4e14\u989c\u8272\u76f4\u65b9\u56fe\u6bd4\u7070\u5ea6\u76f4\u65b9\u56fe\u66f4\u53ef\u53d6\uff0c\u56e0\u4e3a\u5bf9\u8c61\u7684\u989c\u8272\u5bf9\u6bd4\u7070\u5ea6\u5f3a\u5ea6\u662f\u5b9a\u4e49\u5bf9\u8c61\u7684\u597d\u65b9\u6cd5\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u8be5\u76f4\u65b9\u56fe\u201c\u53cd\u6295\u5f71\u201d\u5230\u9700\u8981\u627e\u5230\u5bf9\u8c61\u7684\u6d4b\u8bd5\u56fe\u50cf\u4e0a\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u8ba1\u7b97\u51fa\u5c5e\u4e8e\u80cc\u666f\u7684\u6bcf\u4e2a\u50cf\u7d20\u7684\u6982\u7387\u5e76\u5c06\u5176\u663e\u793a\u51fa\u6765\u3002\u5728\u9002\u5f53\u7684\u9608\u503c\u4e0b\u4ea7\u751f\u7684\u8f93\u51fa\u4f7f\u6211\u4eec\u4ec5\u83b7\u5f97\u80cc\u666f\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u73b0\u5728\u6709\u4e00\u4e2a\u56db\u884c\u56db\u5217\u5f97\u7070\u5ea6\u56fe\uff0c\u5b83\u5f97\u7070\u5ea6\u503c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/pic1.zhimg.com\/80\/v2-415f95ae752bd9e035cb4f7dad827408_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u8bf4\u8fd9\u5e45\u56fe\u6709\u4ec0\u4e48\u7279\u5f81\u5462\uff1f\u76f4\u89c2\u4e0a\u770b\u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u8fb9\u89d2\uff0c\u4f46\u8fd9\u662f\u76f4\u89c2\u4e0a\uff0c\u600e\u4e48\u8868\u793a\u51fa\u6765\u5462\uff1f\u6df1\u5ea6\u5b66\u4e60\u662f\u9760\u795e\u7ecf\u7f51\u7edc\u9ed1\u7bb1\u8ba1\u7b97\u51fa\u6765\u5f97\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u76f4\u65b9\u56fe\u3002<\/p>\n\n\n\n<p>\u90a3\u6211\u4eec\u5c31\u8ba1\u7b97\u8fd9\u5e45\u7070\u5ea6\u56fe\u5f97\u76f4\u65b9\u56fe\uff0c\u5982\u679c\u4ee5\u7ec4\u8ddd\u4e3a1\u8ba1\u7b97\u76f4\u65b9\u56fe\u5e76\u53cd\u5411\u6295\u5f71\u5230\u539f\u56fe\uff0c\u5f97\u5230\u5f97\u4e3a\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized is-style-default\"><img loading=\"lazy\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-6bd20cfed9f9762eeafe7bccc076a0af_1440w.jpg\" alt=\"\" width=\"178\" height=\"111\"\/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u5927\u6982\u8868\u8ff0\u4e00\u4e0b\u8fb9\u89d2\u5f97\u7279\u5f81\uff1a\u5de6\u4e0b\u89d2\u67096\u4e2a\u50cf\u7d20\u503c\u76f8\u540c\u5f97\u4e09\u89d2\u5f62\u533a\u57df\uff0c\u4e2d\u95f4\u659c\u5411\u4e0b\u6709\u56db\u4e2a\u50cf\u7d20\u503c\u76f8\u540c\u5f97\u8fb9\u754c\u7ebf\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8fd9\u5c31\u662f\u7528\u76f4\u65b9\u56fe\u5f97\u5230\u5f97\u8fb9\u89d2\u5f97\u7279\u5f81\u3002<\/p>\n\n\n\n<p>\u90a3\u5982\u679c\u4ee5\u7ec4\u8ddd\u4e3a2\u8ba1\u7b97\u76f4\u65b9\u56fe\u5462\uff1f\u53cd\u5411\u6295\u5f71\u540e\u4e3a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/pic2.zhimg.com\/80\/v2-3034920d75370159f424d97280b24911_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u7279\u5f81\u63cf\u8ff0\u5f97\u66f4\u4e3a\u5e7f\u6cdb\u4e86\uff0c\u5c31\u50cf\u6df1\u5ea6\u5b66\u4e60\u91cc\uff0c\u63d0\u53d6\u66f4\u9ad8\u5c42\u6b21\u5f97\u7279\u5f81\uff0c\u867d\u7136\u66f4\u4e3a\u666e\u9002\uff0c\u4f46\u4e5f\u4f1a\u5ffd\u7565\u6389\u4e00\u4e9b\u7ec6\u8282\u7279\u5f81\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5c31\u662f\u62ff\u8fd9\u4e2a\u53cd\u5411\u6295\u5f71\u6240\u8868\u8fbe\u5f97\u7279\u5f81\u4fe1\u606f\uff0c\u53bb\u548c\u6574\u5e45\u56fe\u505a\u5bf9\u6bd4\uff0c\u6765\u5f97\u5230\u7279\u5f81\u76f8\u4f3c\u5f97\u90e8\u5206\uff0c\u8fbe\u5230\u5206\u5272\u5f97\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8981\u5f52\u4e00\u5316\u5462\uff0c\u76f4\u65b9\u56fe\u53cd\u5411\u6295\u5f71\u5230\u539f\u56fe\u540e\uff0c\u539f\u56fe\u5404\u4f4d\u7f6e\u8868\u793a\u7684\u662f\u6574\u5e45\u56fe\u4e2d\u7b49\u4e8e\u8be5\u70b9\u50cf\u7d20\u503c\u7684\u6570\u91cf\uff0c\u5f52\u4e00\u5316\u540e\u5c31\u53d8\u6210\u6982\u7387\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/pic4.zhimg.com\/80\/v2-0a52fec16406b64c3c35740246f9e8e7_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u901a\u8fc7\u56fe\u50cf\u7684\u53cd\u5411\u6295\u5f71\u77e9\u9635\uff0c\u6211\u4eec\u5b9e\u9645\u4e0a\u628a\u539f\u56fe\u50cf\u7b80\u5355\u5316\u4e86\uff0c\u7b80\u5355\u5316\u7684\u8fc7\u7a0b\u5b9e\u9645\u4e0a\u5c31\u662f\u63d0\u53d6\u51fa\u56fe\u50cf\u7684\u67d0\u4e2a\u7279\u5f81\u3002\u6240\u4ee5\u4ee5\u540e\u6211\u4eec\u53ef\u4ee5\u7528\u8fd9\u4e2a\u7279\u5f81\u6765\u5bf9\u6bd4\u4e24\u5e45\u56fe\uff0c\u5982\u679c\u4e24\u5e45\u56fe\u7684\u53cd\u5411\u6295\u5f71\u77e9\u9635\u76f8\u4f3c\u6216\u76f8\u540c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u5224\u5b9a\u8fd9\u4e24\u5e45\u56fe\u8fd9\u4e2a\u7279\u5f81\u662f\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<h3 id=\"numpy\">Numpy\u4e2d\u7684\u7b97\u6cd5<a href=\"http:\/\/woshicver.com\/FifthSection\/4_10_4_%E7%9B%B4%E6%96%B9%E5%9B%BE-4%EF%BC%9A%E7%9B%B4%E6%96%B9%E5%9B%BE%E5%8F%8D%E6%8A%95%E5%BD%B1\/#numpy\"><\/a><\/h3>\n\n\n\n<ol><li>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u8ba1\u7b97\u6211\u4eec\u8981\u67e5\u627e\u7684\u5bf9\u8c61\uff08\u4f7f\u5176\u4e3a\u201c M\u201d\uff09\u548c\u8981\u641c\u7d22\u7684\u56fe\u50cf\uff08\u4f7f\u5176\u4e3a\u201c I\u201d\uff09\u7684\u989c\u8272\u76f4\u65b9\u56fe\u3002<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> cv2 <strong>as<\/strong> cvfrom matplotlib <strong>import<\/strong> pyplot <strong>as<\/strong> plt\n<em>#roi\u662f\u6211\u4eec\u9700\u8981\u627e\u5230\u7684\u5bf9\u8c61\u6216\u5bf9\u8c61\u533a\u57df<\/em>\nroi = cv.imread('rose_red.png')\nhsv = cv.cvtColor(roi,cv.COLOR_BGR2HSV)\n<em>#\u76ee\u6807\u662f\u6211\u4eec\u641c\u7d22\u7684\u56fe\u50cf<\/em>\ntarget = cv.imread('rose.png')\nhsvt = cv.cvtColor(target,cv.COLOR_BGR2HSV)\n<em># \u4f7f\u7528calcHist\u67e5\u627e\u76f4\u65b9\u56fe\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528np.histogram2d\u5b8c\u6210<\/em>\nM = cv.calcHist(&#91;hsv],&#91;0, 1], <strong>None<\/strong>, &#91;180, 256], &#91;0, 180, 0, 256] )\nI = cv.calcHist(&#91;hsvt],&#91;0, 1], <strong>None<\/strong>, &#91;180, 256], &#91;0, 180, 0, 256] )<\/code><\/pre>\n\n\n\n<ol><li>\u6c42\u51fa\u6bd4\u503cR=MI\u3002\u7136\u540e\u53cd\u5411\u6295\u5f71R\uff0c\u5373\u4f7f\u7528R\u4f5c\u4e3a\u8c03\u8272\u677f\uff0c\u5e76\u4ee5\u6bcf\u4e2a\u50cf\u7d20\u4f5c\u4e3a\u5176\u5bf9\u5e94\u7684\u76ee\u6807\u6982\u7387\u521b\u5efa\u4e00\u4e2a\u65b0\u56fe\u50cf\u3002\u5373<code>B(x,y) = R[h(x,y),s(x,y)]<\/code>&nbsp;\u5176\u4e2dh\u662f\u8272\u8c03\uff0cs\u662f\u50cf\u7d20\u5728(x\uff0cy)\u7684\u9971\u548c\u5ea6\u3002\u4e4b\u540e\uff0c\u5e94\u7528\u6761\u4ef6B(x,y)=min[B(x,y),1]\u3002<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>h,s,v = cv.split(hsvt)\nB = R&#91;h.ravel(),s.ravel()]\nB = np.minimum(B,1)\nB = B.reshape(hsvt.shape&#91;:2])<\/code><\/pre>\n\n\n\n<ol><li>\u73b0\u5728\u5bf9\u5706\u76d8\u5e94\u7528\u5377\u79ef\uff0cB=D\u2217B\uff0c\u5176\u4e2dD\u662f\u5706\u76d8\u5185\u6838\u3002<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>disc = cv.getStructuringElement(cv.MORPH_ELLIPSE,(5,5))\ncv.filter2D(B,-1,disc,B)\nB = np.uint8(B)\ncv.normalize(B,B,0,255,cv.NORM_MINMAX)<\/code><\/pre>\n\n\n\n<ol><li>\u73b0\u5728\u6700\u5927\u5f3a\u5ea6\u7684\u4f4d\u7f6e\u7ed9\u4e86\u6211\u4eec\u7269\u4f53\u7684\u4f4d\u7f6e\u3002\u5982\u679c\u6211\u4eec\u671f\u671b\u56fe\u50cf\u4e2d\u6709\u4e00\u4e2a\u533a\u57df\uff0c\u5219\u5bf9\u5408\u9002\u7684\u503c\u8fdb\u884c\u9608\u503c\u5904\u7406\u5c06\u83b7\u5f97\u4e0d\u9519\u7684\u7ed3\u679c\u3002<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>ret,thresh = cv.threshold(B,50,255,0) <\/code><\/pre>\n\n\n\n<h3 id=\"opencv\">OpenCV\u7684\u53cd\u6295\u5f71<a href=\"http:\/\/woshicver.com\/FifthSection\/4_10_4_%E7%9B%B4%E6%96%B9%E5%9B%BE-4%EF%BC%9A%E7%9B%B4%E6%96%B9%E5%9B%BE%E5%8F%8D%E6%8A%95%E5%BD%B1\/#opencv\"><\/a><\/h3>\n\n\n\n<p>OpenCV\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5185\u5efa\u7684\u51fd\u6570**cv.calcBackProject**()\u3002\u5b83\u7684\u53c2\u6570\u51e0\u4e4e\u4e0e**cv.calchist**()\u51fd\u6570\u76f8\u540c\u3002\u5b83\u7684\u4e00\u4e2a\u53c2\u6570\u662f\u76f4\u65b9\u56fe\uff0c\u4e5f\u5c31\u662f\u7269\u4f53\u7684\u76f4\u65b9\u56fe\uff0c\u6211\u4eec\u5fc5\u987b\u627e\u5230\u5b83\u3002\u53e6\u5916\uff0c\u5728\u4f20\u9012\u7ed9backproject\u51fd\u6570\u4e4b\u524d\uff0c\u5e94\u8be5\u5bf9\u5bf9\u8c61\u76f4\u65b9\u56fe\u8fdb\u884c\u5f52\u4e00\u5316\u3002\u5b83\u8fd4\u56de\u6982\u7387\u56fe\u50cf\u3002\u7136\u540e\u6211\u4eec\u7528\u5706\u76d8\u5185\u6838\u5bf9\u56fe\u50cf\u8fdb\u884c\u5377\u79ef\u5e76\u5e94\u7528\u9608\u503c\u3002\u4e0b\u9762\u662f\u6211\u7684\u4ee3\u7801\u548c\u7ed3\u679c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> cv2 <strong>as<\/strong> cv\nroi = cv.imread('rose_red.png')\nhsv = cv.cvtColor(roi,cv.COLOR_BGR2HSV)\ntarget = cv.imread('rose.png')\nhsvt = cv.cvtColor(target,cv.COLOR_BGR2HSV)\n<em># \u8ba1\u7b97\u5bf9\u8c61\u7684\u76f4\u65b9\u56fe<\/em>\nroihist = cv.calcHist(&#91;hsv],&#91;0, 1], <strong>None<\/strong>, &#91;180, 256], &#91;0, 180, 0, 256] )\n<em># \u76f4\u65b9\u56fe\u5f52\u4e00\u5316\u5e76\u5229\u7528\u53cd\u4f20\u7b97\u6cd5<\/em>\ncv.normalize(roihist,roihist,0,255,cv.NORM_MINMAX)\ndst = cv.calcBackProject(&#91;hsvt],&#91;0,1],roihist,&#91;0,180,0,256],1)\n<em># \u7528\u5706\u76d8\u8fdb\u884c\u5377\u79ef<\/em>\ndisc = cv.getStructuringElement(cv.MORPH_ELLIPSE,(5,5))\ncv.filter2D(dst,-1,disc,dst)\n<em># \u5e94\u7528\u9608\u503c\u4f5c\u4e0e\u64cd\u4f5c<\/em>\nret,thresh = cv.threshold(dst,50,255,0)\nthresh = cv.merge((thresh,thresh,thresh))\nres = cv.bitwise_and(target,thresh)\nres = np.vstack((target,thresh,res))\ncv.imwrite('res.jpg',res)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7406\u8bba \u8fd9\u662f\u7531**Michael J. Swain**\u548c**Dana H. Ballard**\u5728\u4ed6\u4eec\u7684\u8bba\u6587\u300a\u901a\u8fc7 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/13\/calcbackproject\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u56fe\u50cf\u76f4\u65b9\u56fe\u53cd\u5411\u6295\u5f71<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1928"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=1928"}],"version-history":[{"count":10,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1928\/revisions"}],"predecessor-version":[{"id":1975,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1928\/revisions\/1975"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=1928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=1928"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=1928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}