【目次】
手順の要点: 前準備として,NVIDIA CUDA 10.0, NVIDIA cuDNN 7.6.5, Python 3.7, TensorFlow 1.15.5 等をインストール.
ソフトウェア等の利用条件等は,利用者で確認すること.
謝辞:ソフトウェアの作者に感謝します
NVIDIA CUDA 10.0 は Visual Studio Commnity 2017, 2015, 2013, 2012 と連携して動く機能がある.
NVIDIA CUDA 10.0 のインストールの前に, Visual Studio Commnity 2017 のインストールを行う.
Visual Studio Commnity 2017 のインストールは, https://visualstudio.microsoft.com/ja/vs/older-downloads/ で「2017」を選び,「ダウンロード」をクリック. その後表示されるダウンロードの画面で, 「Visual Studio Commnity 2017」を選ぶ. インストール時には「C++ によるデスクトップ開発」をチェックしてインストールする.
Git のページ https://git-scm.com/ からダウンロードしてインストール:
sudo apt -y update sudo apt -y install git
cmake のダウンロードページ: https://cmake.org/download/
【Python のインストールでの注意点】
Windows で,ユーザ名が日本語のとき,あとでトラブルが発生するかもしれない. トラブルの回避のため, Python をシステム管理者の領域にインストール(パソコンの全ユーザの共有領域)する.
【Python 3.7 のインストール手順の詳細(別ページ) 】
Windows での Python 3.7 のインストール: 別ページ »で説明
【Python の公式ページ】
【インストール手順の概要】
ページの上の方にある「Downloads」をクリック,「Downloads」の下にメニューが出るので,その中の「Windows」をクリック.
そして,Python 3.7.x (x は数字)を探す.
そして,Windows の 64ビット版のインストーラをダウンロードしたいので,「Windows x86-64 executable installer」を選ぶ
※ すでに Python ランチャーをインストール済みのときは, 「Install launcher for all users (recommended)」がチェックできないようになっている場合がある.そのときは,チェックせずに進む.
Python のインストールディレクトリは,「C:\Program Files\Python37」のように自動設定されることを確認.
「Install」をクリック
py とpip にパスが通っていることの確認である.
where py where pip
where py では「C:\Windows\py.exe」 が表示され, where pip では「C:\Program Files\Python37\Scripts\pip.exe」 が表示されることを確認.
Python の使用は「py -3.7」で行う.
py -3.7 -m pip install -U pip setuptools
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行する
次のコマンドを実行する
Python の使用は「C:\venv\py37\Scripts\activate.bat」の後,「python」で行う.
C:\venv\py37\Scripts\activate.bat python -m pip install -U pip setuptools jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter
Windows での Visual Studio Community 2017,NVIDIA ドライバ,NVIDIA CUDA ツールキット 10.0,NVIDIA cuDNN 7.6.5 のインストール: 別ページ »で説明
C:\venv\py37\Scripts\activate.bat python -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow-intel tensorflow-text tensorflow-estimator tf-models-official tf_slim tensorflow_datasets tensorflow-hub keras keras-tuner keras-visualizer scipy pandas matplotlib # TensorFlow 1.15.5 のため numpy, protobuf の古いバージョンを使用.エラーが出にくいと考えられる numpy 1.16.2, protobuf 3.19.4 を使用 python -m pip install -U numpy==1.16.2 protobuf==3.19.4 tensorflow-gpu==1.15.5 keras==2.3.1 scipy==1.5.4
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
cd %HOMEPATH% rmdir /s /q deepgaze
git clone https://github.com/mpatacchiola/deepgaze cd deepgaze py -3.7 setup.py build py -3.7 setup.py install
エラーメッセージが出ていないこと.
必要であればダウンロードして使ってください.
mkdir c:\image cd c:\image curl -O https://www.kkaneko.jp/sample/face/sample1.mp4
Windows でのプログラムを下に示す.Ubuntu でも同様のプログラムになる.
OpenCV による動画表示を行う.
「FACEIMAGEROOT + "sample1.mp4"」のところは、実際のファイル名に置き換えること
import cv2 import numpy as np from deepgaze.color_detection import RangeColorDetector #Firs image boundaries min_range = np.array([0, 48, 70], dtype = "uint8") #lower HSV boundary of skin color max_range = np.array([20, 150, 255], dtype = "uint8") #upper HSV boundary of skin color my_skin_detector = RangeColorDetector(min_range, max_range) #Define the detector object FACEIMAGEROOT="c:/image/" v = cv2.VideoCapture(FACEIMAGEROOT + "sample1.mp4") while(v.isOpened()): r, f = v.read() if ( r == False ): break f = f[0:885, 0:773, 0:3] image_filtered = my_skin_detector.returnFiltered(f, morph_opening=False, blur=False, kernel_size=3, iterations=1) cv2.imshow("", image_filtered) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
Python プログラムを実行する
「v = cv2.VideoCapture(0) 」は、USB カメラを使うためのもの。他の部分は、上のプログラムと同じ。
import cv2 import numpy as np from deepgaze.color_detection import RangeColorDetector #Firs image boundaries min_range = np.array([0, 48, 70], dtype = "uint8") #lower HSV boundary of skin color max_range = np.array([20, 150, 255], dtype = "uint8") #upper HSV boundary of skin color my_skin_detector = RangeColorDetector(min_range, max_range) #Define the detector object v = cv2.VideoCapture(0) while(v.isOpened()): r, f = v.read() if ( r == False ): break f = f[0:885, 0:773, 0:3] image_filtered = my_skin_detector.returnFiltered(f, morph_opening=False, blur=False, kernel_size=3, iterations=1) cv2.imshow("", image_filtered) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
Python プログラムを実行する
Windows でのプログラムを下に示す.Ubuntu でも同様のプログラムになる.
「out = cv2.VideoWriter('C:/image/output.avi', fourcc, 20.0, (640, 480), True) 」の「True」は、カラーという意味
import cv2 import numpy as np from deepgaze.color_detection import RangeColorDetector #Firs image boundaries min_range = np.array([0, 48, 70], dtype = "uint8") #lower HSV boundary of skin color max_range = np.array([20, 150, 255], dtype = "uint8") #upper HSV boundary of skin color my_skin_detector = RangeColorDetector(min_range, max_range) #Define the detector object v = cv2.VideoCapture(0) fourcc = cv2.VideoWriter_fourcc(*'XVID') FACEIMAGEROOT="c:/image/" out = cv2.VideoWriter(FACEIMAGEROOT + 'output.avi', fourcc, 20.0, (640, 480), True) while(v.isOpened()): r, f = v.read() if ( r == False ): break f = f[0:885, 0:773, 0:3] image_filtered = my_skin_detector.returnFiltered(f, morph_opening=False, blur=False, kernel_size=3, iterations=1) cv2.imshow("", image_filtered) out.write(image_filtered) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() out.release() cv2.destroyAllWindows()
Webブラウザを使い、次の画像を「名前を付けて画像を保存」。 ファイル名は「126.png」とする。 「作業用のディレクトリ(フォルダ)」に保存する
次の画像も、「名前を付けて画像を保存」。 ファイル名は「127.png」とする。 「作業用のディレクトリ(フォルダ)」に保存する
次のようになる
Web ブラウザで、 https://github.com/mpatacchiola/deepgaze/blob/master/examples/ex_skin_detection_images/ex_skin_detection_images.py を開く
c:/image/126.png, c:/image/126-filtered.png,
このとき、ファイル名は、skin.py のようなファイル名で保存(拡張子は「.py」)
「作業用のディレクトリ(フォルダ)」である C:\face-image に保存する
先ほど名前を付けて保存したときのファイル名を使う
cd C:\face-image python skin.py
skin.py の中の画像ファイル名を 126 から 127 に書き換えて、python skin.py をもう一度実行。次のような結果になる
mkdir c:\image cd c:\image curl -O https://www.kkaneko.jp/sample/face/sample1.mp4
Windows でのプログラムを下に示す.Ubuntu でも同様のプログラムになる.
OpenCV による動画表示を行う.
「FACEIMAGEROOT + "sample1.mp4"」のところは、実際のファイル名に置き換えること
import numpy as np import cv2 from deepgaze.saliency_map import FasaSaliencyMapping # Using OpenCV the resolution of the webcam is set to these values. # You must check which resolution your webcam support and adjust the values in accordance. RESOLUTION_WIDTH = 320 RESOLUTION_HEIGHT = 180 FACEIMAGEROOT="c:/image/" v = cv2.VideoCapture(FACEIMAGEROOT + "sample1.mp4") # Create the main window and move it cv2.namedWindow('Video') # Obtaining the CAM dimension w = int(v.get(3)) h = int(v.get(4)) # Defining the FASA object using the camera resolution my_map = FasaSaliencyMapping(h, w) while True: # Capture frame-by-frame r, f = v.read() if ( r == False ): break image_salient = my_map.returnMask(f, tot_bins=8, format='BGR2LAB') cv2.imshow("", image_salient) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
OpenCV による動画表示を行う.
import numpy as np import cv2 from deepgaze.saliency_map import FasaSaliencyMapping # Using OpenCV the resolution of the webcam is set to these values. # You must check which resolution your webcam support and adjust the values in accordance. RESOLUTION_WIDTH = 320 RESOLUTION_HEIGHT = 180 # Open the video stream and set the webcam resolution. # It may give problem if your webcam does not support the particular resolution used. video_capture = cv2.VideoCapture(0) # Create the main window and move it cv2.namedWindow('Video') # Obtaining the CAM dimension cam_w = int(video_capture.get(3)) cam_h = int(video_capture.get(4)) # Defining the FASA object using the camera resolution my_map = FasaSaliencyMapping(cam_h, cam_w) while True: # Capture frame-by-frame r, f = video_capture.read() image_salient = my_map.returnMask(f, tot_bins=8, format='BGR2LAB') cv2.imshow("", image_salient) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()