{"id":12,"date":"2019-01-10T20:42:40","date_gmt":"2019-01-10T12:42:40","guid":{"rendered":"http:\/\/www.guger.top\/?p=12"},"modified":"2019-03-05T16:58:25","modified_gmt":"2019-03-05T08:58:25","slug":"%e8%a7%a3%e5%86%b3%e5%88%86%e7%b1%bb%e5%99%a8detectmultiscale%e6%96%b9%e6%b3%95%e7%9a%84%e9%94%99%e8%af%af%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.guger.top\/index.php\/2019\/01\/10\/%e8%a7%a3%e5%86%b3%e5%88%86%e7%b1%bb%e5%99%a8detectmultiscale%e6%96%b9%e6%b3%95%e7%9a%84%e9%94%99%e8%af%af%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u89e3\u51b3\u5206\u7c7b\u5668detectMultiScale\u65b9\u6cd5\u7684\u9519\u8bef\u95ee\u9898"},"content":{"rendered":"<p><!-- wp:paragraph --><\/p>\n<p>\u5f00\u59cb\u79fb\u690d\u7f51\u4e0a\u5df2\u6709\u7a0b\u5e8f\u6bb5\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:syntaxhighlighter\/code {\"language\":\"python\"} --><\/p>\n<pre class=\"wp-block-syntaxhighlighter-code\">import numpy as np\nimport cv2\nimport sys\nimport os\nimg=cv2.imread('G:\/7649.jpg')\nface_haar = cv2.CascadeClassifier(\"haarcascade_frontalface_default.xml\")\neye_haar = cv2.CascadeClassifier(\"haarcascade_eye.xml\")\n# \u628a\u56fe\u50cf\u8f6c\u4e3a\u9ed1\u767d\u56fe\u50cf\ngray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n# # \u68c0\u6d4b\u56fe\u50cf\u4e2d\u7684\u6240\u6709\u8138\nfaces = face_haar.detectMultiScale(gray_img, 1.3, 5)\nfor face_x,face_y,face_w,face_h in faces:\n    cv2.rectangle(img, (face_x, face_y), (face_x+face_w, face_y+face_h), (0,255,0), 2)\n# \u773c\u957f\u5728\u8138\u4e0a\nroi_gray_img = gray_img[face_y:face_y+face_h, face_x:face_x+face_w]\nroi_img = img[face_y:face_y+face_h, face_x:face_x+face_w]\neyes = eye_haar.detectMultiScale(roi_gray_img, 1.3, 5)\nfor eye_x,eye_y,eye_w,eye_h in eyes:\n    cv2.rectangle(roi_img, (eye_x,eye_y), (eye_x+eye_w, eye_y+eye_h), (255,0,0), 2)\ncv2.imshow('image',img)\ncv2.waitKey(0)<\/pre>\n<p><!-- \/wp:syntaxhighlighter\/code --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u7136\u800c\u8fd0\u884c\u9519\u8bef<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:syntaxhighlighter\/code {\"language\":\"python\"} --><\/p>\n<pre class=\"wp-block-syntaxhighlighter-code\">   cv2.rectangle(img, (face_x, face_y), (face_x+face_w,face_y+face_h), (0,255,0), 2)\n      ^\nIndentationError: expected an indented block<\/pre>\n<p><!-- \/wp:syntaxhighlighter\/code --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u95ee\u9898\u80af\u5b9a\u51fa\u5728\u5206\u7c7b\u5668\u7684haar\u6587\u4ef6\u5730\u5740\u4e0a\uff0c\u589e\u52a0\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n<p><!-- wp:syntaxhighlighter\/code {\"language\":\"python\"} --><\/p>\n<pre class=\"wp-block-syntaxhighlighter-code\">face_haar.load(\"G:\/opencv program\/opencv\/build\/etc\/haarcascades\/haarcascade_frontalface_default.xml\")\neye_haar.load(\"G:\/opencv program\/opencv\/build\/etc\/haarcascades\/haarcascade_frontalface_default.xml\")<\/pre>\n<p><!-- \/wp:syntaxhighlighter\/code --><\/p>\n<p><!-- wp:paragraph --><\/p>\n<p>\u7528load\u65b9\u6cd5\u589e\u52a0\u5b8c\u6574\u5730\u5740\uff0c\u6216\u8005\u76f4\u63a5\u5c06\u51fd\u6570\u4e2d\u5730\u5740\u8865\u5168\u4e5f\u53ef\u3002<\/p>\n<p><!-- \/wp:paragraph --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f00\u59cb\u79fb\u690d\u7f51\u4e0a\u5df2\u6709\u7a0b\u5e8f\u6bb5\uff1a \u7136\u800c\u8fd0\u884c\u9519\u8bef \u95ee\u9898\u80af\u5b9a\u51fa\u5728\u5206\u7c7b\u5668\u7684haar\u6587\u4ef6\u5730\u5740\u4e0a\uff0c\u589e\u52a0\u4ee5\u4e0b\u8bed\u53e5\uff1a \u7528load\u65b9\u6cd5\u589e\u52a0\u5b8c\u6574\u5730\u5740\uff0c\u6216\u8005\u76f4 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":17,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":""},"categories":[3,2],"tags":[5,4],"class_list":["post-12","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv","category-python","tag-opencv","tag-python"],"_links":{"self":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/media\/17"}],"wp:attachment":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}