{"id":2625,"date":"2018-11-28T07:10:17","date_gmt":"2018-11-27T22:10:17","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2625"},"modified":"2018-11-28T07:10:17","modified_gmt":"2018-11-27T22:10:17","slug":"python%ef%bc%88opencv%ef%bc%89-%e9%a1%94%e3%81%8c%e4%b8%8a%e3%82%92%e5%90%91%e3%81%8f%e3%82%88%e3%81%86%e3%81%ab%e5%86%99%e7%9c%9f%e3%81%8b%e3%82%89%e5%88%87%e3%82%8a%e5%87%ba%e3%81%99%e6%96%b9","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2625","title":{"rendered":"Python\uff08OpenCV\uff09 \u9854\u304c\u4e0a\u3092\u5411\u304f\u3088\u3046\u306b\u5199\u771f\u304b\u3089\u5207\u308a\u51fa\u3059\u65b9\u6cd5"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593\u3053\u306e\u30d6\u30ed\u30b0\u3067<a href=\"https:\/\/blog.capilano-fw.com\/?p=2246\">Electron + Python \u3067\u9078\u3093\u3060\u9854\u306b\u30e2\u30b6\u30a4\u30af\u3092\u304b\u3051\u308b\u30a2\u30d7\u30ea\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09<\/a>\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u6700\u8fd1\u3067\u306f\u6a5f\u68b0\u5b66\u7fd2\u306e\u5411\u4e0a\u306b\u3088\u3063\u3066\u753b\u50cf\u8a8d\u8b58\u306e\u7cbe\u5ea6\u304c\u3068\u3066\u3082\u3088\u304f\u306a\u3063\u3066\u304d\u305f\u7d50\u679c\u3001\u6a5f\u68b0\u5b66\u7fd2\u81ea\u4f53\u306b\u7cbe\u901a\u3057\u3066\u3044\u306a\u3044\u6211\u3005\u3067\u3082\u7c21\u5358\u306b\u3053\u3046\u3044\u3063\u305f\u30a2\u30d7\u30ea\u304c\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u4eca\u56de\u306f\u3053\u306e\u9854\u8a8d\u8b58\u3092\u4f7f\u3063\u3066\u3001\u3082\u3046\u5c11\u3057\u5de5\u592b\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092<code>Python<\/code>\u3067\u3064\u304f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u30c6\u30fc\u30de\u306f\u305a\u306f\u308a\u3001<strong>\u300c\u9854\u304c\u4e0a\u3092\u5411\u304f\u3088\u3046\u306b\u5199\u771f\u304b\u3089\u5207\u308a\u51fa\u3059\u300d<\/strong>\u3067\u3059\u3002<\/p>\n<p>\u305c\u3072\u5b66\u7fd2\u306e\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3002<br \/>\n\uff08\u8a18\u4e8b\u306e\u6700\u5f8c\u3067\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2596 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/14-2.png\" alt=\"\" width=\"370\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/14-2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/14-2-300x284.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>\u203b \u958b\u767a\u74b0\u5883\uff1a Python 2.7<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4f8b\u3048\u3070\u6b21\u306e\u5199\u771f\u306b\u306f\u9854\u304c\uff15\u3064\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2257\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/faces.jpg\" alt=\"\" width=\"457\" height=\"640\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/faces.jpg 457w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/faces-214x300.jpg 214w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u5192\u982d\u3067\u7d39\u4ecb\u3057\u305f\u65b9\u6cd5\u3067\u3053\u306e\uff15\u3064\u306e\u9854\u3092\u691c\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3089\u306e\u9854\u306f\u3059\u3053\u3057\u305a\u3064\u50be\u3044\u3066\u3044\u3066\u4e0a\u3092\u5411\u3044\u3066\u3044\u307e\u305b\u3093\u3002\u7279\u306b\u5de6\u4e0b\u306e\u5973\u306e\u5b50\u306f\u3001\u5de630\u5ea6\u3050\u3089\u3044\u50be\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u9854\u304c\u4e0a\u3092\u5411\u304f\u3088\u3046\u306b\u56de\u8ee2\u3055\u305b\u3001\u6b21\u306e\u3088\u3046\u306b\u753b\u50cf\u3092\u5207\u308a\u51fa\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2626\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/family_faces.png\" alt=\"\" width=\"351\" height=\"114\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/family_faces.png 351w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/family_faces-300x97.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/p>\n<p>\u203b \u5206\u304b\u308a\u3084\u3059\u3044\u306e\u3067\u3001\u4e00\u756a\u9854\u306e\u50be\u304d\u304c\u5927\u304d\u3044\u5de6\u4e0b\u306e\u5973\u306e\u5b50\u306b\u6ce8\u76ee\u3057\u3066\u30b3\u30fc\u30c9\u3092\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h1>\u6e96\u5099<\/h1>\n<p>\u9854\u306e\u691c\u51fa\u306b\u306f\u6b21\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3082\u3057\u307e\u3060\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3001\u5225\u9014\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul>\n<li>OpenCV<\/li>\n<li>dlib<\/li>\n<li>numpy<\/li>\n<\/ul>\n<p>\u203b \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=2246\">Electron + Python \u3067\u9078\u3093\u3060\u9854\u306b\u30e2\u30b6\u30a4\u30af\u3092\u304b\u3051\u308b\u30a2\u30d7\u30ea\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09<\/a>\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u306f\u9854\u306e\u50be\u304d\u3092\u8a08\u7b97\u3059\u308b\u305f\u3081\u306b\u3001\u4e21\u76ee\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u9854\u306e\u30dd\u30a4\u30f3\u30c868\u30f6\u6240\u3092\u53d6\u5f97\u3067\u304d\u308b\u30e2\u30c7\u30eb <strong>&#8220;shape_predictor_68_face_landmarks.dat&#8221;<\/strong> \u3092<code>dlib<\/code>\u306e\u30d5\u30a1\u30a4\u30eb\u30da\u30fc\u30b8\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u5c55\u958b\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"http:\/\/dlib.net\/files\/\">http:\/\/dlib.net\/files\/<\/a><\/p>\n<p>\u203b \u30d5\u30a1\u30a4\u30eb\u540d\u306f\u3001<code>shape_predictor_68_face_landmarks.dat.bz2<\/code>\u3067\u3059\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u203b \u5c55\u958b\u5f8c\uff11\uff10\uff10MB\u8fd1\u304f\u306b\u306a\u308b\u306e\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u306b\u5c11\u3057\u6642\u9593\u304c\u304b\u304b\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/span><\/p>\n<p>\u3067\u306f\u6b21\u304b\u3089\u5b9f\u969b\u306b\u958b\u767a\u3092\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1>\u4e0a\u5411\u304d\u306e\u753b\u50cf\u3092\u5207\u308a\u51fa\u3059<\/h1>\n<h2>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u3080<\/h2>\n<p>\u307e\u305a\u306f\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<br \/>\n\uff08\u65e5\u672c\u8a9e\u3092\u4f7f\u3044\u305f\u3044\u306e\u3067utf-8\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\uff09<\/p>\n<pre>#!\/usr\/bin\/python\n# -*- coding: utf-8 -*-\n\n<strong>import cv2<\/strong>\n<strong>import dlib<\/strong>\n<strong>import numpy as np<\/strong>\n<strong>import math<\/strong><\/pre>\n<h2>\u9854\u691c\u51fa\u3068\u30dd\u30a4\u30f3\u30c8\u691c\u51fa\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u305d\u308c\u305e\u308c\u3001<code>dlib<\/code>\u306e<code>detector<\/code>\u3068<code>predictor<\/code>\u3092\u3064\u304f\u3063\u3066\u304a\u304d\u307e\u3059<\/p>\n<pre><strong>detector = dlib.get_frontal_face_detector()<\/strong>\n<strong>predictor = dlib.shape_predictor('***\/shape_predictor_68_face_landmarks.dat')<\/strong><\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001\u5f79\u5272\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>detector\u3000\u30fb\u30fb\u30fb\u3000\u9854\u304c\u3042\u308b\u4f4d\u7f6e\u3092\u53d6\u5f97\u3059\u308b<\/li>\n<li>predictor\u3000\u30fb\u30fb\u30fb\u3000\u76ee\u3084\u9f3b\u306a\u3069\uff16\uff18\u30f6\u6240\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3059\u308b<\/li>\n<\/ul>\n<h2>\u753b\u50cf\u3092OpenCV\u3067\u8aad\u307f\u8fbc\u3080<\/h2>\n<p>\u5207\u308a\u51fa\u3057\u305f\u3044\u9854\u304c\u5199\u3063\u3066\u3044\u308b\u753b\u50cf\u3092OpenCV\u3067\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<pre>im = <strong>cv2.imread('***\/family.jpg', cv2.IMREAD_COLOR)<\/strong>\n\nif im is None:\n    print('\u753b\u50cf\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093')\n    exit()<\/pre>\n<p>\u203b \u3082\u3057\u753b\u50cf\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<h2>detector\u3067\u9854\u3092\u691c\u51fa\u3059\u308b<\/h2>\n<p>\u7d9a\u3044\u3066\u3001<code>detector<\/code>\u3067\u9854\u306e\u4f4d\u7f6e\u3092\u691c\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>rects = detector(im, 1)<\/strong>\n\nif len(rects) == 0:\n    print('\u9854\u304c\u62bd\u51fa\u3055\u308c\u307e\u305b\u3093\u3067\u3057\u305f')\n    exit()<\/pre>\n<p>\u306a\u304a\u3001\u53d6\u5f97\u3055\u308c\u305f\u9854\u306f<code>dlib<\/code>\u306e<code>rectangles<\/code>\u3068\u3057\u3066\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u3082\u3057\u691c\u51fa\u3055\u308c\u305f\u9854\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<h2>\u9854\u3092\u5207\u308a\u51fa\u3059<\/h2>\n<p>\u5c11\u3057\u9577\u304f\u306a\u308a\u307e\u3059\u304c\u3001\u5168\u3066\u30eb\u30fc\u30d7\u51e6\u7406\u306e\u4e2d\u306b\u3042\u308b\u306e\u3067\u307e\u305a\u306f\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre>for index,rect in enumerate(rects):\n\n    # \u9854\u3060\u3051\u5207\u308a\u51fa\u3059\n    rectWidth = rect.width()\n    rectHeight = rect.height()\n    rectCenter = rect.center()\n    x_start = rectCenter.x - rectWidth\n    x_end = x_start + rectWidth*2\n    y_start = rectCenter.y - rectHeight\n    y_end = y_start + rectHeight*2\n    face_im = im[y_start:y_end, x_start:x_end]\n\n    # \u9854\u306e\u89d2\u5ea6\u3092\u4fee\u6b63\n    points = []\n    for point in predictor(im, rect).parts():\n        points.append([int(point.x), int(point.y)])\n    x_diff = points[45][0] - points[36][0]\n    y_diff = points[45][1] - points[36][1]\n    angle = math.degrees(math.atan2(y_diff, x_diff))\n    rotated_im = fitting_rotated_image(face_im, angle)\n\n    # \u56de\u8ee2\u5f8c\u306e\u753b\u50cf\u3067\u9854\u691c\u51fa\u3057\u3066\u753b\u50cf\u4fdd\u5b58\n    rotated_rects = detector(rotated_im, 1)\n    if len(rotated_rects) == 0:\n        print('\u9854\u304c\u62bd\u51fa\u3055\u308c\u307e\u305b\u3093\u3067\u3057\u305f')\n        continue\n\n    rotated_rect = rotated_rects[0]\n    x_start = rotated_rect.left()\n    x_end = rotated_rect.right()\n    y_start = rotated_rect.top()\n    y_end = rotated_rect.bottom()\n    cropped_im = rotated_im[y_start:y_end, x_start:x_end]\n    cv2.imwrite('face_'+ str(index) +'.jpg', cropped_im)<\/pre>\n<p>\u3067\u306f\u3072\u3068\u3064\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u9854\u3060\u3051\u5207\u308a\u51fa\u3059<\/h3>\n<p>\u307e\u305a\u306f\u691c\u51fa\u3055\u308c\u305f\u9854\u90e8\u5206\u3060\u3051\u3092\u5207\u308a\u51fa\u3057\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f\u5148\u306b\u753b\u50cf\u5168\u4f53\u3092\u56de\u8ee2\u3055\u305b\u3066\u3057\u307e\u3046\u3068\u3001\u9854\u306e\u5ea7\u6a19\u304c\u79fb\u52d5\u3057\u3066\u3057\u307e\u3046\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u306f\u5207\u308a\u51fa\u3059\u5927\u304d\u3055\u3067\u3059\u3002<br \/>\n\u3082\u3057\u3001\u691c\u51fa\u3055\u308c\u305f\u90e8\u5206\u3060\u3051\u5207\u308a\u51fa\u3057\u3066\u3057\u307e\u3046\u3068\u5f8c\u3067\u56de\u8ee2\u3055\u305b\u307e\u3059\u306e\u3067\u3001\u5fc5\u8981\u306a\u90e8\u5206\u304c\u6b20\u3051\u3066\u3057\u307e\u3046\u304b\u3082\u3057\u308c\u306a\u3044\u304b\u3089\u3067\uff53\uff0e<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u6b21\u306e\u3088\u3046\u306b\u691c\u51fa\u3055\u308c\u305f\u7e26\u6a2a\u3068\u3082\u306b\uff12\u500d\u306e\u9577\u3055\u3067\u5207\u308a\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2627\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/only_face_0.jpg\" alt=\"\" width=\"106\" height=\"106\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/only_face_0.jpg 106w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/only_face_0-100x100.jpg 100w\" sizes=\"auto, (max-width: 106px) 100vw, 106px\" \/><\/p>\n<h3>\u9854\u306e\u89d2\u5ea6\u3092\u4fee\u6b63<\/h3>\n<p>\u7d9a\u3044\u3066\u3001\u53d6\u5f97\u3055\u308c\u305f\u9854\u306e\u89d2\u5ea6\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<br \/>\n\u624b\u9806\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>predictor\u3067\u5de6\u53f3\u306e\u76ee\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3059\u308b<\/li>\n<li>\u305d\u306e\uff12\u3064\u306e\u5ea7\u6a19\u304b\u3089\u50be\u304d\u3092\u8a08\u7b97<\/li>\n<li>\u50be\u304d\u304c0\u306b\u306a\u308b\u3088\u3046\u306b\u9854\u753b\u50cf\u3092\u56de\u8ee2\u3055\u305b\u308b<\/li>\n<\/ol>\n<p>\u76ee\u306e\u4f4d\u7f6e\u306f\u3001<code>points<\/code>\u306e<code>[45]<\/code>\u3068<code>[36]<\/code>\u306b\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u30b3\u30fc\u30c9\u3067\u306f\u5272\u611b\u3057\u307e\u3057\u305f\u304c\u3001\u753b\u50cf\u306e\u56de\u8ee2\u3082\u5143\u306e\u30b5\u30a4\u30ba\u3068\u540c\u3058\u306b\u3057\u3066\u3057\u307e\u3046\u3068\u5fc5\u8981\u306a\u90e8\u5206\u304c\u6b20\u3051\u3066\u3057\u307e\u3046\u306e\u3067\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=1990\">opencv \u306e\u57fa\u672c\u7684\u306a\u753b\u50cf\u5909\u5f62\uff1a \u516812\u5b9f\u4f8b\uff01<\/a>\u00a0\u306e\u300c\u56de\u8ee2\u3059\u308b\u300d\u3067\u7d39\u4ecb\u3057\u305f\u300c\u3074\u3063\u305f\u308a\u53ce\u307e\u308b\u56de\u8ee2\u300d\u3092\u5fdc\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>def fitting_rotated_image(img, angle):\n    height,width = img.shape[:2]\n    center = (int(width\/2), int(height\/2))\n    radians = np.deg2rad(angle)\n    M = cv2.getRotationMatrix2D(center, angle, 1.0)\n\n    new_width = int(abs(np.sin(radians)*height) + abs(np.cos(radians)*width))\n    new_height = int(abs(np.sin(radians)*width) + abs(np.cos(radians)*height))\n\n    M[0,2] += int((new_width-width)\/2)\n    M[1,2] += int((new_height-height)\/2)\n\n    return cv2.warpAffine(img, M, (new_width, new_height))<\/pre>\n<p>\u3053\u308c\u3067\u753b\u50cf\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2628\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/rotated_face_0.jpg\" alt=\"\" width=\"142\" height=\"142\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/rotated_face_0.jpg 142w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/rotated_face_0-100x100.jpg 100w\" sizes=\"auto, (max-width: 142px) 100vw, 142px\" \/><\/p>\n<h3>\u56de\u8ee2\u5f8c\u306e\u753b\u50cf\u3067\u9854\u691c\u51fa\u3057\u3066\u753b\u50cf\u4fdd\u5b58<\/h3>\n<p>\u305d\u3057\u3066\u3001\u6700\u5f8c\u306b\u3082\u3046\u4e00\u5ea6<code>detector<\/code>\u3092\u4f7f\u3063\u3066\u9854\u691c\u51fa\u3092\u3057\u3001\u53d6\u5f97\u3055\u308c\u305f\u90e8\u5206\u3092\u5207\u308a\u51fa\u3057\u3066\u4fdd\u5b58\u3057\u3066\u3044\u307e\u3059\u3002\uff08\u3053\u3061\u3089\u306e\u307b\u3046\u304c\u56de\u8ee2\u524d\u306e\u30c7\u30fc\u30bf\u3092\u4fee\u6b63\u3057\u3066\u5207\u308a\u51fa\u3059\u3088\u308a\u7cbe\u5ea6\u304c\u9ad8\u3044\u3067\u3059\uff09<\/p>\n<p>\u3053\u3061\u3089\u304c\u5b9f\u969b\u306e\u753b\u50cf\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2629\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/face_0.jpg\" alt=\"\" width=\"52\" height=\"51\" \/>\u3000<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2630\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/face_4.jpg\" alt=\"\" width=\"43\" height=\"43\" \/>\u3000<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2633\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/face_1.jpg\" alt=\"\" width=\"52\" height=\"52\" \/>\u3000<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2632\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/face_2.jpg\" alt=\"\" width=\"52\" height=\"52\" \/>\u3000<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2631\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/face_3.jpg\" alt=\"\" width=\"62\" height=\"62\" \/><\/p>\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p><code>detector<\/code>\u306f\u9854\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u982d\u304c\u5c11\u3057\u6b20\u3051\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<br \/>\n\u305d\u306e\u305f\u3081\u3001\u305d\u3093\u306a\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u5207\u308a\u51fa\u3059\u90e8\u5206\u3092\u5927\u304d\u304f\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3053\u3061\u3089\u306f1.5\u500d\u306e\u30b5\u30a4\u30ba\u306b\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n<pre>rotated_rect_center = rotated_rect.center()\nx_start = int(rotated_rect_center.x - rotated_rect.width()*0.75)\nx_end = int(x_start + rotated_rect.width()*1.5)\ny_start = int(rotated_rect_center.y - rotated_rect.height()*0.75)\ny_end = int(y_start + rotated_rect.height()*1.5)\ncropped_im = rotated_im[y_start:y_end, x_start:x_end]<\/pre>\n<p>\u7d50\u679c\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2634\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/face_lg_0.jpg\" alt=\"\" width=\"79\" height=\"78\" \/><\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n<h1>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u4f7f\u3063\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001<code>shape_predictor_68_face_landmarks.dat<\/code>\u3068\u753b\u50cf\u306f\u3054\u81ea\u8eab\u3067\u6e96\u5099\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=2638&amp;tmstv=1777539258\" rel=\"nofollow\" id=\"download-link-2638\" data-redirect=\"false\" >\n\tPython\uff08OpenCV\uff09 \u9854\u304c\u4e0a\u3092\u5411\u304f\u3088\u3046\u306b\u5199\u771f\u304b\u3089\u5207\u308a\u51fa\u3059<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Python<\/code>\u3068<code>OpenCV<\/code>\u3001<code>dlib<\/code>\u306a\u3069\u3092\u4f7f\u3063\u3066\u9854\u304c\u4e0a\u3092\u5411\u304f\u3088\u3046\u306b\u753b\u50cf\u3092\u5207\u308a\u51fa\u3059\u65b9\u6cd5\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u753b\u50cf\u306e\u4e16\u754c\u3067\u306f\u6a5f\u68b0\u5b66\u7fd2\u306e\u6210\u679c\u304c\u5927\u304d\u304f\u306a\u3063\u3066\u304d\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u3053\u307e\u3067\u7c21\u5358\u306b\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3053\u3068\u306b\u306f\u30db\u30f3\u30c8\u306b\u9a5a\u304f\u3070\u304b\u308a\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u4eca\u56de\u306f\u4eba\u306e\u9854\u3092\u691c\u51fa\u3057\u307e\u3057\u305f\u304c\u3001<code>dlib<\/code>\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30da\u30fc\u30b8\u306b\u306f\u72ac\u3092\u691c\u51fa\u3059\u308b\u30e2\u30c7\u30eb\u3084\u8eca\u3092\u691c\u51fa\u3059\u308b\u3082\u306e\u307e\u3067\u3042\u308b\u3088\u3046\u3067\u3059\u3002\u307e\u3060\u8a66\u3057\u3066\u307f\u305f\u3053\u3068\u306f\u306a\u3044\u3067\u3059\u304c\u3001\u305d\u306e\u3046\u3061\u6642\u9593\u3092\u898b\u3064\u3051\u3066\u3084\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u3054\u671f\u5f85\u4e0b\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2595 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593\u3053\u306e\u30d6\u30ed\u30b0\u3067Electron + Python \u3067\u9078\u3093\u3060\u9854\u306b\u30e2\u30b6\u30a4\u30af\u3092\u304b\u3051\u308b\u30a2\u30d7\u30ea\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002 \u6700\u8fd1\u3067\u306f\u6a5f\u68b0\u5b66\u7fd2 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2625\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Python\uff08OpenCV\uff09 \u9854\u304c\u4e0a\u3092\u5411\u304f\u3088\u3046\u306b\u5199\u771f\u304b\u3089\u5207\u308a\u51fa\u3059\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2649,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[120,39],"tags":[121],"class_list":["post-2625","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv","category-python","tag-dlib"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2625"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2625\/revisions"}],"predecessor-version":[{"id":2648,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2625\/revisions\/2648"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2649"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}