ãã®ãã¥ãŒããªã¢ã«ã§ã¯ãOpenCVãPythonãããã³ImageMagickã䜿çšããŠã¢ãã¡ãŒã·ã§ã³GIFãäœæããæ¹æ³ã瀺ããŸãã 次ã«ããããã®ã¡ãœãããçµã¿åãããŠãOpenCVã§ããŒã ãžã§ãã¬ãŒã¿ãŒãäœæããŸãã
ç§ãã¡ã¯çãæã
ç¬ãå¿
èŠããããŸãã ãããŠãããããã«ã«ã¶ãèŠã€ããæè¯ã®æ¹æ³ã¯ããŒã ã䜿ãããšã§ãã ç§ã®ãæ°ã«å
¥ãã®ããã€ãïŒ
- ã«ãŒãããã¶ã«ãšã«ïŒãããããããã¯ç§ã®ããžãã¹ã§ã¯ãããŸããã
- äžæ©å«ãããªç«
- 壮倧ãªå€±æ
- ã°ããã¬ã€ã°ã¬ãã°
ããããå人çã«ã¯ããããã®ããŒã ã¯ãããããããŒã ãDeal With ItãïŒãDeal with itããŸãã¯ãUnderstand it yourãïŒãšæ¯èŒããããšã¯ã§ããŸããããã®äŸã¯èšäºã®åé ã«ãããŸããéåžžã次ã®å Žåã«äœ¿çšãããŸãã
- ããªããããããš/èšã£ãããšãæ¿èªããªã人ãžã®çããŸãã¯å察ãšããŠïŒãããã§å¯ŸåŠãããïŒ
- ãŸãã§ããªããå»ã£ãŠãããã®ããã«çŒé¡ããããåé¡ãæ±ãã人ãæŸã£ãŠããïŒãèªåã§ç解ãããïŒ
æ°å¹Žåãèè
ã®ããã°ã§æ¥œããèšäºãèªã¿ãŸããããã³ã³ãã¥ãŒã¿ãŒããžã§ã³ã䜿çšããŠãã®ãããªããŒã ãçæããæ¹æ³ãæãåºããŸããã å
é±ãç§ã¯ãã®ã¬ã€ããã©ãã«ãèŠã€ããããšãã§ããªãã£ãã®ã§ãããã¬ãŒãã³ã³ãã¥ãŒã¿ãŒããžã§ã³ã®å°é家ãããŒã ã®éå®å®¶ãšããŠãèªåã§ãã¥ãŒããªã¢ã«ãæžãããšã«ããŸããïŒ ïŒã¡ãªã¿ã«ãå
ã®ãœãŒã¹ã誀ã£ãŠç¥ã£ãŠããå Žåã¯ãèè
ã«æè¬ã§ããããã«ãç¥ãããã ãã
ãUPD ïŒ Kirk Kaiserã®ããã°
MakeArtWithPythonããå
ã®èšäºãèŠã€ããŸãããïŒ
OpenCVã§ããŒã ãžã§ãã¬ãŒã¿ãŒãéçºãããšã次ã®ãããªè²Žéãªå®çšçãªã¹ãã«ãåŠã¶ããšãã§ããŸãã
- 深局åŠç¿ææ³ã䜿çšããé¡æ€åº
- dlibã©ã€ãã©ãªã䜿çšããŠé¡ã®ã©ã³ãããŒã¯ãæ€åºããç®ã®é åãæœåºãã
- åä¿¡ããæ
å ±ã«åºã¥ããŠäž¡ç®ã®éã®å転è§ãèšç®ããæ¹æ³
- ãããŠæåŸã«ãOpenCVã䜿çšããŠã¢ãã¡ãŒã·ã§ã³GIFãçæããæ¹æ³ïŒImageMagickããå°ãå©ããåããŠïŒ
ãã®ã¬ã€ãã¯æ¥œãããŠé¢çœããã®ã§ãããšåæã«ãçŸå®ã®äžçã§åœ¹ç«ã€è²Žéãªã³ã³ãã¥ãŒã¿ãŒããžã§ã³ããã°ã©ãã³ã°ã¹ãã«ãæããŸãã
OpenCVã䜿çšããGIFã®äœæ
ã¬ã€ãã®æåã®éšåã§ã¯ãéçºç°å¢ã®æ£ããèšå®ãªã©ããã®ãããžã§ã¯ãã«å¿
èŠãªæ¡ä»¶ãšäŸåé¢ä¿ã«ã€ããŠèª¬æããŸãã
次ã«ãOpenCV GIFãžã§ãã¬ãŒã¿ãŒã®ãããžã§ã¯ã/ã«ã¿ãã°æ§é ãæ€èšããŸãã
ãããžã§ã¯ãã®æ§é ãç解ãããããã«ã次ã®ããšãæ€èšããŸãã1ïŒæ§æãã¡ã€ã«ã 2ïŒOpenCVã§GIFãäœæããPythonã¹ã¯ãªããã
æåŸã«ã人æ°ã®ããŒã ãDeal With Itãã§ããã°ã©ã ã®çµæãè©äŸ¡ããŸãã
åææ¡ä»¶ãšäŸåé¢ä¿
å³ 1. OpenCVãdlibãImageMagickã䜿çšããŠGIFãäœæããŸãOpencvããã³dlib
OpenCVã¯ããã¬ãŒã å
ã®é¡ãšåºæ¬çãªç»ååŠçã決å®ããããã«å¿
èŠã§ãã
OpenCVãã·ã¹ãã ã«ã€ã³ã¹ããŒã«ãããŠããªã
å Žåã¯ã
OpenCVã€ã³ã¹ããŒã«ã¬ã€ãã®ããããã«åŸã£ãŠãã ããã
Dlibã䜿çšããŠé¡ã®ã©ã³ãããŒã¯ãæ€åºããŸããããã«ãããé¡ã«2ã€ã®ç®ãèŠã€ããŠãµã³ã°ã©ã¹ããããããšãã§ããŸãã
ãã®æé ã䜿çšããŠdlibãã€ã³ã¹ããŒã«ã§ã
ãŸã ã
Imagemagick
ImageMagickã«æ
£ããŠããªãå Žåã¯ãç¡é§ã§ãã ããã¯ãå€ãã®ç»ååŠçæ©èœãåããã¯ãã¹ãã©ãããã©ãŒã ã®ã³ãã³ãã©ã€ã³ããŒã«ã§ãã
1ã€ã®ã³ãã³ãã§PNG / JPGãPDFã«å€æããŸããïŒ åé¡ãããŸããã
è€æ°ããŒãžã®PDFãäœæããããã«å¿
èŠãªç»åãããã€ããããŸããïŒ ç°¡åã§ãã
å€è§åœ¢ãç·ããã®ä»ã®åœ¢ç¶ãæãå¿
èŠããããŸããïŒ ãããŠããã¯å¯èœã§ãã
1ã€ã®ã³ãã³ãã§ãã¹ãŠã®åçãäžæ¬ã«ã©ãŒã°ã¬ãŒãã£ã³ã°ãŸãã¯ãµã€ãºå€æŽããã®ã¯ã©ãã§ããïŒ ãããè¡ãããã«ãOpenCVçšã®Pythonã§æ°è¡ãèšè¿°ããå¿
èŠã¯ãããŸããã
ImageMagickã¯ãä»»æã®ç»åããGIFãçæããŸãã
UbuntuïŒãŸãã¯RaspbianïŒã«ImageMagickãã€ã³ã¹ããŒã«ããã«ã¯ãaptã䜿çšããŸãã
OpenCVShellã§GIFãäœæãã
$ sudo apt-get install imagemagick
macOSã§ã¯ãHomeBrewã䜿çšã§ããŸãã
$ brew install imagemagick
imutils
ã»ãšãã©ã®èšäºãã³ãŒã¹ãæžç±ã§ã¯ã䟿å©ãª
imutilsç»ååŠç
ããã±ãŒãžã䜿çšããŠã
ãŸã ã pipã䜿çšããŠã·ã¹ãã ãŸãã¯ä»®æ³ç°å¢ã«ã€ã³ã¹ããŒã«ãããŸãã
$ pip install imutils
ãããžã§ã¯ãæ§é
å³ 2.ãããžã§ã¯ãæ§é ã«ã¯ãæ§æãã¡ã€ã«ãšPythonã¹ã¯ãªããã®2ã€ã®ãã£ã¬ã¯ããªãå«ãŸããŸããããžã§ã¯ãã«ã¯2ã€ã®ã«ã¿ãã°ããããŸãã
images/
ïŒã¢ãã¡ãŒã·ã§ã³GIFãäœæããå
¥åç»åã®äŸã ç§ã¯ããã€ãã®ç»åãèŠã€ããŸããããèªç±ã«è¿œå ããŠãã ãããassets/
ïŒãã®ãã©ã«ããŒã«ã¯ãé¡æ€åºåšãé¡ã©ã³ãããŒã¯æ€åºåšãããã³ãã¹ãŠã®ç»å+é¢é£ãã¹ã¯ãå«ãŸããŠããŸãã ãããã®ã¢ã»ããã䜿çšããŠãæåã®ãã©ã«ããŒã®å
ã®ç»åã«ãã€ã³ããšããã¹ããé
眮ããŸãã
æ§æå¯èœãªãã©ã¡ãŒã¿ãŒãå€æ°ããããã次ã®JSONæ§æãã¡ã€ã«ãäœæããããšã«ããŸããã1ïŒãã©ã¡ãŒã¿ãŒã®ç·šéã容æã«ããŸãã 2ïŒå¿
èŠãªã³ãã³ãã©ã€ã³åŒæ°ãå°ãªããªããŸãã ãã®ãããžã§ã¯ãã«å¿
èŠãªãã¹ãŠã®æ§æãã©ã¡ãŒã¿ãŒã¯
config.json
å«ãŸããŠã
config.json
ã
config.json
ããã³
create_gif.py
å
容ãèæ
®ããŠãã ããã
ã泚æ PerãïŒãããžã§ã¯ãã³ãŒããšã³ã³ãã¥ãŒã¿ãŒããžã§ã³ãæ©æ¢°åŠç¿ãOpenCVã®17ããŒãžã®ããã¥ã¢ã«ã¯ãç»é²åŸã«çºè¡ãããŸã ïŒãã©ãŒïŒ ãœãŒã¹ã³ãŒã ã ããã¥ã¢ã« ïŒãOpenCVã䜿çšããGIFçæ
ããã§ã¯ãOpenCV GIFãžã§ãã¬ãŒã¿ãŒã®äœæãç¶ããŸãããïŒ
JSONæ§æãã¡ã€ã«ã®ã³ã³ãã³ã
JSONæ§æãã¡ã€ã«ããå§ããŠã次ã«Pythonã¹ã¯ãªããã«é²ã¿ãŸãããã
æ°ãã
config.json
ãã¡ã€ã«ãéãã次ã®ããŒãšå€ã®ãã¢ãæ¿å
¥ããŸãã
OpenCVPythonã§GIFãäœæãã
{ "face_detector_prototxt": "assets/deploy.prototxt", "face_detector_weights": "assets/res10_300x300_ssd_iter_140000.caffemodel", "landmark_predictor": "assets/shape_predictor_68_face_landmarks.dat",
ãããã¯
ããã£ãŒãã©ãŒãã³ã°ã®OpenCVé¡æ€åºã¢ãã«ãã¡ã€ã«ã§ãã
æåŸã®è¡ã¯ãdlibãã§ã€ã¹ãã¬ãã£ã¯ã¿ãŒãžã®ãã¹ã§ãã
ãããŠä»ãç»åãã¡ã€ã«ãžã®ããã€ãã®ãã¹ããããŸãïŒ
"sunglasses": "assets/sunglasses.png", "sunglasses_mask": "assets/sunglasses_mask.png", "deal_with_it": "assets/deal_with_it.png", "deal_with_it_mask": "assets/deal_with_it_mask.png",
ãããã¯ã以äžã«ç€ºããµã³ã°ã©ã¹ãããã¹ããããã³ãããã«äžèŽãããã¹ã¯ãžã®ãã¹ã§ãã
ãŸãã掟æãªãµã³ã°ã©ã¹ãšãã¹ã¯ïŒ
å³ 3.ãã¯ã»ã«ä»ãã®ã¡ã¬ããå«ãã§ããïŒ ææ
¢ããŠå³ 4.ãµã³ã°ã©ã¹ã«ãã¹ã¯ãå¿
èŠãªçç±ãããããŸãããïŒ ããã«ææ
¢ããŠãã ãã-ãŸãã¯çãã®ããã«èšäºã®æ®ããèªãã§ãã ããããããŠä»ãç§ãã¡ã®ããã¹ãã¯ãDEAL WITH ITããšãã¹ã¯ã§ãïŒ
å³ 5. Helvetica Neue Condensedãå«ãã§ããïŒ ããã«å¯ŸåŠããå³ 6ïŒãã®ãã¹ã¯ã䜿çšãããšãããã¹ãã®åšå²ã«å¢çç·ãæç»ã§ããŸãã ãããå€åããªãã¯ããããªããããªãã¯åœå¢ã欲ããã§ããïŒ ææ
¢ããŠåçã«å¯Ÿå¿ããç»åããªãŒããŒã¬ã€ããã«ã¯ããã¹ã¯ãå¿
èŠã§ããããã«ã€ããŠã¯åŸã§èª¬æããŸãã
ããŒã ãžã§ãã¬ãŒã¿ãŒã®ããã€ãã®ãã©ã¡ãŒã¿ãŒãèšå®ããŸãã
"min_confidence": 0.5, "steps": 20, "delay": 5, "final_delay": 250, "loop": 0, "temp_dir": "temp" }
åãã©ã¡ãŒã¿ãŒã®å®çŸ©ã¯æ¬¡ã®ãšããã§ãã
min_confidence
ïŒæäœéå¿
èŠãªé¡æ€åºç¢ºçãsteps
ïŒæçµã¢ãã¡ãŒã·ã§ã³ã®ãã¬ãŒã æ°ã åãã¹ããããã¯ããµã³ã°ã©ã¹ãäžéšå¢çç·ããã¿ãŒã²ããïŒã€ãŸããç®ïŒã«ç§»åããŸããdelay
ïŒ100åã®1ç§åäœã®ãã¬ãŒã éã®é
延ãfinal_delay
ïŒ100åã®1ç§final_delay
ã§ã®æåŸã®ãã¬ãŒã ã®é
延ïŒããã¹ããä»ã®ãã¬ãŒã ãããé·ã衚瀺ãããã®ã§ããã®ã³ã³ããã¹ãã§åœ¹ç«ã¡ãŸãïŒãloop
ïŒãŒãã®å€ã¯ãGIFãæ°žé ã«ç¹°ãè¿ãããããšã瀺ããŸãããã以å€ã®å Žåãã¢ãã¡ãŒã·ã§ã³ã®ç¹°ãè¿ãæ°ã«æ£ã®æŽæ°ãæå®ããŸããtemp_dir
ïŒæçµGIFãäœæããåã«åãã¬ãŒã ãä¿åãããäžæãã£ã¬ã¯ããªã
ããŒã ãGIFãããã³OpenCV
JSONæ§æãã¡ã€ã«ãäœæããã®ã§ãå®éã®ã³ãŒãã«ç§»ããŸãããã
æ°ãããã¡ã€ã«ãéãã
create_gif.py
ãšããååãä»ããŠã次ã®ã³ãŒãã貌ãä»ããŸãã
ããã§å¿
èŠãªããã±ãŒãžãã€ã³ããŒãããŸãã ç¹ã«ãimutilsãdlibãããã³OpenCVã䜿çšããŸãã ãããã®äŸåé¢ä¿ãã€ã³ã¹ããŒã«ããã«ã¯ãäžèšã®åææ¡ä»¶ãšäŸåé¢ä¿ã»ã¯ã·ã§ã³ãåç
§ããŠãã ããã
ã¹ã¯ãªããã«ã¯å¿
èŠãªããã±ãŒãžãå«ãŸããŠããããã
overlay_image
é¢æ°ãå®çŸ©ããŸãã
def overlay_image(bg, fg, fgMask, coords):
overlay_image
é¢æ°ã¯ãèæ¯ç»åïŒ
bg
ïŒã®åº§æšåº§æš
ïŒåº§æš
ïŒxãyïŒ ïŒã«åæ¯ïŒ
fg
ïŒã課ãã
fgMask
åæ¯ãã¹ã¯äžã®ã¢ã«ãã¡éæ床ãå®çŸããŸãã
ãã¹ã¯ã®æäœãªã©ãOpenCVã®åºæ¬ã«ã€ããŠåŠç¿ããã«ã¯ã
ãã®ã¬ã€ããå¿
ããèªã¿
ãã ãã ã
ãã¬ã³ãããã»ã¹ãå®äºããã«ã¯ãã¢ã«ãã¡ãã¬ã³ããå®è¡ããŸãã
def alpha_blend(fg, bg, alpha):
ãã®ã¢ã«ãã¡ãã¬ã³ãã£ã³ã°ã®å®è£
ã¯
ãLearnOpenCVããã°ã§ãæäŸã
ããŠããŸãã
æ¬è³ªçã«ãåæ¯ãèæ¯ãããã³ã¢ã«ãã¡ãã£ãã«ãç¯å²
[0ã1]ã®æµ®åå°æ°ç¹æ°ã«å€æããŸãã 次ã«ãã¢ã«ãã¡ãã¬ã³ãã£ã³ã°ãå®è¡ããåæ¯ãšèæ¯ãè¿œå ããŠãåŒã³åºãå
ã®é¢æ°ã«æ»ãçµæãååŸããŸãã
ImageMagickãš
convert
ã³ãã³ãã䜿çšããŠãäžé£ã®ç»åãã¹ããGIFãçæã§ãããã«ããŒé¢æ°ãäœæããŸãã
def create_gif(inputPath, outputPath, delay, finalDelay, loop):
create_gif
é¢æ°ã¯äžé£ã®ç»åã
create_gif
ãããããããã¬ãŒã ãšã«ãŒãéã®æå®ãããé
延ã§GIFã¢ãã¡ãŒã·ã§ã³ã«åéããŸãã ImageMagickã¯ããããã¹ãŠãåŠçããŸã-ããŸããŸãªãã©ã¡ãŒã¿ãŒãåçã«åŠçããé¢æ°ã§
convert
ã³ãã³ããã©ããããã ãã§ãã
å©çšå¯èœãª
convert
åŒæ°ã
確èªããã«
ã¯ãããã¥ã¡ã³ããåç
§ããŠãã ãã ã ããã«ããã®ããŒã ãæã£ãŠããæ©èœã®æ°ã衚瀺ãããŸãïŒ
ç¹ã«ãã®é¢æ°ã§ã¯ã次ã®ããšãè¡ããŸãã
imagePaths
ãŸãã- æåŸã®ç»åã®ãã¹ãéžæããŸããããã«ã¯åå¥ã®é
延ããããŸãã
imagePaths
ãåå²ãåœãŠããŠãæåŸã®ãã¹ãé€å€ããŸãã- ã³ãã³ãã©ã€ã³åŒæ°ã䜿çšããŠã³ãã³ããäœæãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«
convert
ããŠGIFã¢ãã¡ãŒã·ã§ã³ãäœæconvert
ããæ瀺ããŸãã
ã¹ã¯ãªããã«ç¬èªã®ã³ãã³ãã©ã€ã³åŒæ°ãå²ãåœãŠãŸãã
å®è¡æã«åŠçããã3ã€ã®ã³ãã³ãã©ã€ã³åŒæ°ããããŸãã
--config
ïŒJSONæ§æãã¡ã€ã«ãžã®ãã¹ã åã®ã»ã¯ã·ã§ã³ã§æ§æãã¡ã€ã«ã確èªããŸããã--image
ïŒã¢ãã¡ãŒã·ã§ã³ã®äœæ察象ãšãªãå
¥åç»åãžã®ãã¹ïŒã€ãŸããé¡ã®æ€åºããµã³ã°ã©ã¹ã®è¿œå ãããã¹ãïŒã--output
ïŒçµæã®GIFãžã®ãã¹ã
ãããã®ååŒæ°ã¯ãã³ãã³ãã©ã€ã³/ã¿ãŒããã«ã§ã¹ã¯ãªãããå®è¡ãããšãã«å¿
èŠã§ãã
æ§æãã¡ã€ã«ãããã³ã¡ã¬ããšå¯Ÿå¿ãããã¹ã¯ãããŠã³ããŒãããŸãã
ããã§ãæ§æãã¡ã€ã«ãããŒãããŸãïŒå°æ¥çã«PythonèŸæžãšããŠå©çšã§ããããã«ãªãå¯èœæ§ããããŸãïŒã 次ã«ããµã³ã°ã©ã¹ãšãã¹ã¯ãåãä»ããŸãã
åã®ã¹ã¯ãªããããäœããæ®ã£ãŠããå Žåã¯ãäžæãã£ã¬ã¯ããªãåé€ããŠããã空ã®äžæãã£ã¬ã¯ããªãåäœæããŸãã äžæãã©ã«ããŒã«ã¯ãGIFã¢ãã¡ãŒã·ã§ã³ã®åã
ã®ãã¬ãŒã ãå«ãŸããŸãã
OpenCV深局åŠç¿é¡æ€åºåšãã¡ã¢ãªã«ããŒãããŸãã
ãããè¡ãã«ã¯ã
cv2.dnn.readNetFromCaffe
åŒã³åºã
cv2.dnn.readNetFromCaffe
ã
dnn
ã¢ãžã¥ãŒã«ã¯OpenCV 3.3以éã§ã®ã¿äœ¿çšå¯èœã§ãã é¡æ€åºåšã¯ãç»åå
ã®é¡ã®ååšãæ€åºããŸãã
å³ 7. OpenCV DNNã䜿çšããé¡æ€åºåšã®æäœæ¬¡ã«ã
dlibé¡ã©ã³ãããŒã¯äºæž¬åãããŒãããŸãã ç®ãçæ¯ã錻ãå£ãããã®ç·ãªã©ã®åã
ã®æ§é ãããŒã«ã©ã€ãºã§ããŸãã
å³ 8. dlibã§èŠã€ãã£ãã©ã³ãããŒã¯ãç§ã®é¡ã«éããããŸããã®ã¹ã¯ãªããã®åŸåã§ã¯ãç®ã®é åã®ã¿ãæœåºããŸãã
次ã«ãé¡ãèŠã€ããŸãããïŒ
ãã®ãããã¯ã§ã¯ã次ã®ããšãè¡ããŸãã
- å
ã®
image
ããŠã³ããŒããimage
ã - ãã¥ãŒã©ã«ãããã¯ãŒã¯ã®é¡æ€åºåšã«éä¿¡ãã
blob
ãäœæããŸãã ãã®èšäºã§ã¯ãOpenCVã®blobFromImage
ã«ã€ããŠèª¬æããŸãã - é¡æ€åºæé ãå®è¡ããŸãã
- æãé«ã確çå€ãæã€äººãèŠã€ãããããæå°ã®èš±å®¹ç¢ºçãããå€ãšæ¯èŒããŸãã åºæºãæºããããªãå Žåã¯ãã¹ã¯ãªãããçµäºããŸãã ãã以å€ã®å Žåã¯ãç¶è¡ããŸãã
次ã«ãé¡ãæœåºããŠã©ã³ãããŒã¯ãèšç®ããŸãã
é¡ãæœåºããŠé¡ã®ã©ã³ãããŒã¯ãèŠã€ããã«ã¯ã次ã®æé ãå®è¡ããŸãã
- é¡ã®åšãã®å¢çããã¯ã¹ã®åº§æšãæœåºããŸãã
- dlibã§
rectangle
ãªããžã§ã¯ããäœæããé¡ã®ããŒã«ã©ã€ãºãé©çšããŸãã - ïŒxãyïŒ
leftEyePts
ããã³rightEyePts
ãããããååŸããŸãã
ç®ã®åº§æšãæå®ãããšããµã³ã°ã©ã¹ãé
眮ããå Žæãšæ¹æ³ãèšç®ã§ããŸãã
ãŸããåç®ã®äžå¿ãèšç®ãã次ã«éå¿éã®è§åºŠãèšç®ããŸãã åãæäœã¯
ããã¬ãŒã å
ã®é¡ã®æ°Žå¹³æ¹åã®
é
眮ã§å®è¡ãããŸãã
ããã§ãã¡ã¬ããå転ããã³ãµã€ãºå€æŽã§ããŸãã ã¢ãã£ã³å€æåŸã«è¡šç€ºãããªãéšåãOpenCVãããªãã³ã°ããªã
rotate
ãåã«
rotate
ã§ã¯ãªã
rotate_boundé¢æ°ã䜿çš
ããããšã«æ³šæããŠãã ããã
ã¡ã¬ãã«é©çšãããã®ãšåãæäœãããã¹ã¯ã«ãé©çšãããŸãã ãã ãããã¹ã¯ã¯åžžã«ãã€ããªã§ãããããæåã«ã°ã¬ãŒã®æ¿æ·¡ã«å€æããŠ2å€åããå¿
èŠããããŸãã 次ã«ãã¡ã¬ãã®å Žåãšåãæ¹æ³ã§ãã¹ã¯ãå転ããŠãµã€ãºãå€æŽããŸãã
泚ïŒãã¹ã¯ã¯2ã€ã®å€ïŒ0ãš255ïŒã®ã¿ãæã€å¿
èŠãããããããã¹ã¯ã®ãµã€ãºãå€æŽãããšããæãè¿ãé£æ¥ãã€ã³ãã®è£éã䜿çšããããšã«æ³šæããŠãã ãã ã ä»ã®è£éæ¹æ³ã¯ããèŠãç®ãè¯ãã§ããããã¹ã¯ã«ã¯é©ããŠããŸããã ããã§ã¯ãæãè¿ãé£æ¥ç¹ã§ã®è£éã«é¢ããè¿œå æ
å ±ãååŸã§ããŸããæ®ãã®3ã€ã®ã³ãŒããããã¯ã¯ãGIFã¢ãã¡ãŒã·ã§ã³ã®ãã¬ãŒã ãäœæããŸãã
ã¡ã¬ãã¯ç»åã®äžéšããèœã¡ãŸãã åãã¬ãŒã ã§ãç®ãèŠããŸã§é¡ã®è¿ãã«è¡šç€ºãããŸãã JSONæ§æãã¡ã€ã«ã®
"steps"
å€æ°ã䜿çšããŠãåãã¬ãŒã ã®y座æšãçæããŸãã ãããè¡ãã«ã¯ãNumPyã®
linspace
é¢æ°ãå€ãã®åªåãªãã§äœ¿çšããŸãã
å·Šäžã«ãããã«ã·ããããç·ã¯å°ãå¥åŠã«èŠãããããããŸããããã¡ã¬ããç®å
šäœãã«ããŒããç®ã®äžå¿ã«ç§»åããã ãã§ã¯ãªãããšãä¿èšŒããããã«å¿
èŠã§ãã å軞ã«æ²¿ã£ããªãã»ãããèšç®ããããã«ãçµéšçã«ããŒã»ã³ããŒãžã決å®ããŸããã 次ã®è¡ã¯ãè² ã®å€ããªãããšãä¿èšŒããŸãã
overlay_image
é¢æ°ã䜿çšããŠãæçµ
output
ãã¬ãŒã
overlay_image
çæã
output
ã
次ã«ãå¥ã®ãã¹ã¯ã䜿çšããŠãDEAL WITH ITããšããããã¹ããé©çšããŸãã
æåŸã®ã¹ãããã§ã¯ãå®éã«ã¯å¥ã®ç»åã§ããããã¹ãã課ããŸãã
OpenCVãã©ã³ãã®ã¬ã³ããªã³ã°æ©èœã¯ããªãå¶éãããŠãããããç»åã䜿çšããããšã«ããŸããã ããã«ãããã¹ãã®åšãã«åœ±ãšå¢çç·ãè¿œå ãããã£ãã®ã§ããããããOpenCVã«ã¯ããããŸããã
ãã®ã³ãŒãã®æ®ãã®éšåã§ã¯ãç»åãšãã¹ã¯ã®äž¡æ¹ãèªã¿èŸŒãã§ãããã¢ã«ãã¡ãã¬ã³ãã£ã³ã°ãå®è¡ããŠæçµçµæãçæããŸãã
åãã¬ãŒã ããã£ã¹ã¯ã«ä¿åããŠãããGIFã¢ãã¡ãŒã·ã§ã³ãäœæããã ãã§ãã
çµæããã£ã¹ã¯ã«æžã蟌ã¿ãŸãã ãã¹ãŠã®ãã¬ãŒã ãçæããåŸã
create_gif
é¢æ°ãåŒã³åºããŠGIFã¢ãã¡ãŒã·ã§ã³ãã¡ã€ã«ãäœæããŸãã ããã¯ãImageMagick
convert
ã³ãã³ãã©ã€ã³ããŒã«ã«ãã©ã¡ãŒã¿ãŒãæž¡ãã·ã§ã«ã§ããããšã«æ³šæããŠãã ããã
æåŸã«ãäžæåºåãã£ã¬ã¯ããªãšåã
ã®ç»åãã¡ã€ã«ãåé€ããŸãã
çµæ
ããããã¯ãããŒã ãžã§ãã¬ãŒã¿ãŒãäœæãããã®ãèŠãŠã¿ãŸãããã
ãœãŒã¹ã³ãŒãããµã³ãã«ç»åããã£ãŒãã©ãŒãã³ã°ã¢ãã«ã
ããŠã³ããŒãããŠãã ããã 次ã«ãã¿ãŒããã«ãéãã次ã®ã³ãã³ããå®è¡ããŸãã
$ python create_gif.py --config config.json --image images/adrian.jpg \ --output adrian_out.gif [INFO] loading models... [INFO] computing object detections... [INFO] creating GIF... [INFO] cleaning up...
å³9.ãã®Pythonã¹ã¯ãªããã䜿çšããŠOpenCVããã³ImageMagickã§çæãããGIFã¢ãã¡ãŒã·ã§ã³ããã§ã¯ãOpenCVãšImageMagickã䜿çšããŠäœæãããGIFãèŠãããšãã§ããŸãã 次ã®ã¢ã¯ã·ã§ã³ãå®è¡ãããŸãã
- é¡ã®æ£ããæ€åºã
- ç®ã®ããŒã«ãªãŒãŒã·ã§ã³ãšãã®äžå¿ã®èšç®ã
- ã¡ã¬ããé¡ã«æ£ããèœã¡ãŸãã
ç§ã®ããã°ã®èªè
ã¯ãç§ããžã¥ã©ã·ãã¯ããŒã¯ã®å€§ããªãªã¿ã¯ã§ããããšãç¥ã£ãŠãããç§ã®æ¬ãã³ãŒã¹ãåŠç¿ã¬ã€ãã§ããèšåããŠããŸãã
ãžã¥ã©ã·ãã¯ããŒã¯ã奜ãã§ã¯ãããŸãããïŒ
ããããŸãããããã«ç§ã®çãããããŸãïŒ
$ python create_gif.py --config config.json --image images/adrian_jp.jpg \ --output adrian_jp_out.gif [INFO] loading models... [INFO] computing object detections... [INFO] creating GIF... [INFO] cleaning up...
å³ 10.ãžã¥ã©ã·ãã¯ã¯ãŒã«ã2ã®æè¿ã®ã¹ã¯ãªãŒãã³ã°ã®åçã«åºã¥ãOpenCV GIFã¢ãã¡ãŒã·ã§ã³ããã§ç§ã¯ã·ã§ãŒããžã¥ã©ã·ãã¯ã¯ãŒã«ãïŒ2ãã«ããŒãã®Tã·ã£ããçãŠãå
ã®ã°ã©ã¹ãšã³ã¬ã¯ã·ã§ã³æ¬ãæã£ãŠããŸãã
楜ããã¹ããŒãªãŒïŒ
5ã6幎åã劻ãšç§ã¯ãããªãå·ãã£ãºããŒã¯ãŒã«ãã®ãšãã³ããã»ã³ã¿ãŒããŒãããŒã¯ã蚪ããŸããã
ç§ãã¡ã¯ã³ããã«ããã®å³ããå¬ããéããããã«æ
è¡ã«è¡ãããšã決ããŸããããããŠãå¿
æ»ã«æ¥å
ãå¿
èŠãšããŸããã
æ®å¿µãªããããããªãã§ã¯åžžã«éšãéããæ°æž©ã¯ãããããŠ10°Cãè¶
ããŸããã
ã«ããã£ã¢ã³ã¬ãŒãã³ã®è¿ãã§ãããªã·ã£ã¯ç§ã®åçãæ®ããŸããã圌女ã¯ãèåŸã«ããç·è±ããªåºåã«å²ãŸãããçœãèãé»ãæãããŒãã®åžè¡é¬Œã®ããã«èŠãããšèšããŸãã
$ python create_gif.py --config config.json --image images/vampire.jpg \ --output vampire_out.gif [INFO] loading models... [INFO] computing object detections... [INFO] creating GIF... [INFO] cleaning up...
å³ 11. OpenCVãšPythonã䜿çšããŠããã®ããŒã ãŸãã¯å¥ã®ã¢ãã¡ãŒã·ã§ã³GIFãäœæã§ããŸãåãå€ãTrishaã¯ãœãŒã·ã£ã«ãããã¯ãŒã¯ã§åçãå
¬éããŸãããç§ã¯ããã«èããªããã°ãªããŸããã§ããã
PyImageConf 2018ã«åå ãã人ïŒ
ã¬ãã¥ãŒãèªã ïŒã¯ãç§ããã€ãåè«ãèšã£ãŠããããšãç¥ã£ãŠ
ããŸã ã 以äžã«äŸã瀺ããŸãã
質åïŒãªã³ããªãéè·¯ã暪åãã®ã¯ãªãã§ããïŒ $ python create_gif.py --config config.json --image images/rooster.jpg \ --output rooster_out.gif [INFO] loading models... [INFO] computing object detections... [INFO] creating GIF... [INFO] cleaning up...
å³ 12.äœã³ã³ãã©ã¹ãã§ãé¡ãèªèãããOpenCVã¯åçãæ£ããåŠçãããµã³ã°ã©ã¹ãäžããŸãåçïŒçãã¯èšããŸãã-ææ
¢ããŠãã ãããæåŸã«ãä»æ¥ã®ã¬ã€ããè¯ãããŒã ã§ç· ãããããŸããçŽ6幎åãç¶ãšç§ã¯å°ããªããŒã°ã«ãGemmaãæ¡çšããŸãããããã§ç§ã®è©ã«ãžã§ããèŠãããšãã§ããŸãïŒ $ python create_gif.py --config config.json --image images/pupper.jpg \ --output pupper_out.gif [INFO] loading models... [INFO] computing object detections... [INFO] creating GIF... [INFO] cleaning up...
å³ 13.ãžã§ã³ãã¯ããããã§ããããæããŸãããïŒæ¬¡ã«ããããã«åæããïŒã圌女ãããããããšã«åæããŸãããïŒããã«å¯ŸåŠãããAttributeErrorãšã©ãŒããããŸããïŒ
å¿é
ããªãã§ïŒãã®ãšã©ãŒã衚瀺ãããå ŽåïŒ $ python create_gif.py --config config.json --image images/adrian.jpg \ --output adrian_out.gif ... Traceback (most recent call last): File "create_gif.py", line 142, in <module> (lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"] AttributeError: module 'imutils.face_utils' has no attribute 'FACIAL_LANDMARKS_IDXS'
...次ã«ãimutilsããã±ãŒãžãæŽæ°ããã ãã§ãã $ pip install --upgrade imutils Collecting imutils ... Successfully installed imutils-0.5.1
ãªãã§ïŒ
ããã©ã«ãã§imutils.face_utils
ã¯ãdlibã«çµã¿èŸŒãŸãã68ãã€ã³ãã®ã©ã³ãããŒã¯æ€åºåšã䜿çšããŸãïŒãã®èšäºã®ããã«ïŒããããè¿
é5ç¹æ€åºä»ãimutilsãšååããŠããç§ã¯æè¿ãäž¡æ¹ã®æ€åºåšããµããŒãããããã«imutilsãæŽæ°ããŸããïŒãšã©ãŒã衚瀺ãããå ŽåããããŸãïŒããŸãšã
ä»æ¥ã®ãã¥ãŒããªã¢ã«ã§ã¯ãOpenCVã䜿çšããŠGIFãäœæããæ¹æ³ãåŠã³ãŸãããã¬ãã¹ã³ã楜ããããããã«ãOpenCVã䜿çšããŠãDeal With ItãGIFã¢ãã¡ãŒã·ã§ã³ãçæããŸãããããã¯ãã»ãšãã©ãã¹ãŠã®ãœãŒã·ã£ã«ãããã¯ãŒãã³ã°ãµã€ãã§äœããã®åœ¢ã§èŠããã人æ°ã®ããŒã ïŒããã³ç§ã®ãæ°ã«å
¥ãïŒã§ãããã®éçšã§ãã³ã³ãã¥ãŒã¿ãŒããžã§ã³ãšãã£ãŒãã©ãŒãã³ã°ã䜿çšããŠãããã€ãã®å®éçãªåé¡ã解決ããŸããã- 人ã®èå¥
- é¡ã®ã©ã³ãããŒã¯ãäºæž¬
- é¡ã®é åã®èå¥ïŒãã®å Žåãç®ïŒ
- é¡ãæããããã®ç®ã®éã®è§åºŠã®èšç®
- ã¢ã«ãã¡ãã¬ã³ãã£ã³ã°ã䜿çšããŠéæãªãã¬ã³ããäœæãã
æåŸã«ãçæãããäžé£ã®ç»åãååŸããOpenCVãšImageMagickã䜿çšããŠã¢ãã¡ãŒã·ã§ã³GIFãäœæããŸãããä»æ¥ã®ãã¥ãŒããªã¢ã«ãã楜ãã¿ãã ããïŒããªããããã奜ããªããã³ã¡ã³ããæ®ããŠãç§ã«ç¥ãããŠãã ãããæ°ã«å
¥ããªãã£ããšããŠãåé¡ã§ã¯ãããŸããããã ææ
¢ããŠãã ããã ;ïŒ