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":3506,"date":"2023-08-18T09:02:21","date_gmt":"2023-08-18T00:02:21","guid":{"rendered":"https:\/\/craft-gogo.com\/?p=3506"},"modified":"2023-08-18T09:02:23","modified_gmt":"2023-08-18T00:02:23","slug":"opencv-eyedetection","status":"publish","type":"post","link":"https:\/\/craft-gogo.com\/opencv-eyedetection\/","title":{"rendered":"\u3010Python+OpenCV\u3011\u9854\u691c\u51fa\u5fdc\u7528\uff01\u76ee\u3068\u7b11\u9854\u306e\u691c\u51fa\u65b9\u6cd5"},"content":{"rendered":"\n

\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<\/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\u7c21\u5358!\u305f\u3063\u305f\u5341\u6570\u884c\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u9854\u691c\u51fa<\/a>\n\t\t\t\t\t\t\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 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 OpenCV\u306b\u306f\u5927\u91cf\u306e\u753b…<\/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

\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<\/span><\/strong>\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n\n\n\n

\u3053\u3061\u3089\u304c\u76ee\u3001\u7b11\u9854\u3092\u691c\u51fa\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n\n\n\n

import cv2 as cv\n\n# \u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u8aad\u307f\u8fbc\u307f\nfrontalface_cascade = cv.CascadeClassifier("haarcascade_frontalface_default.xml")\neye_cascade = cv.CascadeClassifier("haarcascade_eye.xml")\nsmile_cascade = cv.CascadeClassifier("haarcascade_smile.xml")\n\n# \u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\nimg = cv.imread("sample.jpg")\n\n# \u9854\u691c\u51fa\nface = frontalface_cascade.detectMultiScale(img)\n\n# \u9854\u90e8\u3092\u8d64\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    \n    # \u9854\u90e8\u306e\u4e0a3\/4\u3092\u5207\u308a\u53d6\u308a\n    upper_face_img = img[y:int(y+3*h\/4), x:x+w]\n    \n    # \u76ee\u691c\u51fa\n    eye = eye_cascade.detectMultiScale(upper_face_img)\n    \n    # \u76ee\u90e8\u3092\u9752\u67a0\u3067\u56f2\u3080\n    for x1, y1, w1, h1 in eye:\n        cv.rectangle(img, (x+x1,y+y1), (x+x1+w1, y+y1+h1), (255,0,0), 1)\n      \n    # \u9854\u90e8\u306e\u4e0b\u534a\u5206\u3092\u5207\u308a\u53d6\u308a  \n    under_face_img = img[int(y+h\/2):(y+h), x:x+w]\n\n    # \u7b11\u9854\u691c\u51fa\n    smile = smile_cascade.detectMultiScale(under_face_img)\n     \n    # \u7b11\u9854\u3092\u7dd1\u67a0\u3067\u56f2\u3080\n    for x2, y2, w2, h2 in smile:\n        cv.rectangle(img,(x+x2, int(y+h\/2)+y2), (x+x2+w2, int(y+h\/2)+y2+h2), (0,255,0), 1)\n\ncv.imshow("img", img)\ncv.waitKey(0)\ncv.destroyAllWindows()<\/code><\/pre><\/div>\n\n\n\n

\u5b9f\u884c\u7d50\u679c\u304c\u3053\u3061\u3089<\/p>\n\n\n\n

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

3\u4eba\u3068\u3082\u76ee\u304c\u691c\u51fa\u3067\u304d\u307e\u3057\u305f\u3002\u53f32\u4eba\u306f\u7b11\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u53e3\u5143\u304c\u7b11\u9854\u3068\u5224\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

\u6b21\u7ae0\u3067\u306f\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n

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

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u6d41\u308c\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

\n
<\/span>STEP<\/span><\/div>
\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u8aad\u307f\u8fbc\u307f<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u9854\u306e\u691c\u51fa<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u76ee\u306e\u691c\u51fa<\/div>
\n\n<\/div><\/div>\n\n\n\n
<\/span>STEP<\/span><\/div>
\u7b11\u9854\u306e\u691c\u51fa<\/div>
\n\n<\/div><\/div>\n<\/div>\n\n\n\n

