{"id":33,"date":"2018-11-06T19:55:30","date_gmt":"2018-11-06T10:55:30","guid":{"rendered":"https:\/\/unclemasa.com\/blog\/?p=33"},"modified":"2018-11-06T19:56:08","modified_gmt":"2018-11-06T10:56:08","slug":"pyhson2%e3%81%a8opencv2%e3%81%a7%e5%8b%95%e7%94%bb%e8%bf%bd%e5%b0%be","status":"publish","type":"post","link":"https:\/\/unclemasa.com\/blog\/?p=33","title":{"rendered":"pyhson2\u3068openCv2\u3067\u52d5\u753b\u8ffd\u5c3e"},"content":{"rendered":"<p>\u3088\u304fpyhson3\u3068openCv3\u3067\u30d3\u30c7\u30aa\u753b\u9762\u3067 \u4eba\u3084 \u304a\u76ee\u3081\u3092\u8ffd\u8de1\u3059\u308b\u306e\u304c\u3042\u308b\u306e\u3067\u4f5c\u6210\u3057\u3088\u3046\u3068\u601d\u3044<\/p>\n<p>\u304c \u3057\u304b\u3057centos7\u306b\u3069\u3046\u3057\u3066\u3082 openCV3\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u51fa\u6765\u306a\u304b\u3063\u305f\u306e\u3060<\/p>\n<p>\u3067\u00a0pyhson2\u3068openCv2\u3067\u52d5\u753b\u8ffd\u5c3e\u3067\u4f5c\u6210\u3057\u305f\u306e\u3067\u3057\u305f<\/p>\n<p>\u4ee5\u4e0b \u30b3\u30fc\u30c9<\/p>\n<h6>&#8220;&#8221;&#8221; ########################################################### &#8220;&#8221;&#8221;<\/h6>\n<p>#!\/usr\/local\/bin\/python<br \/>\n#! -*- coding: utf-8 -*-<\/p>\n<p>import cv2<br \/>\nimport numpy as np<br \/>\nface_cascade_path = &#8216;\/\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30d1\u30b9\/opencv-master\/data\/haarcascades\/haarcascade_frontalface_default.xml&#8217;<br \/>\neye_cascade_path = &#8216;\/\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30d1\u30b9\/opencv-master\/data\/haarcascades\/haarcascade_eye.xml&#8217;<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<\/p>\n<p>vc = cv2.VideoCapture(0)<br \/>\nface_cascade = cv2.CascadeClassifier(face_cascade_path)<br \/>\neye_cascade = cv2.CascadeClassifier(eye_cascade_path)<\/p>\n<p>while True:<\/p>\n<p>r, img = vc.read()<br \/>\nif not r:<br \/>\nbreak<br \/>\nsrc=img<br \/>\nimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)<br \/>\nfaces = face_cascade.detectMultiScale(img)<br \/>\nfor x, y, w, h in faces:<br \/>\ncv2.rectangle(src, (x, y), (x + w, y + h), (255, 0, 0), 2)<br \/>\nface = src[y: y + h, x: x + w]<br \/>\nface_gray = img[y: y + h, x: x + w]<br \/>\neyes = eye_cascade.detectMultiScale(face_gray)<br \/>\nfor (ex, ey, ew, eh) in eyes:<br \/>\ncv2.rectangle(face, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)<br \/>\nbreak<\/p>\n<p>r = cv2.waitKey(20)<br \/>\nif r &gt;= 0:<br \/>\nbreak<br \/>\ncv2.imshow(&#8216;Camera&#8217;, src)<br \/>\nvc.release()<br \/>\ncv2.destroyAllWindows<\/p>\n<h6>&#8220;&#8221;&#8221;#################################<\/h6>\n<p>\u3068\u3053\u3093\u306a\u611f\u3058\u306b \u306a\u308a\u7533\u3057\u305f \u9854\u306e\u4e2d\u306e \u76ee\u7389\u3092\u56db\u89d2\u3067\u304b\u3053\u3080&#8221;&#8221;&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3088\u304fpyhson3\u3068openCv3\u3067\u30d3\u30c7\u30aa\u753b\u9762\u3067 \u4eba\u3084 \u304a\u76ee\u3081\u3092\u8ffd\u8de1\u3059\u308b\u306e\u304c\u3042\u308b\u306e\u3067\u4f5c\u6210\u3057\u3088\u3046\u3068\u601d\u3044 \u304c \u3057\u304b\u3057centos7\u306b\u3069\u3046\u3057\u3066\u3082 openCV3\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u51fa\u6765\u306a\u304b\u3063\u305f\u306e\u3060 \u3067\u00a0pyhson2\u3068openCv2\u3067\u52d5\u753b\u8ffd\u5c3e\u3067\u4f5c\u6210\u3057\u305f\u306e\u3067\u3057\u305f \u4ee5\u4e0b \u30b3\u30fc\u30c9 &#8220;&#8221;&#8221; ########################################################### &#8220;&#8221;&#8221; #!\/usr\/local\/bin\/python #! -*- coding: utf-8 -*- import cv2 import numpy as np face_cascade_path = &#8216;\/\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30d1\u30b9\/opencv-master\/data\/haarcascades\/haarcascade_frontalface_default.xml&#8217; eye_cascade_path = &#8216;\/\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30d1\u30b9\/opencv-master\/data\/haarcascades\/haarcascade_eye.xml&#8217; if __name__ == &#8220;__main__&#8221;: vc = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier(face_cascade_path) eye_cascade = cv2.CascadeClassifier(eye_cascade_path) while True: r, img = vc.read() if not r: break src=img img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(img) for x, y, w, h in faces: cv2.rectangle(src, (x, y), (x + w, y + h), (255, 0, 0), 2) face = src[y: y + h, x: x + w] face_gray = img[y: y + h, x: x + w] eyes = eye_cascade.detectMultiScale(face_gray) for (ex, ey, ew, eh) in eyes: cv2.rectangle(face, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2) break r = cv2.waitKey(20) if r &gt;= 0: break cv2.imshow(&#8216;Camera&#8217;, src) vc.release() cv2.destroyAllWindows &#8220;&#8221;&#8221;################################# \u3068\u3053\u3093\u306a\u611f\u3058\u306b \u306a\u308a\u7533\u3057\u305f \u9854\u306e\u4e2d\u306e \u76ee\u7389\u3092\u56db\u89d2\u3067\u304b\u3053\u3080&#8221;&#8221;&#8221;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":2,"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":35,"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions\/35"}],"wp:attachment":[{"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unclemasa.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}