#topicpath

** Python+OpenCV [#e002765c]
*** OpenCVとは [#ob03bb3e]
- CV は Computer Vision の略である。計算機に接続されたカメラを通じて得られる画像を処理するためのライブラリのこと。~
Intel が開発して、その後、Open になった。~
デジカメなどで顔と認識された部分に枠を表示したりするのは、OpenCV の初期の応用例としてよく知られている。~
~
- [[導入についての情報>http://robo.mydns.jp/Lecture/index.php?%B8%A6%B5%E6%A4%CE%A5%DA%A1%BC%A5%B8%2FPython#h64eeefa]]は、[[研究のページ/Python>研究のページ/Python]]内の [[WinPython>http://robo.mydns.jp/Lecture/index.php?%B8%A6%B5%E6%A4%CE%A5%DA%A1%BC%A5%B8%2FPython#e34ee010]]、[[Anaconda>http://robo.mydns.jp/Lecture/index.php?%B8%A6%B5%E6%A4%CE%A5%DA%A1%BC%A5%B8%2FPython#tb4e9041]]それぞれの項目を参照のこと。~
~
*** サンプルプログラム [#x71a8d4f]
- 導入チェック用サンプルプログラム~
-- サンプルプログラム1 ([[OpenCV Getting Started>http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html#read-an-image]]から)~
~
 import numpy as np
 import cv2
 
 # Load an color image in grayscale
 img = cv2.imread('sample.png',0)
 cv2.imshow('image',img)
 cv2.waitKey(0)
 cv2.destroyAllWindows()
~
これを実行する際に working directory を指定できるので、これを適当な場所に指定し、その中に、sample.png という画像ファイルを置いておく。~
※ 画像ファイル(sample.png)の置き場:~
--- 実行する際に working directory を指定できる画面が現れることがある。これを適当な場所に指定し、その中に画像ファイルを置いておく。~
--- 現れない場合には、メニューを Run > Configure とたどり、Working dir の欄で適当な場所を指定し、その中に画像ファイルを置いておく。~
~
-- サンプルプログラム2 (OpenCV のチュートリアルページの一つ([[Getting Started with Videos>http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html]])から)~
~
 import numpy as np
 import cv2
 
 cap = cv2.VideoCapture(0)
 
 while(True):
     # Capture frame-by-frame
     ret, frame = cap.read() 
 
     # Our operations on the frame come here
     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
 
     # Display the resulting frame
     cv2.imshow('frame',gray)
     if cv2.waitKey(1) & 0xFF == ord('q'):
         break
 
 # When everything done, release the capture
 cap.release()
 cv2.destroyAllWindows()
~
カメラでとらえた映像が表示される。~
※ このプログラムでは、numpy は必要でない。その旨、エディターに表示されることにも注意する。~
~

トップ   編集 差分 添付 複製 名前変更 リロード   新規 検索 最終更新   ヘルプ   最終更新のRSS