STEP1\uff5e3\u306f\u3001\u5225\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u672c\u8a18\u4e8b\u3067\u306f\u5272\u611b\u3057\u307e\u3057\u305f\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\u7c21\u5358!\u305f\u3063\u305f\u5341\u6570\u884c\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u9854\u691c\u51fa<\/a>\n\t\t\t\t\t\t\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 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 OpenCV\u306b\u306f\u5927\u91cf\u306e\u753b…<\/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

\u3053\u3053\u3067\u306f\u3001STEP4: \u76ee\u306e\u691c\u51fa\u3001STEP5: \u7b11\u9854\u306e\u691c\u51fa\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n

\u76ee\u306e\u691c\u51fa<\/h3>\n\n\n\n

\u76ee\u3092\u691c\u51fa\u3059\u308b\u306b\u306f\u300chaarcascade_eye.xml<\/span><\/strong>\u300d\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

# \u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u8aad\u307f\u8fbc\u307f\neye_cascade = cv.CascadeClassifier("haarcascade_eye.xml")\n\n# \u9854\u90e8\u306e\u4e0a3\/4\u3092\u5207\u308a\u53d6\u308a\nupper_face_img = img[y:int(y+3*h\/4), x:x+w]\n\n# \u76ee\u691c\u51fa\neye = eye_cascade.detectMultiScale(upper_face_img)\n\n# \u76ee\u90e8\u3092\u9752\u67a0\u3067\u56f2\u3080\nfor x1, y1, w1, h1 in eye:\n    cv.rectangle(img, (x+x1,y+y1), (x+x1+w1, y+y1+h1), (255,0,0), 1)mg)<\/code><\/pre><\/div>\n\n\n\n

\u9854\u90e8\u306e\u4e0a3\/4\u3092\u5207\u308a\u53d6\u308a\u3001\u3053\u306e\u4e2d\u304b\u3089\u76ee\u3092\u691c\u51fa\u3057\u3066\u9752\u67a0\u3067\u56f2\u3080<\/strong>\u3068\u3044\u3046\u3053\u3068\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

\u3082\u3057\u3001\u9854\u90e8\u3092\u5207\u308a\u53d6\u3089\u306a\u304b\u3063\u305f\u3089\u3069\u3046\u306a\u308b\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n

\u4e0b\u56f3\u306f\u9854\u90e8\u3092\u5207\u308a\u53d6\u3089\u306a\u304b\u3063\u305f\u5834\u5408\u306e\u5b9f\u884c\u7d50\u679c\u3067\u3059\u3002<\/p>\n\n\n\n

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

\u5de6\u306e\u5973\u6027\u306e\u304a\u3067\u3053\u3068\u53e3\u304c\u76ee\u3068\u8aa4\u5224\u5b9a\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u76ee\u306f\u9854\u306e\u4e0a\u90e8\u306b\u4f4d\u7f6e\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u8aa4\u5224\u5b9a\u3057\u306a\u3044\u305f\u3081\u306b\u3082\u691c\u51fa\u7bc4\u56f2\u3092\u9854\u306e\u4e0a\u90e8\u306e\u307f\u306b\u7d5e\u308b\u65b9\u304c\u826f\u3044\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n

\u7b11\u9854\u306e\u691c\u51fa<\/h3>\n\n\n\n

\u7b11\u9854\u3092\u691c\u51fa\u3059\u308b\u306e\u306f\u300chaarcascade_smile.xml<\/span><\/strong>\u300d\u3067\u3059\u3002<\/p>\n\n\n\n

