Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"id":391,"date":"2021-04-30T15:57:39","date_gmt":"2021-04-30T06:57:39","guid":{"rendered":"https:\/\/cra-log.sakura.ne.jp\/?p=391"},"modified":"2023-08-19T09:22:11","modified_gmt":"2023-08-19T00:22:11","slug":"python-opencv-face-detection","status":"publish","type":"post","link":"https:\/\/craft-gogo.com\/python-opencv-face-detection\/","title":{"rendered":"\u3010Python+OpenCV\u3011\u7c21\u5358!\u305f\u3063\u305f\u5341\u6570\u884c\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u9854\u691c\u51fa"},"content":{"rendered":"\n

\u30c7\u30b8\u30ab\u30e1\u306e\u3088\u3046\u306b\u9854\u691c\u51fa\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u305b\u3093\u304b\uff1f<\/p>\n\n\n\n

OpenCV\u3092\u4f7f\u3048\u3070\u3001\u305f\u3063\u305f\u5341\u6570\u884c\u3067\u9854\u691c\u51fa\u3067\u304d\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u51fa\u6765\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n

OpenCV\u306b\u306f\u5927\u91cf\u306e\u753b\u50cf\u304b\u3089\u4eba\u306e\u9854\u306e\u7279\u5fb4\u3092\u5b66\u7fd2\u3057\u3001\u4eba\u306e\u9854\u3092\u5224\u5225\u3059\u308b\u300c\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u300d\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u4f7f\u7528\u3057\u305f\u9854\u691c\u51fa\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

\u9854\u691c\u51fa\u306e\u6d41\u308c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n

\n
<\/span>STEP<\/span><\/div>
\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u3092\u8aad\u307f\u8fbc\u3080<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u3080<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u9854\u691c\u51fa<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u9854\u90e8\u3092\u67a0\u3067\u56f2\u3080<\/div>
\n\n<\/div><\/div>\n<\/div>\n\n\n\n

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n\n\n\n
import cv2 as cv\n\n#\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u8aad\u307f\u8fbc\u307f\nHAAR_FILE = "haarcascade_frontalface_default.xml"\ncascade = cv.CascadeClassifier(HAAR_FILE)\n\n#\u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\nimg = cv.imread("sample.jpg")\n\n#\u9854\u691c\u51fa\nface = cascade.detectMultiScale(img)\n\n#\u9854\u90e8\u3092\u67a0\u3067\u56f2\u3080\nfor x, y, w, h in face:\n    cv.rectangle(img,(x,y),(x+w,y+h),(0,0,255),1)\n\ncv.imshow("img", img)\ncv.waitKey(0)\ncv.destroyAllWindows()<\/code><\/pre><\/div>\n\n\n\n

\u30d7\u30ed\u30b0\u30e9\u30e0\u89e3\u8aac<\/h2>\n\n\n\n

\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u3092\u8aad\u307f\u8fbc\u3080<\/h3>\n\n\n\n
HAAR_FILE = "haarcascade_frontalface_default.xml"\ncascade = cv.CascadeClassifier(HAAR_FILE)<\/code><\/pre><\/div>\n\n\n\n

cv.CascadeClassifier()\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u4eba\u306e\u9854\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u306e\u300c\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u300d\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n\n\n

\n
\n
\"\"<\/figure>\n<\/div>\n
\n

\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\uff1f<\/p>\n<\/div>\n<\/div>\n

\u753b\u50cf\u304b\u3089\u3042\u308b\u7269\u4f53\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u5927\u91cf\u306e\u753b\u50cf\u304b\u3089\u3042\u308b\u7269\u4f53\u306e\u7279\u5fb4\u3092\u5b66\u7fd2\u3057\u3001\u3053\u306e\u7279\u5fb4\u3092\u307e\u3068\u3081\u305f\u30c7\u30fc\u30bf\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u7279\u5fb4\u3092\u307e\u3068\u3081\u305f\u30c7\u30fc\u30bf\u306e\u3053\u3068\u3092\u300c\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u300d\u3068\u547c\u3073\u307e\u3059\u3002<\/span><\/div>\n\n\n

OpenCV\u306f\u3001\u4eba\u306e\u9854\u3092\u96c6\u3081\u305f\u5927\u91cf\u753b\u50cf\u304b\u3089\u4eba\u306e\u9854\u306e\u7279\u5fb4\u91cf\u3092\u307e\u3068\u3081\u305fHaar-Cascade\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306fGitHub<\/a>\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n

\u4eca\u56de\u306f\u3001\u6b63\u9762\u306e\u9854\u3092\u691c\u51fa\u3059\u308b\u300chaarcascade_frontalface_default.xml\u300d\u3092\u4f7f\u7528\u3057\u307e\u3057\u305f\u3002\u4ed6\u306b\u3082\u8272\u3005\u306a\u5206\u985e\u5668\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n

\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\u3042\u308f\u305b\u3066\u8aad\u307f\u305f\u3044<\/span>\n\t\t\t\t\t
\"\"<\/figure><\/div>\t\t\t\t\t
\n\t\t\t\t\t\t\u3010Python+OpenCV\u3011\u9854\u691c\u51fa\u5fdc\u7528\uff01\u76ee\u3068\u7b11\u9854\u306e\u691c\u51fa\u65b9\u6cd5<\/a>\n\t\t\t\t\t\t\u4ee5\u524d\u306e\u8a18\u4e8b\u3067OpenCV\u3067\u9854\u691c\u51fa\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002 \u4eca\u56de\u306f\u3001\u9854\u691c\u51fa\u306e\u5fdc\u7528\u3068\u3057\u3066\u3001\u76ee\u3068\u7b11\u9854\u3092\u691c\u51fa\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u3010\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3011 \u3053\u3061\u3089…<\/span>\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n\n\n

\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u3080<\/h3>\n\n\n\n
img = cv.imread("sample.jpg")<\/code><\/pre><\/div>\n\n\n\n

cv.imread()\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u4eba\u306e\u9854\u3092\u691c\u51fa\u3057\u305f\u3044\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n\n\n\n

\u9854\u691c\u51fa<\/h3>\n\n\n\n
face = cascade.detectMultiScale(img)<\/code><\/pre><\/div>\n\n\n\n

cascade.detectMultiScale()\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u753b\u50cf\u5185\u306e\u9854\u3092\u691c\u51fa\u3057\u307e\u3059\u3002\u623b\u308a\u5024\u3068\u3057\u3066\u3001\u691c\u51fa\u3057\u305f\u9854\u306e\u4f4d\u7f6e\u304c\u914d\u5217\u306b\u683c\u7d0d\u3055\u308c\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002\u623b\u308a\u5024\u306f\u9806\u306b\u3001\u9854\u306e\u4f4d\u7f6e\u306ex\u5ea7\u6a19\u3001y\u5ea7\u6a19\u3001\u6a2a\u5e45\u3001\u7e26\u5e45\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n

\u9854\u90e8\u3092\u67a0\u3067\u56f2\u3080<\/h3>\n\n\n\n
for x, y, w, h in face:\n    cv.rectangle(img,(x,y),(x+w,y+h),(0,0,255),1)<\/code><\/pre><\/div>\n\n\n\n

face\u306b\u9854\u306e\u4f4d\u7f6e\u5ea7\u6a19\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u9854\u304c\u6b63\u5e38\u306b\u691c\u51fa\u3055\u308c\u305f\u304b\u3069\u3046\u304b\u78ba\u8a8d\u3059\u308b\u305f\u3081\u3001\u5143\u753b\u50cf\u306b\u8d64\u67a0\u3092\u52a0\u3048\u307e\u3059\u3002<\/p>\n\n\n\n