{"id":19288,"date":"2024-04-09T23:28:59","date_gmt":"2024-04-09T15:28:59","guid":{"rendered":"https:\/\/www.wqeq.com\/?p=19288"},"modified":"2024-04-10T11:30:00","modified_gmt":"2024-04-10T03:30:00","slug":"%e7%ae%97%e6%b3%95%e5%ad%a6%e4%b9%a0%ef%bc%88%e4%ba%8c%ef%bc%89-%e5%9b%be%e5%83%8f%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.wqeq.com\/?p=19288","title":{"rendered":"\u7b97\u6cd5\u5b66\u4e60\uff08\u4e8c\uff09\u2014\u2014\u56fe\u50cf\u5904\u7406"},"content":{"rendered":"<p>\u9996\u5148\u9700\u8981\u51c6\u5907\u56fe\u7247\uff0c\u6700\u597d\u5e26\u6709\u4eba\u7269\u7684\u3002\u6211\u8fd9\u91cc\u51c6\u5907\u4e86\u4e24\u5f20\u56fe\u7247<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19292 aligncenter\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/test.jpg\" alt=\"\" width=\"366\" height=\"368\" \/><\/p>\n<p style=\"text-align: center;\">C:\\Users\\jiangli\\Desktop\\11\\\u56fe\u7247\\test.jpg<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19291 aligncenter\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/face.png\" alt=\"\" width=\"410\" height=\"261\" \/><\/p>\n<p style=\"text-align: center;\">C:\\Users\\jiangli\\Desktop\\11\\\u56fe\u7247\\face.jpg<\/p>\n<h2>\u5bfc\u5165\u5de5\u5177\u5305<\/h2>\n<p>[code lang=&#8221;python&#8221;]# \u56fe\u50cf\u5de5\u5177\u5305<br \/>\nimport cv2<br \/>\n# \u6570\u5b66\u5de5\u5177\u5305<br \/>\nimport numpy as ny[\/code]<\/p>\n<h2>\u5c55\u793a\u56fe\u7247<\/h2>\n<p>[code lang=&#8221;python&#8221;]img = cv2.imread(&quot;C:\\\\Users\\\\jiangli\\\\Desktop\\\\11\\\\\u56fe\u7247\\\\test.jpg&quot;)<br \/>\ncv2.imshow(&quot;test111&quot;,img)<br \/>\n# cv2.imwrite(&quot;D:\\\\pyspace-yolodemo\\\\images\\\\test.jpg&quot;,img) #\u4fdd\u5b58\u56fe\u7247\u5230\u6307\u5b9a\u4f4d\u7f6e<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        imshow\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u8be5\u5c55\u793a\u56fe\u7247\u8fdb\u884c\u547d\u540d\uff0c\u800cwaitKey(0)\u8868\u793a\u6309\u4e0b\u4efb\u610f\u952e\u9000\u51fa\uff0c\u5982\u679c\u4e0d\u5199\u8be5\u8bed\u53e5\uff0c\u5219\u7a0b\u5e8f\u5c06\u76f4\u63a5\u6267\u884c\u5b8c\u6bd5\uff0c\u4e0d\u65b9\u4fbf\u89c2\u5bdf\u5c55\u793a\u56fe\u7247\u7684\u6548\u679c<\/p>\n<p>        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19308\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec1.png\" alt=\"\" width=\"2322\" height=\"1350\" \/><\/p>\n<h2>\u5c55\u793a\u56fe\u7247\u5c5e\u6027<\/h2>\n<p>        \u6bd4\u5982\u56fe\u7247\u7684\u5bbd\u9ad8\u3001\u5927\u5c0f\u3001\u989c\u8272\u5206\u91cf<br \/>\n[code lang=&#8221;python&#8221;]<br \/>\n# \u8f93\u51fa\u56fe\u7247\u5f62\u72b6\uff0c\u5176\u4e2d\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u5982\u679c\u662f3\u8868\u793abgr\u989c\u8272<br \/>\nprint(img.shape)<br \/>\n# \u8f93\u51fa\u56fe\u7247\u5927\u5c0f<br \/>\nprint(img.size)<\/p>\n<p># \u8f93\u51fa\u56fe\u7247\u7684\u5bbd\u9ad8<br \/>\nw = img.shape[0]<br \/>\nh = img.shape[1]<br \/>\nprint(w,h)<\/p>\n<p># \u8f93\u51fa\u56fe\u7247bgr\u989c\u8272<br \/>\n(b, g, r) = img[0, 0]<br \/>\nprint(b, g, r)<br \/>\n[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19309\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec2.png\" alt=\"\" width=\"1141\" height=\"1129\" \/><\/p>\n<h2>\u4fee\u6539\u56fe\u7247\u6307\u5b9a\u4f4d\u7f6e\u7684\u989c\u8272\u503c<\/h2>\n<p>[code lang=&#8221;python&#8221;]img[0:200, 0:200] = (128, 0, 0)<br \/>\ncv2.imshow(&quot;HelloCV&quot;, img)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19323\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec3.png\" alt=\"\" width=\"2293\" height=\"1277\" \/><\/p>\n<h2 id=\"the-pasted-async\">\u5728\u56fe\u7247\u4e0a\u9762\u753b\u77e9\u5f62\u4ee5\u53ca\u5728\u65c1\u8fb9\u8f93\u51fa\u4e00\u6bb5\u6587\u5b57<\/h2>\n<p>[code lang=&#8221;python&#8221;]red = (0, 0, 255) # b g r<br \/>\nfont = cv2.FONT_HERSHEY_COMPLEX_SMALL # \u5b57\u4f53\u5927\u5c0f<br \/>\ncv2.putText(img, &quot;title&quot;, (100, 90), font, 4, red)<br \/>\ncv2.rectangle(img, (100, 100), (400, 400), red, 0) # 0:\u7a7a\u5fc3, -1:\u5b9e\u5fc3<br \/>\ncv2.imshow(&quot;HelloCV&quot;, img)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19334\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec4.png\" alt=\"\" width=\"2297\" height=\"1402\" \/><\/p>\n<h2>\u5e73\u79fb\u56fe\u50cf<\/h2>\n<p>[code lang=&#8221;python&#8221;]# \u521b\u5efa\u4e00\u4e2a\u53d8\u6362\u77e9\u9635<br \/>\n# \u5e73\u79fb\uff1ax\u8f74\u6b63\u65b9\u5411(1,0) 200\uff0c y\u8f74\u6b63\u65b9\u5411(0,1) 100<br \/>\nM = ny.float32([[1, 0, 200], [0, 1, 100]])<br \/>\ndst = cv2.warpAffine(img, M, (w, h))<br \/>\ncv2.imshow(&quot;Hello&quot;, dst)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19335\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec5.png\" alt=\"\" width=\"2189\" height=\"1382\" \/><\/p>\n<h2>\u65cb\u8f6c\u56fe\u50cf<\/h2>\n<p>[code lang=&#8221;python&#8221;]# \u521b\u5efa\u65cb\u8f6c\u77e9\u9635\uff0c\u53c2\u6570\u4e3a\u65cb\u8f6c\u4e2d\u5fc3\uff0c\u65cb\u8f6c\u89d2\u5ea6\uff0c\u7f29\u653e\u6bd4\u4f8b<br \/>\nN = cv2.getRotationMatrix2D((0.5 * w, 0.5 * h), 45, 0.75)<br \/>\ndst1 = cv2.warpAffine(img, N, (w, h))<br \/>\ncv2.imshow(&quot;HelloCV1&quot;, dst1)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19367\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec6.png\" alt=\"\" width=\"2397\" height=\"1430\" \/><\/p>\n<h2>\u5408\u5e76\u901a\u9053<\/h2>\n<p>[code lang=&#8221;python&#8221;]# \u62c6\u5206\u62103\u4e2a\u989c\u8272\u5206\u91cf\u901a\u9053\u56fe\u7247<br \/>\n(B, G, R) = cv2.split(img)<br \/>\ncv2.imshow(&quot;blue&quot;, B)<br \/>\ncv2.imshow(&quot;green&quot;, G)<br \/>\ncv2.imshow(&quot;red&quot;, R)<br \/>\nmerge = cv2.merge([B, G, R]) #\u5408\u5e76\u901a\u9053<br \/>\ncv2.imshow(&quot;merge&quot;, merge)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19370\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec7.png\" alt=\"\" width=\"2489\" height=\"1384\" \/><\/p>\n<h2>\u8fb9\u7f18\u68c0\u6d4b1<\/h2>\n<p>[code lang=&#8221;python&#8221;]gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # \u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\uff0c\u4ee5\u4fbf\u8fd0\u7b97<br \/>\n# cv2.imshow(&quot;gray&quot;,gray)<br \/>\nlab = cv2.Laplacian(img, cv2.CV_64F) # \u6df1\u5ea6<br \/>\ncv2.imshow(&quot;lab1&quot;,lab)<br \/>\nlab = ny.uint8(ny.absolute(lab)) # \u7edd\u5bf9\u503c\u5316<br \/>\ncv2.imshow(&quot;lab2&quot;, lab)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19374\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec8.png\" alt=\"\" width=\"2534\" height=\"1454\" \/><\/p>\n<h2>\u8fb9\u7f18\u68c0\u6d4b2<\/h2>\n<p>[code lang=&#8221;python&#8221;]# canny\u50cf\u7d20\u503c\u8303\u56f4200\u5230240<br \/>\ncanny = cv2.Canny(img, 200, 240)<br \/>\ncv2.imshow(&quot;canny&quot;, canny)<br \/>\ncv2.waitKey(0)[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19378\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec9.png\" alt=\"\" width=\"2296\" height=\"1384\" \/><\/p>\n<h2>\u56fe\u7247\u9762\u90e8\u8bc6\u522b<\/h2>\n<p>[code lang=&#8221;python&#8221;]<br \/>\nimgFace = cv2.imread(&quot;C:\\\\Users\\\\jiangli\\\\Desktop\\\\11\\\\\u56fe\u7247\\\\face.png&quot;)<br \/>\ncas = cv2.CascadeClassifier(&quot;face\/haarcascade_frontalface_alt2.xml&quot;) # \u8f7d\u5165\u7ea7\u8054\u5206\u7c7b\u5668\uff0c\u5373\u4eba\u8138\u6570\u636e\u5e93<br \/>\ngray = cv2.cvtColor(imgFace, cv2.COLOR_BGR2GRAY) # \u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\uff0c\u4ee5\u4fbf\u8fd0\u7b97<br \/>\n# \u68c0\u6d4b\u4eba\u8138\uff1a\u8ddf\u6570\u636e\u5e93\u8fdb\u884c\u6bd4\u8f83<br \/>\n# \u7ed3\u679c\u96c6\u5408\uff1a\u6bcf\u4e2a\u7ed3\u679c\u5305\u542b\u4eba\u8138\u7684\u5750\u6807x, y, \u957f\u5ea6, \u5bbd\u5ea6<br \/>\nrects = cas.detectMultiScale(gray)<br \/>\n# \u5faa\u73af\u7ed3\u679c\u96c6\u5408\u5728\u753b\u9762\u4e0a\u7ed8\u5236\u77e9\u5f62<br \/>\nfor x, y, width, height in rects:<br \/>\ncv2.rectangle(imgFace, (x, y), (x + width, y + height), (0, 0, 255), 3)<\/p>\n<p>cv2.imshow(&quot;face&quot;, imgFace)<br \/>\ncv2.waitKey(0)<br \/>\n[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19380\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec10.png\" alt=\"\" width=\"2091\" height=\"566\" \/><\/p>\n<h2>\u89c6\u9891\u9762\u90e8\u8bc6\u522b<\/h2>\n<p>[code lang=&#8221;python&#8221;]# \u6444\u50cf\u5934\u7f16\u53f70(\u9ed8\u8ba4) 1 2 3 \u5fc5\u987b\u8981\u6709\u53c2\u6570<br \/>\ncamera = cv2.VideoCapture(0)  # \u4ece\u6444\u50cf\u5934\u8bfb\u53d6<br \/>\n# camera = cv2.VideoCapture(&quot;C:\\\\Users\\\\jiangli\\\\Desktop\\\\11\\\\\u89c6\u9891\\\\trailer.mp4&quot;)  # \u4ece\u6307\u5b9a\u7684\u89c6\u9891\u8bfb\u53d6<br \/>\n# python\u8bed\u6cd5\uff0c\u7528\u7f29\u8fdb\u8868\u793a\u4ee3\u7801\u5757\uff0c\u76f8\u5f53\u4e8ec\u7684\u62ec\u53f7<br \/>\nwhile True:<br \/>\n        # \u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf,ret\u4e3a\u662f\u5426\u8bfb\u5230\u7684\u8fd4\u56de\u503c\uff0cimg\u4e3a\u8bfb\u5230\u7684\u56fe\u50cf<br \/>\n        (ok, img) = camera.read()<br \/>\n        if not ok:<br \/>\n                # print(&quot;open video failed&quot;)<br \/>\n                break<br \/>\n        else:<br \/>\n                # print(&quot;open video success&quot;)<\/p>\n<p>                cas = cv2.CascadeClassifier(&quot;face\/haarcascade_frontalface_alt2.xml&quot;)  # \u8f7d\u5165\u7ea7\u8054\u5206\u7c7b\u5668\uff0c\u5373\u4eba\u8138\u6570\u636e\u5e93<br \/>\n                gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  # \u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\uff0c\u4ee5\u4fbf\u8fd0\u7b97<br \/>\n                # \u68c0\u6d4b\u4eba\u8138\uff1a\u8ddf\u6570\u636e\u5e93\u8fdb\u884c\u6bd4\u8f83<br \/>\n                # \u7ed3\u679c\uff1a\u4eba\u8138\u7684\u5750\u6807x, y, \u957f\u5ea6, \u5bbd\u5ea6<br \/>\n                rects = cas.detectMultiScale(gray)<\/p>\n<p>                for x, y, width, height in rects:<br \/>\n                        cv2.rectangle(img, (x, y), (x + width, y + height), (0, 0, 255), 3)<\/p>\n<p>                cv2.imshow(&quot;face&quot;, img)<\/p>\n<p>        if cv2.waitKey(33) &amp; 0xFF == ord(&#8216;q&#8217;):  # \u7b49\u5f8533\u6beb\u79d2,\u8f93\u5165q\u8df3\u51fa<br \/>\n                break<\/p>\n<p>camera.release()<br \/>\ncv2.destroyAllWindows()<br \/>\ncv2.waitKey(0);[\/code]<br \/>\n        \u6267\u884c\u7ed3\u679c<\/p>\n<p>        <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19384\" src=\"https:\/\/www.wqeq.com\/wp-content\/uploads\/2024\/04\/exec11.png\" alt=\"\" width=\"2189\" height=\"1147\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u9700\u8981\u51c6\u5907\u56fe\u7247\uff0c\u6700\u597d\u5e26\u6709\u4eba\u7269\u7684\u3002\u6211\u8fd9\u91cc\u51c6\u5907\u4e86\u4e24\u5f20\u56fe\u7247 C:\\Users\\jiangli\\Desktop\\11 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":19294,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[96,94],"_links":{"self":[{"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/posts\/19288"}],"collection":[{"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19288"}],"version-history":[{"count":92,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/posts\/19288\/revisions"}],"predecessor-version":[{"id":19417,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/posts\/19288\/revisions\/19417"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=\/wp\/v2\/media\/19294"}],"wp:attachment":[{"href":"https:\/\/www.wqeq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wqeq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}