【目次】
手順の要点: Python 3.6, TensorFlow 1.15 を使用
ソフトウエア等の利用条件等は,利用者で確認すること.
【サイト内の関連ページ】:
謝辞:ソフトウエアの作者に感謝します
TensorFlow 1.15 を使う.
「Visual Studio Community 2019 vesion 16.2, マイクロソフト C++ ビルドツールのインストール(Windows 上)」で説明している.
すでに TensorFlow 2 を使っている,あるいは使う予定ということがありえる. 単純には,TensorFlow 2 と TensorFlow 1.15 を共存させて Python で使うということはできないが, 少しの手間で,共存できるようになる. そこで,TensorFlow 2 とTensorFlow 1.15 の共存を前提として, TensorFlow 1.15 のインストールを行う.
【Python 開発環境のインストール】
Python を使うときは,Python開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter など)の利用も便利である
Windows, Ubuntu での Python 開発環境,Python コンソール(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, spyder)のインストール: 別ページで,インストール手順を説明している.
Windows でのPython3.6,TensorFlow 1.15 のインストール:別ページで説明している.
すでにPython 3.9 あるいは Python 3.8 をインストールしている,あるいは,インストール予定という場合を想定し, あとのトラブルが起きにくい,そして,簡単に運用できるように 「Python 3.6 をインストールし,その上に,TensorFlow 1.15.5 をインストールする」という手順を案内している.
Ubuntu でのPython,TensorFlow 1.15 のインストール:別ページで案内している.
Ubuntu のシステム Python に影響を与えないように,隔離された Python 3.6 仮想環境の新規作成し,その上にTensorFlow 1.15.5 をインストールするという手順(venv を使用)(Ubuntu 上)を案内している.
Git の URL: https://git-scm.com/
sudo apt -y update sudo apt -y install git
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
mkdir c:\pytools cd c:\pytools rmdir /s /q deepgaze
cd c:\pytools git clone https://github.com/mpatacchiola/deepgaze cd deepgaze python setup.py build python setup.py install
エラーメッセージが出ていないこと.
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
ここで使用する mp4 形式ビデオファイル: sample1.mp4
ファイルのコピー
cd c:\pytools cd deepgaze\examples\ex_cnn_head_pose_estimation_images copy ex_cnn_head_pose_estimation_images.py a.py
notepad a.py
v = cv2.VideoCapture("c:/image/sample1.mp4")
while(v.isOpened()):
r, img = v.read()
if ( r == False ):
break
img = cv2.resize(img, (480, 480))
roll = my_head_pose_estimator.return_roll(img) # Evaluate the roll angle using a CNN
pitch = my_head_pose_estimator.return_pitch(img) # Evaluate the pitch angle using a CNN
yaw = my_head_pose_estimator.return_yaw(img) # Evaluate the yaw angle using a CNN
print("roll %s, pitch %s, yaw %s" % ( str(roll[0,0,0]), str(pitch[0,0,0]), str(yaw[0,0,0]) ) )
cv2.imshow("", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
v.release()
cv2.destroyAllWindows()
編集したら,ファイルを「上書き保存」する
py -3.6 a.py
v = cv2.VideoCapture(0)
v = cv2.VideoCapture(0)
while(v.isOpened()):
r, img = v.read()
if ( r == False ):
break
img = cv2.resize(img, (480, 480))
roll = my_head_pose_estimator.return_roll(img) # Evaluate the roll angle using a CNN
pitch = my_head_pose_estimator.return_pitch(img) # Evaluate the pitch angle using a CNN
yaw = my_head_pose_estimator.return_yaw(img) # Evaluate the yaw angle using a CNN
print("roll %s, pitch %s, yaw %s" % ( str(roll[0,0,0]), str(pitch[0,0,0]), str(yaw[0,0,0]) ) )
cv2.imshow("", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
v.release()
cv2.destroyAllWindows()
Python プログラムを動かす.
python a.py