# \u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u8aad\u307f\u8fbc\u307f\nsmile_cascade = cv.CascadeClassifier("haarcascade_smile.xml")\n\n# \u9854\u90e8\u306e\u4e0b\u534a\u5206\u3092\u5207\u308a\u53d6\u308a  \nunder_face_img = img[int(y+h\/2):(y+h), x:x+w]\n\n# \u7b11\u9854\u691c\u51fa\nsmile = smile_cascade.detectMultiScale(under_face_img)\n    \n# \u7b11\u9854\u3092\u7dd1\u67a0\u3067\u56f2\u3080\nfor x2, y2, w2, h2 in smile:\n    cv.rectangle(img,(x+x2, int(y+h\/2)+y2), (x+x2+w2, int(y+h\/2)+y2+h2), (0,255,0), 1)<\/code><\/pre><\/div>\n\n\n\n

\u76ee\u306e\u691c\u51fa\u540c\u69d8\u3001\u9854\u90e8\u306e\u4e0b\u534a\u5206\u3092\u5207\u308a\u53d6\u308a\u3001\u3053\u306e\u4e2d\u304b\u3089\u7b11\u9854\u3092\u691c\u51fa\u3057\u3066\u7dd1\u67a0\u3067\u56f2\u307f\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n

\u3053\u3061\u3089\u3082\u9854\u90e8\u3092\u5207\u308a\u53d6\u3089\u306a\u304b\u3063\u305f\u5834\u5408\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n

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

\u69d8\u3005\u306a\u3068\u3053\u308d\u3067\u7b11\u9854\u304c\u691c\u51fa\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u691c\u51fa\u7bc4\u56f2\u3092\u7d5e\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\uff01<\/p>\n\n\n\n

\u8272\u3005\u306a\u753b\u50cf\u3067\u76ee\u30fb\u7b11\u9854\u306e\u691c\u51fa<\/h2>\n\n\n\n

\u3053\u3061\u3089\u306e\u753b\u50cf\u3067\u306f\u53f3\u5074\u5973\u6027\u306e\u53f3\u76ee\u304c\u691c\u51fa\u51fa\u6765\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n

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

\u3053\u3061\u3089\u306e\u5199\u771f\u306f3\u4eba\u3068\u3082\u7b11\u9854\u3067\u306f\u306a\u3044\u3067\u3059\u304c\u3001\u53e3\u5143\u304c\u7b11\u9854\u3068\u691c\u51fa\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

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

\u7b11\u9854\u691c\u51fa\u3068\u3044\u3046\u3088\u308a\u306f\u3001\u53e3\u691c\u51fa\u306b\u8fd1\u3044\u3067\u3059\u306d\u3002<\/p>\n\n\n\n

\u307e\u3068\u3081<\/h2>\n\n\n\n

\u9854\u691c\u51fa\u306e\u5fdc\u7528\u3068\u3057\u3066\u3001OpenCV\u306e\u300c\u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u300d\u3092\u4f7f\u7528\u3057\u305f\u76ee\u30fb\u7b11\u9854\u691c\u51fa\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n

\n

\u624b\u9806\u306e\u304a\u3055\u3089\u3044<\/p>\n\n\n\n

    \n
  • \u30ab\u30b9\u30b1\u30fc\u30c9\u5206\u985e\u5668\u8aad\u307f\u8fbc\u307f<\/li>\n\n\n\n
  • \u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f<\/li>\n\n\n\n
  • \u9854\u306e\u691c\u51fa<\/li>\n\n\n\n
  • \u76ee\u306e\u691c\u51fa<\/li>\n\n\n\n
  • \u7b11\u9854\u306e\u691c\u51fa<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n

    \u4eca\u56de\u306e\u8a18\u4e8b\u304c\u7686\u3055\u3093\u306ePython\u5b66\u7fd2\u306b\u5f79\u7acb\u3064\u306a\u3089\u5e78\u3044\u3067\u3059\u3002<\/p>\n\n\n\n

    Python\u72ec\u5b66\u304c\u5927\u5909\u306a\u65b9\u306f\u3001\u66f8\u7c4d\u3084\u30b9\u30af\u30fc\u30eb\u3092\u6d3b\u7528<\/strong>\u3059\u308b\u306e\u3082\u624b\u3067\u3059\u3002<\/p>\n\n\n\n

    \n
    \n