Raspberry Pi3ã§èªåãã¼ãåãè£ ç½®ãä½ã£ã
ã¯ããã«
æ°çæ å ±å·¥å¦å®é¨ç¬¬äºã¨ããæ¼ç¿ã§ãRaspberry Piãã¤ãã£ã¦ä½ããä½ããã¨ã«ãªãã¾ãããããã§AMATERASUã¨ããèªåãã¼ãåãè£ ç½®ãä½ã£ãã®ã§ç´¹ä»ãã¾ãã
ããããRaspberry Piã£ã¦?
Raspberry Pi3 Model B ãã¼ãï¼ã±ã¼ã¹ã»ãã (Element14ç, Clear)-Physical Computing Lab
- åºç社/ã¡ã¼ã«ã¼: TechShare
- ã¡ãã£ã¢: ã¨ã¬ã¯ãããã¯ã¹
- ãã®ååãå«ãããã° (3件) ãè¦ã
ããã§ããå®ãã¦å°åã§è²ããªã»ã³ãµã¼ãã¤ãã¦éã¹ãã³ã³ãã¥ã¼ã¿ã§ããä»åã¯ã«ã¡ã©ã¢ã¸ã¥ã¼ã«ã使ãã¾ããã
èªåãã¼ãåãè£ ç½®ã¨ã¯
èªåãã¼ãåãã®ç®æ¨ã¯ãè¬ç¾©ãæ®å½±ããåç»*1ãå¦çãããã¨ã§ããã¼ãã®ä»£ããã¨ãã¦ä½¿ããç»åãåºåãããã¨ã§ããå
·ä½çã«ã¯æ¬¡ã®gifã®ãããªç»åã次ã
åºåãã¦ããã®ãç®æ¨ã«ãã¦ãã¾ããé»ããªã£ã¦ããé¨åãä½ãã«ã¤ãã¦ã¯å¾ã»ã©èª¬æãã¾ãããããã«ã¯æ
å ±ããªãã¨ãããã¨ã表ãã¦ãã¾ãã
åç»ãå ¥åãã¦å¦çãããã¨ãã§ãã¾ããããªã³ã©ã¤ã³ã§å¦çãããã¨ãæ³å®ãã¦ãã¾ãã
åºåãããç»åã¯æ¬¡ã®ãããªæ¡ä»¶ãæºããããã«ãã¾ãã
- æ å ±ã®æ¼ãããªãã§ããæå¡ãé»æ¿ã«æ¸ãããã¨ã¯ãå ¨ã¦ã©ããã®ã¿ã¤ãã³ã°ã§åºåãããç»åã«åã£ã¦ãã¾ãã
- ç¡é§ãªæ å ±ãçãã¾ããã¤ã¾ããåãæ¿æ¸ãè¤æ°ååºåãããªãããã«ãã¾ãã
- æå¡ãåããã¾ãªãããã«ãã¾ãã
åºæ¬æ¦ç¥
AMATERASUãã©ã®ããã«åºåããç»åãä½ã£ã¦ãããã«ã¤ãã¦å¤§ã¾ãã«è¿°ã¹ã¾ããã¾ãé»æ¿ãï¼ã ãããï¼5ç§ããã«æ®å½±ãã¾ãããã®ç»åã®ãã¡ãæ å ±ãæ°ããã¦ãæå¡ãæ ãããã§ããªãé¨åã ããæ®ãã¾ãããã®ãããªé¨åç»åã次ã 足ãåããã¦ãããã¨ã§é»æ¿å ¨ä½ãåã£ãç»åãå¾ã¾ããã¾ããé»æ¿å ¨ä½ã®ç»åãå®æãã¦ãã¦ä»åºåãã¹ããå¦ãã«ã¤ãã¦ã®å¤å®ãè¡ãã¾ãã
ååã®ç±æ¥
èªç´ã§èº«ã®æ½ç½ã証æãã建éé ä½ä¹ç·å½ã¯ãé«å¤©åã«å± 座ã£ããããã¦ãç°ã®çãå£ãã¦æºãåãããã御殿ã«ç³ãæãæ£ããããã®ä¹±æ´ãåãããä»ã®ç¥ã¯å¤©ç §å¤§ç¥ã«è¦æ ãããããå¤©ç §å¤§ç¥ã¯ãèãããã£ã¦ã®ãã¨ãªã®ã ãã¨ã¹ãµãã²ããã°ã£ãã
ããããå¤©ç §å¤§ç¥ãæ©å±ã§ç¥ã«å¥ããè¡£ãç¹ã£ã¦ããã¨ãã建éé ä½ä¹ç·å½ãæ©å±ã®å±æ ¹ã«ç©´ãéãã¦ãç®ãå¥ãã 馬ãè½ã¨ãå ¥ãããããé©ãã1人ã®å¤©ã®æç¹å¥³ã¯æ¢ï¼ã²ï¼ãé°é¨ã«åºãã£ã¦æ»ãã§ãã¾ã£ããããã§å¤©ç §å¤§ç¥ã¯è¦çã¿ã¦ã天岩æ¸ã«å¼ãç¯ã£ããé«å¤©åãè¦åä¸å½ãéã¨ãªãããã¾ãã¾ãªç¦ï¼ã¾ãï¼ãçºçããã
天岩戸 - Wikipedia
ã天岩æ¸ã«å¼ãããã£ãã¢ããã©ã¹ããã§ããã¼ããæã«å
¥ã£ã¦åæ¥ã§ãããï¼ãã¨ããçç±ã§ãããã¾ã大ããçç±ã§ããªãããé æåãã¨ãã¨AMATERASUã«ãªããããªãã£ãããæ£å¼å称ãããããã§ããªãã§ã...
Raspberry Piã使ãå©ç¹
Raspberry Piã使ããã¨ã«ã¯ä»¥ä¸ã®ãããªå©ç¹ãããã¾ãã
- å®ãã§ããã«ã¡ã©ã¢ã¸ã¥ã¼ã«ãå«ãã¦ã6000åï½8000åç¨åº¦ã§æ¸ã¿ã¾ãã
- å°åãªã®ã§æ¯è¼çè¨ç½®ã¹ãã¼ã¹ã®åé¡ãèµ·ããã«ããã§ãã
- ãããã¯ã¼ã¯ããªãã¦ããã®å ´ã§å¦çãè¡ãã¾ãã
- ãããã¯ã¼ã¯ãããã°ãdropboxãtwitterã«ã¢ãããã¼ãã§ããéå ±æ§ãããã¾ãã
- ä»åã¯ãã£ã¦ãã¾ããããä»ã®ã»ã³ãµã¼ã使ããã¨ããæ¡å¼µæ§ãããã¾ãã
æ¢åææ³ã¨ã®æ¯è¼
ä»ã®æ¢åææ³ã¨æ¯ã¹ã¦ãã©ã®ãããªã¡ãªãããããã®ãã説æãã¾ãã
åç»
æ¢åææ³ã®ä¸ã¤ç®ã¯è¬ç¾©ãé²ç»ãããã¨ã§ããããã¨æ¯ã¹ãã¨ãAMATERASUã¯
- 容éãå°ãªãã¦æ¸ã¿ã¾ãã2æéã»ã©ã®è¬ç¾©ã§ãç»ååæ°æã§æ¸ãã®ã§çµæ¸çã§ãã
- å¾ã§è¦ç´ãã¨ãã«ä¾¿å©ã§ããåç»ããç»åã®æ¹ãç°¡åã«è¬ç¾©å ¨ä½ãè¦æ¸¡ããè¦ããé¨åãããã«æ¢ãã¾ãã
- æ¬è³ªçãªæ å ±ã¯å ¨ã¦åºåããã¦ãã¾ãã確ãã«åç»ã¯æ å ±ãå®ç§ã«ä¿åãã¦ãã¾ãããåé·ã§ããAMATERASUã§ååã§ãã
ãã·ã£ãã
ãã·ã£ããã¨ã¯è¿å¹´å¤§å¦ã§åé¡ã«ãªã£ã¦ããé»æ¿ãã¹ããã§æ®å½±ãã人ã®ãã¨ã§ãããã·ã£ããã¨æ¯ã¹ãã¨ãAMATERASUã¯
- ã·ã£ãã¿ã¼é³ãããªãã®ã§ãä»ã®åè¬è ã®è¿·æã«ãªãã¾ãããçªç¶ç«ã¡ä¸ãã£ã¦è¦çããµãããã¨ãããã¾ããã
- åºå®ããç¶æ ã§æ®å½±ãããã®ã§ãè¤æ°ã®ç»åãæ¯ã¹ã¦ãä½ç½®ãããã£ã¦ãã¦ãããã§ããææ¯ããããã¾ããã
- æå¡ãåããã¾ãªãã®ã§è¦ãããã§ãã
- æ®å½±ã¯èªåã§è¡ããããããè¬ç¾©ãè´ããã¨ã«éä¸ã§ãã¾ãã
ãã¼ãã®è§£èª¬
使ã£ããã®
ä¸ã§ç´¹ä»ããraspberry pi3ã使ã£ã¦ãã¾ããã«ã¡ã©ã¢ã¸ã¥ã¼ã«ã¯å年度ã®ãã®ãå¼ãç¶ãã ãããå ·ä½çã«ä½ãã¯åãããªãã§ããããããªããã
æ®å½±æ¹æ³
å³ã®ããã«é»æ¿ããæ°ã¡ã¼ãã«é¢ããæºã®ä¸ã«Raspberry piãè¨ç½®ãã¾ãããã®å¾ã«ã¡ã©ã¢ã¸ã¥ã¼ã«ãå²ã箸ã¨ã¬ã ãã¼ãã使ã£ã¦åºå®ãã¾ããæ®å½±ä¸æºãã«ã¡ã©ã¢ã¸ã¥ã¼ã«ã«è¡æãå ãããªãããé
æ
®ããã¦ãã¾ãã
ä¸çªåãã«ã¯äººãæåãåã£ã¦ããªãèæ¯ç»åãæ®å½±ããã¾ãã
ã½ããã®è§£èª¬
ç°å¢
Python2ãç¨ãã¾ãããç»åå¦çã«ã¯OpenCV 3.1ã使ãã¾ãããå®è¡ã¯iPython notebookãç¨ãã¾ãããUbuntuã¨Windowsã§åä½ç¢ºèªãã¦ãã¾ãã
æ¦è¦
AMATERASUã®æ¦è¦ã«ã¤ãã¦è§£èª¬ãã¾ããã¡ã¢ãªä¸ã«ã¯oldã¨nowã¨ãã2ã¤ã®ç»åãããã¾ããoldã¯ä¸ååã«åºåãããç»åã§ãnowã¯ç¾å¨åæä¸ã®ç»åã§ãã5ç§ããã«ã«ã¡ã©ã¢ã¸ã¥ã¼ã«ãé»æ¿ã®æ®å½±ããcapturedã¨ããç»åãå ¥ã£ã¦ãã¾ããcapturedã¯æå¡ãæ ãããã§ãããããªããã¤æ°ããé¨åã®ã¿ãåãåºããã¾ãããã®å¾ããã®é¨åç»åãnowã«è¶³ãåãããã¾ãã足ãåãããã¨ãããã§ã«nowã«å«ã¾ãã¦ããé åã ã£ãå ´åã¯capturedã§ä¸æ¸ãããã¾ããã¾ãåºåå¤å®ãè¡ãããå¿ è¦ãªãHDDã«ä¿åããããã¤ã¼ãããããã¾ãã
AMATERASUã§ã¯nowãåãåºãããcapturedã®ããã«é¨åç»åãæ±ãã¾ãããããã¯1次å çã«x座æ¨ï¼æ¨ªæ¹åï¼ã§åºéåããã¦ãæå¹ãã©ããã管çãã¦ãã¾ããåãx座æ¨ãæã¤ãã¯ã»ã«ã¯å ¨ã¦æå¹ãå ¨ã¦ç¡å¹ãã®2æã§ãã2次å çã«æ±ããªãã®ã¯ãè¨ç®ã軽ãããã®ã¨å®è£ ãç°¡åã«ããããã§ãã
解決ãã¹ãåé¡
æå¡ã®é¤å»
åºæ¬çã«ã¯é»æ¿ãæ®å½±ããã¨æå¡ãåãããã§ãã¾ãã¾ããããããªåæç»åãå¾ãããã«ã¯ããã¡ãã¨æå¡ãåãããã§ããé¨åãèå¥ãã¦é¤å»ããå¿ è¦ãããã¾ãã
åºåå¤å®ã»æ å ±ã®æ°æ§ã®å¤å®
AMATERASUã¯ç¾å¨åºåãã¹ããã©ãããå¤æããå¿
è¦ãããã¾ããã¾ããåºåãåé·ã«ãªããªãããã«ããã«ã¯ãå¤ãæ
å ±ãåãè¾¼ã¾ãªãããæ°ãã¤ããå¿
è¦ãããã¾ããä¾ãè¦ãªãããã®ãã¨ã説æãã¦ããã¾ãã
é»æ¿ã3åå²ãã¦ä½¿ããã¦ããç¶æ³ãèãã¾ãããã®ã¨ããæå¡ã¯ã¯ããã«â ãâ¡ãâ¢ã¨ããæ¿æ¸ãå·¦ããé ã«è¡ãã¾ããããã®å¾ãâ ãæ¶ãã¦ãããã«â£ã¨ããæ°ããæ¿æ¸ããã¾ãããâ¡ãâ¢ã¯ã¾ã æ¶ãããã«æ®ã£ã¦ãã¾ãã
ãã®ã¨ãâ ãæ¶ãã¦â£ãæ¸ãå§ãã段éã§1æç®ã®æ¿æ¸ã¯å®æãã¦ãã¾ãããã®ä¸ãâ£ãnowã«åãè¾¼ãã§ãã¾ãã¨â ãä¸æ¸ãããã¦æ¶ãã¦ãã¾ãã¾ãããã®ãããã®ã¿ã¤ãã³ã°ã§åºåãè¡ããªãã¦ã¯ããã¾ããã
ã¾ããâ£ãæ¸ããã¨ãã«åçãæ®ãã¨ãâ¡ãâ¢ã¨ããå¤ãæ¿æ¸ãä¸ç·ã«åã£ã¦ãã¾ãã¾ãããããããnowã«è¶³ãããããã¦ãã¾ãã¨ã2æç®ã®åºåç»åã«ãâ¡ãâ¢ãå«ã¾ãã¦ãã¾ãåé·ã«ãªã£ã¦ãã¾ãã¾ããã¾ãããã¯ãå¾ã«ç´¹ä»ããåºåå¤å®ã®ã¢ã«ã´ãªãºã ã誤åä½ãããåå ã«ãªãã¾ãããã®ããæ¿æ¸ãå¤ããã®ã§ãããã¨ãå¤å®ãããããããªãã°nowã«åãè¾¼ã¾ãªãä»çµã¿ãå¿ è¦ã§ãã
ãã®ãããªå¦çã¯äººã®ç®ããè¦ãã°å½ããåãªã®ã§ç°¡åã«æãããããã¾ããããRaspberry Piã«ããããããã«ã¯æ©æ¢°çã«æ±ããæ¡ä»¶ã¾ã§è½ã¨ãè¾¼ãã§ããå¿ è¦ãããã¾ãã
ã¡ã¤ã³ã«ã¼ã
AMATERASUã¯ä¸ã«è¿°ã¹ãåé¡ãè¸ã¾ãç»åãåæããããã«ã5ç§ããã«æ°ããç»åãæ®å½±ããããã³æ¬¡ã®ãããªã«ã¼ãã1åã¾ããã¾ãã
ç»åãå ¥ã£ã¦ããã¨ã¾ãæå¡ãæ¤åºããããã®é åãæ¶ããã¾ãã次ã«æ¿æ¸ãæ°ãããå¤å®ãããå¤ããã®ã¯å ¨ã¦æ¶ããã¾ãããã®ããã«ãã¦å¾ãããé¨åç»åãç¨ããåºåå¤å®ãè¡ããã¾ããåºåããªãã¨ãã¯nowã«ãã®é¨åç»åã足ãåãããã¾ãã
é»æ¿é åã®æ¤åº
ããããå ·ä½çãªå¦çã«ã¤ãã¦è¿°ã¹ã¦ããã¾ããã¾ãã¯åå¦çã«ã¤ãã¦ã§ããæ®å½±ããç»åã¯é»æ¿ä»¥å¤ã®ãã®ãæ ã£ã¦ãã¾ããããããã¯å¿ è¦ã§ã¯ããã¾ãããããã©ããã誤åä½ã®åå ã«ããªããã¾ãããã®ããé»æ¿é åãæ¤åºãã¦ãã以å¤ãã«ãããã¾ãã
ããã«ã¯ä¸çªåãã«æ®å½±ããèæ¯ç»åãç¨ãã¾ããèæ¯ç»åãHSV空éã«å¤æããç·è²ã®é åã1ã«ãªããã2å¤åãã¾ãããã®å¾ã1ã®ãã¯ã»ã«ãå¤ãy座æ¨ã®åºéãé»æ¿é åã¨ãã¾ãã
ãã®é»æ¿é åã®æ¤åºã¯blackboardDetectionã¨ããé¢æ°ã«ããè¡ããã¾ããã¾ããåãåºãé åã確å®ããå¾ã¯ãæ®å½±ããç»åã¯ã¾ãconvertToBlackboardSizeByValuesé¢æ°ã«ãã£ã¦é»æ¿é åã ããåãåºããã¾ãã
ä»åã¯æ®å½±ããã¨ãã®ã«ã¡ã©ã®åºå®ã®é½åä¸ç»åãå転ãã¦ãããããåå¦çã§å ã®åãã«æ»ãã¦ãã¾ãã
æå¡æ¤ç¥
æå¡ã®æ¤åºã«ã¤ãã¦èª¬æãã¾ããããã°ã©ã ä¸ã§ã¯find_intervalã¨ããé¢æ°ã«ãã£ã¦è¡ããã¦ãã¾ãã次ã®ç»åãä¾ã«èª¬æãã¾ããå人æ å ±ä¿è·ã®ãã赤è²ã®åè§ã§é¡ãé ãã¦ãã¾ãã
ã¾ãç»åãèæ¯ç»åã¨ã®çµ¶å¯¾å·®å(ãã¯ã»ã«ãã¨ã«å·®ã®çµ¶å¯¾å¤ãåã)ãè¡ãããã®å¾2å¤åãã¾ãã2å¤åããé¾å¤ã¯ãç»åãè¦ã¦æåãæ¸ãã¦ããã¨ãããã¯ã£ããããããå®ãã¾ããã*2
ããããã¨èæ¯ã¨ç°ãªãé¨åãã¤ã¾ãæåã¨äººãç½ããªãã¾ãããã®ç¶æ ãã人ã¨æåããã¾ãåé¢ãããã¨ãã§ããã°ã人ã®æ¤åºãã§ãã¾ãã人ã¨æåã¨ã®éãã¯ãå¾è ã¯ç´°ããã¨ã§ããããã§ç¸®å°å¦çï¼erosionï¼ã使ããã¨ã§æåã®ã¿ãæ¶ããã¨ãã§ãã¾ãã縮å°å¦çã¨ã¯æ¬¡ã®å³ã®ããã«ãå³å½¢ã®å¤å´ãåãå°ãããã¾ãã
æåã¯ç´°ããã縮å°å¦çã«ãã£ã¦æ¶ãã¦ãã¾ãã¾ãããæå¡ã¯å¤ªãããæ®ãã¾ãã縮å°å¦çããããã¨ãæ¡å¤§å¦çã§å ã«æ»ãã¨æ¬¡ã®ãããªç»åãå¾ããã¾ãã
確ãã«äººã®ã¿ãæ®ã£ã¦ãã¾ããé»æ¿æ¶ããæ®ã£ã¦ãã¾ããããæå¡æ¤åºã®æã¯é»æ¿ã®ä¸å¤®é¨ã®ã¿ãç¨ãã¾ãããã®å¾ã人ãããªãã¨ããã®ã¿1ãåããããªé åãä½ãã¨ç»åã®ä¸ã®ã°ã©ããå¾ããã¾ããæå¡ãåãããã®ãé¿ããããã大ããã«åºéãåãããã«ãã¦ãã¾ãã
ç»åå·®åã«ããåºåã»æ´æ°å¤å®
éå®ãããæ¸ç®
åºåãæ´æ°ã®å¤å®ãè¡ãã¨ããæ°ããæ¸ãè¾¼ã¾ããå ´æãæ¿æ¸ãæ¶ãããå ´æã¨ãã£ãæ å ±ãæç¨ã§ãããããã®æ å ±ãåãããã«ãç»åã®å·®åãåãã¾ãããã®ã¨ãã絶対差åã§ã¯ãªã次ã®ãããªãéå®ãããæ¸ç®ã*3ãç¨ãã¾ãã
å¼ãç®ãããçµæãè² ã®æ°ã«ãªãã¨ãã¯çµæã0ã«ä¸¸ãããããã¨ã ããæ®éã®æ¸ç®ã¨éãã¾ããç»åã«ä½¿ãéã¯ãã¯ã»ã«ãã¨ã«ãã®æ¼ç®ãé©å¿ãã¾ãã
絶対差åã¨ã®æ¯è¼
ãã¦ãåç¯ã§å®ç¾©ããæ¸ç®ã¯çµ¶å¯¾å·®åã¨æ¯ã¹ã¦ä½ãå©ç¹ãªã®ã§ããããã
次ã®ãããªä¾ã§èãã¦ã¿ã¾ããé»æ¿ã®å·¦å´ã«ãAãã¨æ¸ããã¦ããç»åãããå³å´ã«ãBãã¨ãããã¦ããç»åãå¼ãã¾ããæåã®é¨åãæ£ã«ãªããã2å¤åãã¦ããã¨ãã¾ãããã®ã¨ãã絶対差åãåãã¨Aã¨Bã®ä¸¡æ¹ãæ®ãã¾ããããã«å¯¾ãã¦ãéå®ãããæ¸ç®ã使ãã¨ãAã®ã¿ãæ®ãBã¯æ®ãã¾ãããBã®é¨åãå¼ãããçµæã¯è² ã«ãªã0ã«ä¸¸ãããã¦ãã¾ãããã§ãã
ãã®é対称æ§ã«ããæ¸ãè¾¼ã¿ãåé¤ã®èå¥ãã§ãã¾ããä¸ã®ãããªå¼ãç®ãèãã¾ããå·¦ã®ç»åã®æ¹ãå³ã®ãã®ããæ°ããã¨ãã¾ãããã®ç¶æ³ã§ã¯Aã¨ããæ°ããæ¸ãè¾¼ã¿ãããã¾ããã¾ãCã¨ããæ¿æ¸ãæ¶ããã¦ãã¾ããBã¯å¤åãã¦ãã¾ããã絶対差åã使ãã¨Aã¨C両æ¹ãã§ã¦ãã¦ãã¾ãã¾ããä¸æ¹éå®ãããæ¸ç®ã使ãã¨Aã®ã¿ãåãåºããã¨ãã§ãã¾ããã¤ã¾ãæ°ããæ¸ãè¾¼ã¾ããã¨ããã ããåãåºãã¦ãã¾ããå·¦ã®ç»åã®ã»ããå¤ãã¨ãã¯æç³»åãéã«ãªããåé¤ãããæ å ±Aã®ã¿ãåãåºããã¨ãã§ãã¾ãã
å®éã®ç»åã§ã®ä¾ã¯ã次ç¯ãåºåå¤å®ã¸ã®å¿ç¨ãã§è¦ã¦ããã¾ãã
ããã°ã©ã ä¸ã§ã¯ãèæ¯ç»åã¨çµ¶å¯¾å·®åãåã2å¤åããå¾ãã¯ã»ã«ãã¨ã«éå®ãããæ¸ç®ãé©å¿ãã¾ããå®éã®ç»åã¯å®ç¹è¦³æ¸¬ãã¦ãããã®ã®ãå¾®å°ãªæ¯åã®ããã§æ°ãã¯ã»ã«ç¨åº¦ã®ä½ç½®ã®ãããããã¾ããä½ç½®ããã®ããã§æ¼ç®ã®çµæãæ£ã«ãªãã¨ãæ¸ãè¾¼ã¿ãåé¤ã®èª¤æ¤åºã«ã¤ãªããã¾ãããããé¿ããããã ã®å³å´ã®ç»åã«ã¯2å¤åå¾æ¡å¤§å¦çãè¡ã£ã¦ãã¾ãã
åºåå¤å®ã¸ã®å¿ç¨
åºåãã¹ãã¿ã¤ãã³ã°ã¯ãã¤ãªã®ãèãã¦ããã¾ããã¾ãé»æ¿ãä¸åå²ããã¦ããç¶æ³ãä¾ã«ãã¾ããã¾ãâ ãâ¡ãâ¢ããããã¾ãããã®å¾â ãæ¶ãã¦â£ãæ¸ãã¾ããããã®ã¨ãï¼åç®ã®åºåããã¹ãã§ãããã®å¾â¡ã¨â¢ãæ¶ããâ¤ã¨â¥ããããã¾ããæå¾ã«â£ãæ¶ããâ¦ãæ¸ããã¾ããããã§2åãã®åºåããã¹ãã§ãã
ãã®ä¾ããããã¤åºåãã¹ããã決ããä¸ã§ãæ¿æ¸ãæ¶ãããã¨ããæ å ±ãæç¨ã ã¨ãããã¨ãåããã¾ãããã ããâ¡ã¨â¢ãæ¶ãããæã«ã¯åºåãè¡ãã¹ãã§ã¯ããã¾ãããã¾ã â£ããæ¸ããã¦ããããç¡é§ãªåºåã«ãªã£ã¦ãã¾ãããã§ãã
以ä¸ãã¾ã¨ããã¨ãåºåãã¹ããªã®ã¯ãååã®åºåå¾ã«æ¸ãããé¨åãæ¶ãããã¨ããã¨ãªãã¾ããååã®åºåå¾ã«æ¸ãããé¨åã¯ãç¾å¨åæä¸ã®nowãã®ãã®ã§ããåé¤ã®å¤å®ã¯ãå¤ãç»åããæ°ããç»åãéå®ãããæ¸ç®ã§å¼ãã°ã§ãã¾ãããã¤ã¾ã ãè¨ç®ãã¦ãæ£ã«ãªããã¯ã»ã«ãããã°åºåãã¹ãã¨ãªãã¾ãããã®æ¡ä»¶ã¯ç¹ã«å·¦ããæ¸ãå§ãããã¨ãä»®å®ãã¦ãã¾ããããªã®ã§ãæå¡ãå·¦å´ã®æ¿æ¸ãæ®ãã¦æ°ããæ¿æ¸ãå§ããå ´åãªã©ã§ãããã¡ãã¨åä½ãã¾ãã
å®éã®ç»åã«ç¨ããã¨ããã®æ¼ç®ã§ã¯ãã¤ãºãæ®ã£ã¦ãã¾ãã¾ããããã§ãã¬ã¦ã¹ã¼ããã§ãã¤ãºé¤å»ãè¡ã£ã¦ãã¾ããã¾ãå¤ãæ å ±ã®æ¶å»ããã¾ããããééãã¦nowã«åãè¾¼ãã§ããå ´åããããæ¶ãããã¨ã誤åºåããã¦ãã¾ãã¾ããããã§ããã°ã©ã ä¸ã§ã¯ããnowã®ãã¡oldã®æ¿æ¸ãæ¶ãããé¨åããã¤ã¾ã ã¨å ±éé¨åãæã¤ãã¨ãæ¡ä»¶ã«å ãããã¨ã§ããã¹ãã«åä½ããããã«ãã¦ãã¾ãã
ã¾ãæå¡ã¯æã«æ¸ãç´ããè¡ãã¾ããæ¸ãç´ãã§ãæ¿æ¸ãæ¶ãã¦ããã®ã§ ã¯æ£ã«ãªã£ã¦ãã¾ãã¾ãããã®ã¨ãã«åºåããã¨ç¡é§ã«ç»åã®ææ°ãå¢ãã¦ãã¾ãã¾ããããã§ãé¾å¤ããã¾ãè¨å®ãããã¨ã§1è¡ç¨åº¦æ¶ããå ´åã«ã¯åºåããªãããã«ãã¦ãã¾ãã
æå¾ã«å®éã®ç»åã§ã¯ã©ããªãããè¦ã¦ã¿ã¾ãããã1æç®ãnowã§2æç®ãcapturedããæå¡ãæ¶å»ãããã®ã§ããcapturedã®å·¦å´ã¯æå¡ãå± ããããç¡å¹ãªåºéã¨ãã¦æ±ããé»ã表示ããã¦ãã¾ããnowã®é»ãé¨åã¯ãã¾ã capturedã足ãããããã¦ããããæ å ±ããªãç¡å¹ãªåºéã§ããé»æ¿ã®å·¦å´ã®æ¿æ¸ãcapturedã§ã¯æ¶ããã¦ããã®ãåããã¾ãã3æç®ã® ã«ããã¦ããã¡ãã¨ãã®æ¿æ¸ã®æ¶å»ãæ¤åºããã¦ãã¾ããæå¾ã«ãããx軸æ¹åã«å°å½±ãã¦ãé¾å¤ãè¶ããã¨ããã1ã¨ãããã¨ã§4æç®ã®åºé表ç¾ãå¾ã¾ãã
æ´æ°å¤å®ã¸ã®å¿ç¨
æ®å½±ããæ¿æ¸ã®ãã¡ãå¤ãé¨åãæ¶å»ãã¦æ°ããé¨åã®ã¿ãnowã«è¶³ãããããªãã¦ã¯ããã¾ãããã©ãæ å ±ã®æ°æ§ãå¤å®ãã¦ããããè¦ã¦ããã¾ãã
åºæ¬çã«ã¯ãcapturedã®ãã¡oldã¨æ¯ã¹ã¦æ°ããæ¸ãè¾¼ã¾ããé¨åãæ°ããæ
å ±ã§ããããã¯
ã§æ±ãããã¨ãã§ãã¾ããããããæ¸ã足ããè¡ãããã¨åé¡ãçãã¾ãã次ã®ãããªä¾ãèãã¦ãã¾ãã
oldã§ã¯â ãâ¡ãâ¢ã¨ããæ¿æ¸ãããã¦ãã¾ãããcapturedã§ã¯â ã¨â¡ã¯æ¶ãããâ ã®é¨åã«â£ãæ¸ããã¦ãã¾ããã¾ããâ¢ã®å 容ãâ£ãæ¸ãå§ããå¾ä»ã足ãã¦ãâ¢'ã«ãªã£ã¦ãã¾ãããã®ãããªæ¸ã足ãã¯æã èµ·ããã¾ãããã®ã¨ãwitternã¯â¢ãæ¸ããã¦ããé»æ¿ã®å³å´ã§ãæ£ã«ãªãã¾ããããããâ¢ã¯å¤ãæ å ±ãªã®ã§nowã«åãè¾¼ãã®ã¯ééãã§ããoldã®æ¹ã«ä¿®æ£ãå ããã¹ãç¶æ³ã§ãã
ããã§ããoldã®ãã¡capturedã§ã¯æ¶å»ãããé¨åããç¨ãã¾ããããã¯
ã§æ±ãããã¨ãã§ãã¾ããæ¶å»ãããå ´æã«æ¸ãè¾¼ã¾ããæ
å ±ã¯æ°ããæ
å ±ã ã¨èãããã¾ããããã§ãerasedã¨writtenã®å
±éé¨åãæ°ããæ
å ±ã ã¨ãã¾ãããã®ããã«ããã¨writtenã®ãã¡ãæ¬å½ã«æ°ããé¨åã¨æ¸ã足ããåãããã¨ãã§ãã¾ããwrittenãæ£ã¨ãªãåºéãã¨ã«ãerasedã¨å
±éé¨åãæã¤ãå¤å®ãã¦ãããã§ãããªãã°nowã«å ããããã§ãªããªãæ¸ã足ããªã®ã§oldã«ä¿®æ£ãå ãã¾ãã
çæ³çã«ã¯ä¸ã®ããã«æ¸ã足ãããã¾ãèå¥ãã¦ãoldãä¿®æ£ãã¦ååºåããã¹ãã§ãããå®éã«ã¯é度ã«oldã®ä¿®æ£ãããããã¾ãåããªãã£ããããæ¸ã足ãã¯ç¡è¦ãã¦æ¨ã¦ãããã«ãã¦ãã¾ãããã®åé¡ã«ã¤ãã¦ã¯å¾ã§è©³ããè¿°ã¹ã¾ãã
çµæ
nowã®æ´æ°
AMATERASUï½Automatic Blackboard Copy Deviceï½
é»ãé¨åã¯ç¡å¹ï¼ã¾ã 足ããã¦ããªãï¼é¨åãæã
æã¨ãç´ã¨ãæ®ã£ã¦ã¾ããã©æçµçã«ãã¾ãè¡ã£ããçµæãªã¼ã©ã¤ã§ã
åºåãã¡ã¤ã«
æã
é»ãé¨åãæ®ã£ã¦ãã¾ãããããã¯ããããä½ãæ¸ãè¾¼ã¾ãã¦ããªãé¨åãªã®ã§åé¡ãªãã§ããä»åã¯èª¬æã®ããé»ãæ®ãã¦ãã¾ãããèæ¯ç»åã§é»ãé¨åãåããã°è¦æ ããè¯ãç»åãå¾ããã¾ãã
åé¡ç¹
試é¨åæ°ã®å°ãªã
ä»åã¯2åãå¥ã®äººã«å¯¾ãã¦åãæ室ã§å®é¨ãè¡ãã¾ãããä»ã®æ室ã§æ£å¸¸ã«åããã¯åããã¾ãããã¾ããä»ã®äººã§è©¦ããå ´åãæå¡ãä»åæ³å®ãã¦ããªãåããããããã§ãã¾ãåããªãå¯è½æ§ãããã¾ãã*4
ã¾ããå®é¨æéã足ããªãã£ããããªã³ã©ã¤ã³å¦çã®å®é¨ã¯è¡ãã¦ãã¾ãããä»çµã¿çã«ãããããªã³ã©ã¤ã³ã§ãåãã¨ã¯æãã¾ãã...
ç°å¢ä¾åæ§
ããã¤ãã®é¾å¤ãåæã«è¨å®ãã¦ãããããç §æã®å ·åã«ãã£ã¦ã¯åããªãããããã¾ãããã¾ããã¯ã¤ããã¼ãã移åå¼é»æ¿ã«ã¯å¯¾å¿ãã¦ãã¾ããã
oldã®æ´æ°åé¡
æ¬å½ã¯æ¸ã足ãããã£ãã¨ãã¯ãoldãä¿®æ£ãã¦ååºåããããã«ãããã¨ãã¦ãã¾ãããããããå®éã«åãããã¨ãããæ¬æ¥nowã«å ¥ãã¹ããã®ãoldã®ä¿®æ£ã«ã¤ãããã¦ãã¾ããoldããã¡ããã¡ãã«ãªãã¨ããåé¡ãçºçãã¾ããããã®ããããã®æ©è½ã¯åé¤ããã¦ãã¾ãã
åå ã¯writtenããããã«æ±ã¾ãã¨ã¯éããªããã¨ã§ãã人éã¯ç»åãè¦ã¦ã©ããåºã¾ãããèªèã§ãã¾ãããåç´ã«å°å½±ãã¦é¾å¤ãè¶ãããã§å¤æãã¦ããAMATERASUã§ã¯ãã¾ããããªãå ´åãããã¾ããå¹³æ»åããããããã«ã¯ãã¦ãã¾ãããæ¬æ¥ã²ã¨ã¾ã¨ãã§ããã¹ãé¨åãã°ãã°ãã«ãªã£ãããéã«é¢ãã¦ããã¹ãé¨åããã£ã¤ããããã¦ãã¾ãã¾ããåè ãèµ·ããã¨ãnowã«è¶³ãã¹ãç»åãoldã®ä¿®æ£ã«ä½¿ããã¦ãã¾ãã¾ããå°å½±ã¨é¾å¤ä»¥å¤ã®ãã¾ã1次å åã使ãã¹ãã§ããããã¾ããoldãä¿®æ£ãããã©ããããå³ããåºæºã§å¤æãããã¨ã§ãã¾ãããããããã¾ããã
ãã®ä»
1次å çã«å¦çãã¦ãããããé»æ¿ãæãã«ä½¿ãããã¨èª¤åä½ãã¦ãã¾ãã¾ããããã«é¢ãã¦ã¯ããããæ¸ãæ¹ããæå¡ãæªãã¨æãã¾ãã...
ä»åã¯ã«ã¡ã©ãåºå®ãã¦ãã¾ããããããã§ããã¬ãææçºçãã¦ãã¾ããããã£ãããããããªã»ã³ãµã¼ã使ããã®ã§å é度ã»ã³ãµã¼ã§ãã¬ãæ¤åºããã¨é¢ç½ãããªã¨æã£ã¦ã¾ãããã¨ã¯ããããã¨ã®ä½ç½®ãããããèæ¯ç»åãªãã§ã®å¦çãã§ããã¨ãããæ±ç¨çã«ãªãã¨æãã¾ãã
ã¾ã¨ã
ãã¾ãåããã®ãã§ããããããã
è¬è¾
@co_co_cocoaæ°ã«ã¯ãã¼ãã®æ®å½±ã¨å®é¨ã¸ã®ä½¿ç¨ã«å¿«ããååããã ãã¾ããããããã¨ããããã¾ãã
ココア (@co_co_cocoa) | Twitter
ãã®å®é¨ã¯5人ã§è¡ã£ããã®ã§ãããèªå1人ã®ææã§ã¯ããã¾ãããçå¡ã®çããã«ã¯ã¢ã«ã´ãªãºã ãèããã¨ãã®è°è«ãå®è£
æã«å¤§å¤ãä¸è©±ã«ãªãã¾ããã
æ°çæ
å ±ç¬¬7ç 究室ã«ã¯ãRaspberry Piçã®æ©æã®è³¼å
¥ãå®é¨ã®æå°ãçºè¡¨ç·´ç¿ãªã©æ§ã
ãªé¢ã§æ¯æ´ãã¦ããã ãã¾ãããããã«æè¬ã®æã表ãã¾ãã
ã½ã¼ã¹ã³ã¼ã
# -*- coding: utf-8 -*- #get_ipython().magic(u'matplotlib inline') #%matplotlib inline import matplotlib.pyplot as plt import numpy as np import cv2 import time import os #from picamera.array import PiRGBArray #from picamera import PiCamera LECTURE_TIME=105*60 MODE=1 #0 camera 1 file PICTURES_DIRECTORY="./Serial_Experiments_Cocoa/" OUTPUT_DIRECTORY="./BlackboardRecord/" INTERVAL_TIME=0 RECAPTURE_TIME=2 BLACKBOARD_WIDTH=1920 def convertToBlackboardSize(image): image2 = cv2.flip(image,-1) return image2[350:900,:,:] def blackboardDetection(image): piet = image piet_hsv = cv2.cvtColor(piet, cv2.COLOR_BGR2HSV) # threshold for hue channel in blue range blue_min = np.array([70, 30, 70], np.uint8) blue_max = np.array([150, 255, 255], np.uint8) threshold_blue_img = cv2.inRange(piet_hsv, blue_min, blue_max) #threshold_blue_img = cv2.cvtColor(threshold_blue_img, cv2.COLOR_GRAY2RGB) #plt.imshow(threshold_blue_img) #plt.show() col_sum = np.sum(threshold_blue_img, axis=1) #plt.plot(col_sum) #plt.show() left = 540 right = 540 for i in range(540): k = 540 - i - 1 if col_sum[k] > 1000: left = k else: break for i in range(540): k = 540 + i if col_sum[k] > 1000: right = k else: break return left, right def convertToBlackboardSizeByValues(lower, upper, image): image2 = cv2.flip(image[lower:upper,:],-1) return image2 BACKGROUNDIMAGE_temp=cv2.imread(PICTURES_DIRECTORY+"blackboard0.jpg") lower_cut, upper_cut = blackboardDetection(BACKGROUNDIMAGE_temp) BACKGROUNDIMAGE = convertToBlackboardSizeByValues(lower_cut, upper_cut, BACKGROUNDIMAGE_temp) # def find_interval(aaa): # kernel = np.zeros((4,4),np.uint8) # kernel[2,:]=1 # kernel[3,:]=1 # ddd7 = np.zeros(50*1920).reshape([50,1920]) # ddd8 = cv2.threshold(aaa[100:495,:,0],140,188,cv2.THRESH_BINARY)[1] # ddd8 = cv2.erode(ddd8,kernel,iterations=3) # ddd8 = cv2.dilate(ddd8,kernel,iterations = 3) # ddd5 = np.concatenate([ddd7,ddd8]) # hsv = cv2.cvtColor(aaa, cv2.COLOR_BGR2HSV) # ddd2 = cv2.threshold(hsv[:,:,1],70,np.max(hsv[:,:,0]),cv2.THRESH_BINARY)[1] # ddd1 = cv2.threshold(hsv[:,:,0],20,188,cv2.THRESH_BINARY)[1] # ddd1 = cv2.threshold(ddd1,20,188,cv2.THRESH_BINARY_INV)[1] # ddd3 = cv2.erode(ddd2[50:495,:],kernel,iterations=4) # ddd3 = cv2.dilate(ddd3,kernel,iterations = 4) # ddd4 = cv2.erode(ddd1[50:495,:],kernel,iterations=4) # ddd4 = cv2.dilate(ddd4,kernel,iterations = 4) # eee = np.mean( np.uint(ddd3) + np.uint(ddd4)+np.uint(ddd5) ,0) # left = 0 # right = 0 # for i,j in enumerate(eee): # if j>8: # left = i-200 # if(left<=0): # left = 0 # if(i>=5): # break # for i,j in enumerate(eee[::-1]): # if j>8: # right = 1920-i+200 # if(right>1920): # right = 1920 # if(i>=5): # break # ####print left,right # interval = np.ones(1920) # interval[left:right]=0 # ddd = np.zeros(1920*550).reshape([550,1920]) # ddd[:,:left]=0 # ddd[:,right:1920]=0 # ddd[:,left:right]=1 # ddd = np.uint8(ddd) # ###true_image = cv2.bitwise_and(aa3,aa3,mask=(1-ddd)) # #cv2.imwrite("./hoge/hey.jpg",aaa) # #plt.imshow(aaa) # return interval def find_interval(image): diff = cv2.absdiff(image, BACKGROUNDIMAGE) grayed = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY) under_thresh = 30 maxValue = 255 th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY) eroded = cv2.erode(drop_back[50:450,:], neiborhood8, iterations = 3) dilated = cv2.dilate(eroded, neiborhood8, iterations = 15) row_sum = np.sum(dilated, axis=0) binarized = np.fmax(np.zeros(row_sum.size), thresold_1dim(row_sum,1000)) res = np.ones(1920) - interval_expansion_strong(binarized, 300) return np.uint8(res) def interval_expansion_strong(interval, iteration): width = iteration kernel = np.ones(iteration) expanded = np.convolve(interval, kernel, mode='same') res = np.fmax(np.zeros(interval.size), thresold_1dim(expanded, 1)) return np.uint8(res) SMOOTH_WIDTH=50 IMAGE_DIFFERENCE_TO_ARRAY_DILATION_ITERATION = 4 neiborhood8 = np.ones((3,3),dtype=np.uint8) def filtered_erase(img1, img2): img = erase_detection(img1,img2) blured = cv2.GaussianBlur(img,(5,5),0) res = binarize(blured, 50) return res def thresold_1dim(array, threshold): delta = array - threshold*np.ones(array.size) return np.sign(delta) def binarize(img, threshold): under_thresh = threshold maxValue = 255 th, drop_back = cv2.threshold(img, under_thresh, maxValue, cv2.THRESH_BINARY) return drop_back def image_difference(img1, img2): #Compute max(img1 - img2, 0) and return 1 dimentional array. background is blackboard0.jpg diff1 = cv2.absdiff(img1, BACKGROUNDIMAGE) diff2 = cv2.absdiff(img2, BACKGROUNDIMAGE) erase = filtered_erase(diff1, diff2) return erase def image_difference_to_array(img1, img2, interval,threshold): #Compute max(img1 - img2, 0) and return 1 dimentional array. background is blackboard0.jpg erase=image_difference(img1,img2) row_sum = np.sum(erase[50:450,:], axis=0) filtered = row_sum*interval kernel = np.ones(SMOOTH_WIDTH)/SMOOTH_WIDTH smoothed = np.convolve(filtered, kernel, mode='same') res = np.fmax(np.zeros(smoothed.size), thresold_1dim(smoothed,threshold)) return np.uint8(res) def strict_image_difference_to_array(img1, img2,interval, threshold): diff = image_difference(img1, img2) row_sum = np.sum(diff[50:450,:] ,axis=0) filtered = row_sum*interval binarized = np.fmax(np.zeros(filtered.size), thresold_1dim(filtered,threshold)) smoothed = interval_expansion(interval_expansion(binarized, 40) , 40) return np.uint8(smoothed) def image_difference3(img1, img2, img3): #Compute max(img1 - img2 - img3, 0) and return 1 dimentional array. background is blackboard0.jpg diff1 = cv2.absdiff(img1, BACKGROUNDIMAGE) diff2 = cv2.absdiff(img2, BACKGROUNDIMAGE) diff3 = cv2.absdiff(img3, BACKGROUNDIMAGE) grayed = cv2.cvtColor(diff2, cv2.COLOR_BGR2GRAY) under_thresh = 30 maxValue = 255 th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY) d_diff2 = cv2.dilate(drop_back,neiborhood8,iterations=IMAGE_DIFFERENCE_TO_ARRAY_DILATION_ITERATION) grayed = cv2.cvtColor(diff3, cv2.COLOR_BGR2GRAY) under_thresh = 30 maxValue = 255 th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY) d_diff3 = cv2.dilate(drop_back,neiborhood8,iterations=IMAGE_DIFFERENCE_TO_ARRAY_DILATION_ITERATION) grayed = cv2.cvtColor(diff1, cv2.COLOR_BGR2GRAY) under_thresh = 30 maxValue = 255 th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY) b_diff = drop_back delta = b_diff - d_diff2 - d_diff3 res = (delta + abs(delta))/2 blured = cv2.GaussianBlur(res,(5,5),0) res2 = binarize(blured, 50) return res2 def image_difference_to_array3(img1, img2, img3, interval,threshold): #Compute max(img1 - img2 - img3, 0) and return 1 dimentional array. background is blackboard0.jpg res2=image_difference3(img1,img2,img3) row_sum = np.sum(res2[50:450,:], axis=0) filtered = row_sum*interval kernel = np.ones(SMOOTH_WIDTH)/SMOOTH_WIDTH smoothed = np.convolve(filtered, kernel, mode='same') return np.uint8(np.fmax(np.zeros(smoothed.size), thresold_1dim(smoothed, threshold))) def erase_detection(img1, img2): #TESTED ONLY FOR ABSOLUTE DIFFERENCE WITH BACKGROUND,detect lost of information of img1 when img2 is taken grayed = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) under_thresh = 30 maxValue = 255 th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY) d_diff2 = cv2.dilate(drop_back,neiborhood8,iterations=IMAGE_DIFFERENCE_TO_ARRAY_DILATION_ITERATION) grayed = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) under_thresh = 30 maxValue = 255 th, drop_back = cv2.threshold(grayed, under_thresh, maxValue, cv2.THRESH_BINARY) b_diff = drop_back delta = b_diff - d_diff2 res = (delta + abs(delta))/2 return res def interval2intervals(interval): now1 = False a = -1 intervals_pair = [] for i in range(interval.size): if ((not now1) and interval[i] == 1): a = i now1 = True elif (now1 and interval[i] == 0): intervals_pair.append((a,i)) now1 = False elif (now1 and i == interval.size - 1): intervals_pair.append((a,i+1)) intervals = [] for i in range(len(intervals_pair)): a = intervals_pair[i][0] b = intervals_pair[i][1] res = np.zeros(interval.size,np.uint8) for j in range(b-a): res[a+j] = 1 intervals.append(np.array(res)) return intervals def interval_expansion(interval, iteration): kernel = np.concatenate((np.zeros(iteration),np.ones(iteration))) expanded1 = np.convolve(interval, kernel, mode='same') res1 = np.fmax(np.zeros(interval.size), thresold_1dim(expanded1, 1)) kernel = np.concatenate((np.ones(iteration),np.zeros(iteration))) expanded2 = np.convolve(interval, kernel, mode='same') res2 = np.fmax(np.zeros(interval.size), thresold_1dim(expanded2, 1)) return np.uint8(np.fmax(interval,res1*res2)) def prodImgInterval(img,interval): interval2 =interval[:,np.newaxis] interval2 =interval2[np.newaxis,:] return img*np.uint8(interval2) #mainLoop #initialize if MODE==0: #camera=PiCamera() #rawCapture=PiRGBArray(camera) #time.sleep(0.1) starttime=time.time() nowtime=starttime else: fileId=10 nowimage=np.array(BACKGROUNDIMAGE, copy=True) nowInterval=np.zeros(BLACKBOARD_WIDTH,np.uint8) oldimage=np.array(BACKGROUNDIMAGE, copy=True) oldInterval=np.ones(BLACKBOARD_WIDTH,np.uint8) firstOutputFlag=True outputCount=-1 recaptureFlag=False starttime=time.time() nowtime=starttime fileId=10 weakRenzoku=0 for f in os.listdir(OUTPUT_DIRECTORY[0:len(OUTPUT_DIRECTORY)-1]): os.remove(OUTPUT_DIRECTORY+f) for f in os.listdir('./Debug'): os.remove('./Debug/'+f) while nowtime<starttime+LECTURE_TIME: if MODE==0: #camera.capture(rawCapture,format="bgr") #image=rawCapture.array print("no camera") else: if fileId>8799: break image=cv2.imread(PICTURES_DIRECTORY+"blackboard%d.jpg"%fileId) fileId+=10 image=convertToBlackboardSizeByValues(lower_cut, upper_cut,image) nohumanInterval=find_interval(image) #if recaptureFlag: # if MODE==0: # time.sleep(RECAPTURE_TIME) # continue #oldgraph=prodImgInterval(oldimage,oldInterval*nohumanInterval) #imagegraph=prodImgInterval(image,nohumanInterval) #characteristic functions old_and_now = oldInterval*nowInterval only_old = oldInterval*(1-nowInterval) only_now = nowInterval*(1-oldInterval) neither_old_nor_now = (1-nowInterval)*(1-oldInterval) erasedInterval=image_difference_to_array(oldimage, image, oldInterval*nohumanInterval,200)*oldInterval*nohumanInterval old_minus_now_Interval = image_difference_to_array(oldimage, nowimage, nowInterval*oldInterval,200)*oldInterval*nowInterval #writtenInterval= (old_and_now*image_difference_to_array3(image, oldimage,nowimage,nohumanInterval*old_and_now) + only_now*image_difference_to_array(image,nowimage,nohumanInterval*only_old) + only_old*image_difference_to_array(image, oldimage,nohumanInterval*only_old) + neither_old_nor_now*image_difference_to_array(image, BACKGROUNDIMAGE, nohumanInterval*neither_old_nor_now))*nohumanInterval owrittenInterval = nohumanInterval*(oldInterval*image_difference_to_array(image,oldimage,nohumanInterval*oldInterval,200) \ + (1-oldInterval)*image_difference_to_array(image, BACKGROUNDIMAGE, nohumanInterval,200)) writtenInterval = interval_expansion(owrittenInterval, 30) writtenInterval = interval_expansion(writtenInterval, 30) writtenIntervals=interval2intervals(writtenInterval) if outputCount==-1: notCompatibleInterval=strict_image_difference_to_array(nowimage,image,nohumanInterval*nowInterval,3000)*nowInterval*nohumanInterval weakNotCompatibleInterval=image_difference_to_array(nowimage,image,nohumanInterval*nowInterval,200)*nowInterval*nohumanInterval else: notCompatibleInterval=strict_image_difference_to_array(nowimage,image,nohumanInterval*nowInterval,3000)*nowInterval*nohumanInterval*old_minus_now_Interval weakNotCompatibleInterval=image_difference_to_array(nowimage,image,nohumanInterval*nowInterval,200)*nowInterval*nohumanInterval*old_minus_now_Interval s=np.sum(notCompatibleInterval) t=np.sum(weakNotCompatibleInterval) if s>100: #debug_output_all_status() weakRenzoku=0 if outputCount==-1: outputCount=0 else: oldimage=prodImgInterval(oldimage,oldInterval) cv2.imwrite(OUTPUT_DIRECTORY+'output%d_%d.png'%(outputCount, fileId),oldimage) outputCount+=1 # print('output%d fileId=%d'%(outputCount,fileId)) # plt.imshow(prodImgInterval(oldimage,oldInterval)) # plt.show() oldimage=np.uint8(np.array(nowimage,copy=True)) nowimage=np.uint8(np.array(BACKGROUNDIMAGE,copy=True)) oldInterval = np.array(nowInterval,copy=True) nowInterval = np.zeros(BLACKBOARD_WIDTH) elif (weakRenzoku==0 and t>100) or (0<weakRenzoku and weakRenzoku<3): weakRenzoku+=1 else: weakRenzoku=0 nowWrittenInterval=np.zeros(BLACKBOARD_WIDTH) for writtenInt in writtenIntervals: if np.sum(writtenInt*erasedInterval)>20 or outputCount==-1: #debug #DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_COUNTER += 1 #if DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_LOWER <= DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_COUNTER and DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_COUNTER <= DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_UPPER: #debug_output_all_status() #print('WRITTENINTERVAL was outputed after'+str(DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_COUNTER)+'times update') #debug end nowimage=prodImgInterval(image,writtenInt)+prodImgInterval(nowimage,nowInterval*(1-writtenInt)) nowInterval=1-(1-nowInterval)*(1-writtenInt) nowWrittenInterval+=writtenInt #else: # oldimage=prodImgInterval(image,writtenInt)+prodImgInterval(oldimage,oldInterval*(1-writtenInt)) # oldInterval=1-(1-oldInterval)*(1-writtenInt) # print("fileId=%d s=%d oC=%d wR=%d"%(fileId,s,outputCount,weakRenzoku)) # if fileId<1500: # continue # Row=3 # Column=3 # fig,ax=plt.subplots(Row,Column,figsize=(10,4)) # fig.tight_layout(); # for r in range(Row): # for c in range(Column): # ax[r,c].axis([0,BLACKBOARD_WIDTH,-0.2,1.2]) # ax[0,0].plot(notCompatibleInterval) # ax[0,0].set_title('notCompatibleInterval') # ax[1,0].plot(writtenInterval) # ax[1,0].set_title('writtenInterval') # ax[2,0].plot(nowWrittenInterval) # ax[2,0].set_title('nowWrittenInterval') # ax[0,1].plot(erasedInterval) # ax[0,1].set_title('erasedInterval') # ax[1,1].plot(nohumanInterval) # ax[1,1].set_title('nohumanInterval') # #ax[1,1].plot(nowInterval) # #ax[1,1].set_title('nowInterval') # ax[2,1].plot(old_minus_now_Interval) # ax[2,1].set_title('old_minus_now_Interval') # ax[0,2].plot(nowInterval) # ax[0,2].set_title('nowInterval') # ax[1,2].plot(weakNotCompatibleInterval) # ax[1,2].set_title('weakNotCompatibleInterval') # ax[2,2].plot(oldInterval) # ax[2,2].set_title('oldInterval') #plt.show() plt.savefig('./Debug/intervals%d.png'%fileId) temptime=nowtime nowtime=time.time() sleeptime=INTERVAL_TIME-(nowtime-temptime) if sleeptime>0:# and MODE==0: time.sleep(sleeptime) #last output cv2.imwrite(OUTPUT_DIRECTORY+'output%d.png'%outputCount,prodImgInterval(oldimage, oldInterval)) outputCount += 1 cv2.imwrite(OUTPUT_DIRECTORY+'output%d.png'%outputCount,prodImgInterval(nowimage, nowInterval)) #mainLoopEnd #debug DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_LOWER = 0 DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_UPPER = 0 DEBUG_OUTPUT_WRITTENINTERVAL_N_TIMES_UPDATE_COUNTER = 0 def debug_output_all_status(): print('fileID,s') print fileId,s print('oldimage') plt.imshow(prodImgInterval(oldimage, oldInterval)) cv2.imwrite('./Debug/'+ str(fileId) + 'oldimage.png',prodImgInterval(oldimage, oldInterval)) plt.show() print('nowimage') plt.imshow(prodImgInterval(nowimage,nowInterval)) plt.show() cv2.imwrite('./Debug/'+ str(fileId) + 'nowimage.png',prodImgInterval(nowimage, nowInterval)) print('image') plt.imshow(image) plt.show() cv2.imwrite('./Debug/'+ str(fileId) + 'image.png',image) erase=image_difference(nowimage,image) res=image_difference_to_array(nowimage,image,nohumanInterval*nowInterval) #temptemp=np.array(erase,copy=True) print('now_erase') plt.imshow(erase) cv2.imwrite('./Debug/'+ str(fileId) + 'now_erase.png',erase) plt.show() print('now_erased_non_binarized') row_sum = np.sum(erase[50:500,:], axis=0) width = 50 filtered = row_sum*nohumanInterval*nowInterval kernel = np.ones(width)/width smoothed = np.convolve(filtered, kernel, mode='same') plt.plot(smoothed) plt.show() print('now_erased(Interval)') plt.plot(res) plt.show() print('nohumanInterval') plt.plot(nohumanInterval) plt.show() print('writtenInterval_image') writtenInterval_image = nohumanInterval*(oldInterval*image_difference(image,oldimage) + (1-oldInterval)*image_difference(image, BACKGROUNDIMAGE)) #writtenInterval_image= old_and_now*image_difference_to_array3_(image, oldimage,nowimage) + only_now*image_difference_to_array_(image,nowimage) + only_old*image_difference_to_array_(image, oldimage) + neither_old_nor_now*image_difference_to_array_(image, BACKGROUNDIMAGE) plt.imshow(writtenInterval_image) cv2.imwrite('./Debug/'+str(fileId)+'writtenInterval.png', writtenInterval_image) plt.show() print('writtenInterval') plt.plot(writtenInterval) plt.show() erase=image_difference(oldimage,image) res=image_difference_to_array(oldimage,image,nohumanInterval*oldInterval) #temptemp=np.array(erase,copy=True) print('erased(old - image)') plt.imshow(erase) cv2.imwrite('./Debug/'+ str(fileId) + 'erase(old-image).png',erase) plt.show() print('erased_non_binarized') row_sum = np.sum(erase[50:500,:], axis=0) width = 50 filtered = row_sum*nohumanInterval*oldInterval kernel = np.ones(width)/width smoothed = np.convolve(filtered, kernel, mode='same') plt.plot(smoothed) plt.show() print('erasedInterval') plt.plot(res) plt.show() erase=image_difference(oldimage,nowimage) res=image_difference_to_array(oldimage,nowimage,nowInterval*oldInterval) #temptemp=np.array(erase,copy=True) print('old - now') plt.imshow(erase) cv2.imwrite('./Debug/'+ str(fileId) + 'old-now.png',erase) plt.show() print('old_minus_now_non_binarized') row_sum = np.sum(erase[50:500,:], axis=0) width = 50 filtered = row_sum*nohumanInterval*oldInterval kernel = np.ones(width)/width smoothed = np.convolve(filtered, kernel, mode='same') plt.plot(smoothed) plt.show() print('old_minus_now_Interval') plt.plot(res) plt.show() #debug end
*1:æ£ç¢ºã«ã¯é£ç¶æ®å½±ãããç»å
*2:å¿ç¨ãèãããªãé¾å¤ãè¨å®ããã®ãèªååãããããã®å¤ã§ç°å¢ãå¤ãã£ã¦ããã¾ãããã確èªãã¹ãã§ãã
*3:Wikipediaå çã¯ããå¼ãã§ã¾ãããè¨ç®çè«ã¨ãã§ããã§ã¦ãããã¤ã§ããã 原始再帰関数 - Wikipedia
*4:ä»åã§ã人ãæã£ã¦ããç´ãæ¤åºãã«ããã¨ããçªç¶ãããã¾ããã¨ãã£ãäºæ³ãã¦ããªãã£ãåé¡ãããã¾ããã