OpenCV-Python ã使ã£ã¦å²ç¢ã®åæå¤å®ããã¦ã¿ãã (1)
ãã®è¨äºã¯ CAMPHOR- Advent Calendar 2015 ã®16æ¥ç®ã®è¨äºã§ãï¼
ããã«ã¡ã¯ï¼@asadamanã§ãï¼
æè¿ï¼OpenCV-Pythonã§éãã§ããã®ã§ï¼ããã«ã¤ãã¦æ¸ãã¦ã¿ããã¨æãã¾ãï¼
OpenCV-Pythonã®ãã¥ã¼ããªã¢ã«ããã£ã¦ããã ãã§ãåå楽ããã®ã§ããï¼ããã使ã£ã¦ãããªã®ãã§ããããããªã£ã¦ããã®ãããã¨ã¯ã¯ã¯ã¯ãã¦ãã¾ãããï¼
ã¨ãããã¨ã§ï¼ãå²ç¢ã®åæå¤å®ãããã¦ã¿ããã¨ããç®æ¨ãç«ã¦ã¦ã¿ã¾ããï¼
å²ç¢ã¯é£å°åãã®ã²ã¼ã ã§ï¼åæã¯ã©ã¡ãã®æ¹ãå¤ãé£å°ãåãããã§æ±ºã¾ãã¾ãï¼é£å°ã¨ã¯ï¼èªåã®ç³ï¼é»ç³ãç½ç³ï¼ã§å²ã¾ããç¢ç¤ã®äº¤ç¹ã®æ°ã§ãï¼
ï¼åããããã説æã¯å²ç¢ã®åºæ¬ï¼å²ç¢ã®åè² ã®ä»ãæ¹ãåèã«ãã¦ããã ãã°ã¨æãã¾ãï¼ï¼
ãã¦ï¼å¦çã®æµãã¨ãã¦ã¯ãã£ããåãã¦ï¼
ç»åããç¢ç¤ã®é åãåãåºã ï¼â ãã¡è©°ãï¼æ»ç³ãªã©ã®å¦çï¼ â 交ç¹ãæ¤åºãï¼ç½é»ã®é£å°ãè¨ç®ãã
ã¨ããæãã«ãªãã¨æãã¾ãï¼
æ¬å½ã¯å ¨é¨ãã£ã¦è¨äºã«ãããã£ãã®ã§ããï¼ã¨ããããåºæ¥ãã¨ããã¾ã§æ¸ãã¦ã¿ããã¨æãã¾ãâ¦
ç»åããç¢ç¤ã®é åãåãåºã
import cv2 import numpy as np # ç»åãèªã¿è¾¼ã¿ img = cv2.imread('sample.jpg') # ã°ã¬ã¼ã¹ã±ã¼ã« gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # ã¬ã¦ã¹ãã£ã«ã¿ smooth = cv2.GaussianBlur(gray,(11,11),0) # Canny Edge Detectionã§è¼ªéæ½åº edges = cv2.Canny(smooth, 100, 200) image, contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # é¢ç©ã大ããé ã«ã½ã¼ã contours.sort(key=cv2.contourArea, reverse=True) for cntr in contours: arclen = cv2.arcLength(cntr, True) approx = cv2.approxPolyDP(cntr, 0.01*arclen, True) # ç·è²ã®ç·ãå¼ã cv2.drawContours(img, [approx], -1, (0,255,0), 2) # 輪éæ½åºãã¦ï¼å ç»åã«éããçµæãåºå cv2.imwrite('edgeDetection.png', img) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = np.float32(gray) # Harris Corner Detectionã§ã³ã¼ãã¼ã®æ¤åº dst = cv2.cornerHarris(gray,5,3,0.04) # æ¤åºãããã³ã¼ãã¼ã«èµ¤è²ã§å°ãã¤ãã img[dst>0.03*dst.max()]=[0,0,255] # ã³ã¼ãã¼æ¤åºãããçµæãåºå cv2.imwrite('cornerDetection.png', img)
輪éæ½åºçµæ
ã³ã¼ãã¼æ¤åºçµæ
ããããç¢ç¤ã®åé
ãæ£ããæ¤åºãã¦ç»åãæãåºãããããã§ããï¼ã©ãããããâ¦ã¨ããç¶æ³ã§ãï¼
ç´ç·åºãã¦ãã®äº¤ç¹ãåãã¨ããããããããâ¦
ç»åãµã¤ãºã©ããªã£ã¦ãã ãï¼ï¼ã¨ãï¼ãã¤ãºé¤å»ã©ããªã£ã¦ãã ãï¼ï¼ã¨ãï¼ãã©ã¡ã¼ã¿ã©ããªã£ã¦ãã ãï¼ï¼ã¨ãï¼çµå±å¾ã®æ´å°ãã£ã¨ç¶ºéºã«ãããï¼ï¼ã¨ãããããªéãé£ãã§ãããã§æ¦ã æã ã¨ãã¦ãã®ã§ããï¼æ¸©ããç®ã§è¦ã¦ããã ããã¨å¹¸ãã§ãï¼
ãªãã³ã¸ç·¨æ¸ããããªâ¦
åèãªã³ã¯
python/OpenCVでレシートみたいな四角いものを見つけてトリミングする - BlankTar
OpenCV-Python Tutorials — OpenCV-Python Tutorials 1 documentation
ææ¥ã® CAMPHOR- Advent Calendar 2015 ã®è¨äºã¯ï¼@shotarokã®æ å½ã§ãï¼ã楽ãã¿ã«ï¼