今回入手してしまったのはPYNQ。Xilinx Zynq7020シリーズを搭載した評価ボードで、あらかじめ用意されたイメージをSDカードに書き込んであげればJupiterからWebブラウザ経由でもいくらか操作を試せるというお手軽さがウリ。

届いたPYNQのパッケージ
秋葉原の職場に送ってもらったので、受け取ったら早々と部品やでヒートシンクと熱伝導シーツを調達。
SDカードにイメージを焼いて起動したら、当然とはいえ、普通にヘッドレスなARM7 Linuxマシンとして起動してきた。OSはUbuntu 15。 OpenCVは 3.1 で、FFmpegサポートも入った状態でコンパイルされている。……これは色々と便利なのでは?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
General configuration for OpenCV 3.1.0 ===================================== | |
Version control: 3.1.0 | |
Platform: | |
Host: Linux 3.17.0-xilinx-dirty armv7l | |
CMake: 3.2.2 | |
CMake generator: Unix Makefiles | |
CMake build tool: /usr/bin/make | |
Configuration: RELEASE | |
C/C++: | |
Built as dynamic libs?: YES | |
C++ Compiler: /usr/bin/c++ (ver 5.2.1) | |
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG | |
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG | |
C Compiler: /usr/bin/cc | |
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG | |
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG | |
Linker flags (Release): | |
Linker flags (Debug): | |
Precompiled headers: YES | |
Extra dependencies: /usr/lib/arm-linux-gnueabihf/libjpeg.so /usr/lib/arm-linux-gnueabihf/libwebp.so /usr/lib/arm-linux-gnueabihf/libpng.so /usr/lib/arm-linux-gnueabihf/libz.so /usr/lib/arm-linux-gnueabihf/libtiff.so gthread-2.0 glib-2.0 v4l1 v4l2 avcodec-ffmpeg avformat-ffmpeg avutil-ffmpeg swscale-ffmpeg dl m pthread rt | |
3rdparty dependencies: libjasper IlmImf libprotobuf | |
OpenCV modules: | |
To be built: core flann imgproc ml photo reg surface_matching video dnn fuzzy imgcodecs shape videoio highgui objdetect plot superres ts xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo structured_light tracking videostab xfeatures2d ximgproc aruco optflow stitching python2 python3 | |
Disabled: world contrib_world | |
Disabled by dependency: - | |
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java viz cvv hdf matlab sfm | |
GUI: | |
QT: NO | |
GTK+: NO | |
GThread : YES (ver 2.46.2) | |
GtkGlExt: NO | |
OpenGL support: NO | |
VTK support: NO | |
Media I/O: | |
ZLib: /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.8) | |
JPEG: /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver ) | |
WEBP: /usr/lib/arm-linux-gnueabihf/libwebp.so (ver encoder: 0x0202) | |
PNG: /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.2.51) | |
TIFF: /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 - 4.0.3) | |
JPEG 2000: build (ver 1.900.1) | |
OpenEXR: build (ver 1.7.1) | |
GDAL: NO | |
Video I/O: | |
DC1394 1.x: NO | |
DC1394 2.x: NO | |
FFMPEG: YES | |
codec: YES (ver 56.41.100) | |
format: YES (ver 56.36.100) | |
util: YES (ver 54.27.100) | |
swscale: YES (ver 3.1.101) | |
resample: NO | |
gentoo-style: YES | |
GStreamer: NO | |
OpenNI: NO | |
OpenNI PrimeSensor Modules: NO | |
OpenNI2: NO | |
PvAPI: NO | |
GigEVisionSDK: NO | |
UniCap: NO | |
UniCap ucil: NO | |
V4L/V4L2: Using libv4l1 (ver 1.6.3) / libv4l2 (ver 1.6.3) | |
XIMEA: NO | |
Xine: NO | |
gPhoto2: NO | |
Parallel framework: pthreads | |
Other third-party libraries: | |
Use IPP: NO | |
Use VA: NO | |
Use Intel VA-API/OpenCL: NO | |
Use Eigen: NO | |
Use Cuda: NO | |
Use OpenCL: YES | |
Use custom HAL: NO | |
OpenCL: | |
Version: dynamic | |
Include path: /home/xpp/opencv/3rdparty/include/opencl/1.2 | |
Use AMDFFT: NO | |
Use AMDBLAS: NO | |
Python 2: | |
Interpreter: /usr/bin/python2.7 (ver 2.7.10) | |
Libraries: /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.10) | |
numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2) | |
packages path: lib/python2.7/dist-packages | |
Python 3: | |
Interpreter: /usr/bin/python3.4 (ver 3.4.3) | |
Libraries: /usr/lib/arm-linux-gnueabihf/libpython3.4m.so (ver 3.4.3+) | |
numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4) | |
packages path: lib/python3.4/dist-packages | |
Python (for build): /usr/bin/python2.7 | |
Java: | |
ant: NO | |
JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include | |
Java wrappers: NO | |
Java tests: NO | |
Matlab: Matlab not found or implicitly disabled | |
Documentation: | |
Doxygen: /usr/bin/doxygen (ver 1.8.9.1) | |
PlantUML: NO | |
Tests and samples: | |
Tests: YES | |
Performance tests: YES | |
C/C++ Examples: YES | |
Install path: /usr/local | |
cvconfig.h is in: /home/xpp/opencv/build | |
----------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd IkaLog/ | |
$ sudo pip3 install u-msgpack-python | |
[sudo] password for hasegaw: | |
The directory '/home/hasegaw/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. | |
The directory '/home/hasegaw/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. | |
Collecting u-msgpack-python | |
Downloading u_msgpack_python-2.2-py2.py3-none-any.whl | |
Installing collected packages: u-msgpack-python | |
Successfully installed u-msgpack-python-2.2 | |
$ python3 IkaLog.py -f ikalog_sample.mp4 | |
IkaLog Primary CLI Language: en_US.UTF-8 (set LANG to override) | |
IkaLog Game Language: ja (set IKALOG_LANG to override) | |
<ikalog.utils.icon_recoginizer.weapon.WeaponRecoginizer object at 0x30b7ce50>: KNN Trained (8599 samples) | |
<ikalog.utils.icon_recoginizer.gearpower.GearPowerRecoginizer object at 0x30b7ce70>: KNN Trained (2410 samples) | |
<ikalog.inputs.filters.warp_model.WarpFilterModel object at 0x3025bab0>: Loaded model data | |
/home/hasegaw/IkaLog/data/webcam_calibration.ja.model (3010 keypoints) | |
<ikalog.outputs.websocket_server.WebSocketServer object at 0x30bd08b0> | |
<ikalog.scenes.misc.amarec_16x10.Amarec16x10Warning object at 0x2c15c8f0>: switching to state _state_tracking | |
<ikalog.scenes.misc.amarec_16x10.Amarec16x10Warning object at 0x2c15c8f0>: switching to state _state_default | |
<ikalog.scenes.game.start.GameStart object at 0x3025b930>: switching to state _state_tracking | |
<ikalog.scenes.game.inklings_tracker.InklingsTracker object at 0x30257c30>: switching to state _state_default | |
Game Start. Stage: Arowana Mall, Mode: Rainmaker | |
<ikalog.scenes.game.start.GameStart object at 0x3025b930>: switching to state _state_default | |
(snip) |

ただしPYNQのbase.bitではDDCの応答内容に問題があるのかWiiUからビデオ信号が出てこない。このためHDMIマトリックススイッチやスイッチャーなどの機械を挟んでいる。また、720pだと色々安定していないような感じ……。過去に試していたとき、ZYBOではDigilentのdvi2rgbのEDIDを書き換えたらWiiUの信号を直接、安定して食えるようになったので、そのときの成果を持ってくれば解決するだろう。だいたい解決策は見えているので後回し。ちなみに以前ZYBOで実験していたときの写真がこちら。
自作HDMI-RGB回路でWiiU画面うつるようになった。 pic.twitter.com/kMH2UQH0NL— もつなべおじさん (@hasegaw) 2015年12月5日
Jupter で操作した内容を IkaLog の映像インプットとして使えるようクラスを追加して、とりあえずだけども対応完了。
https://github.com/hasegaw/IkaLog/commit/5b6b9ce55e1ae32e57c2dd6f05ae20aa00c9b3fd
HDMIのキャプチャは実現できたが、PYNQにはHDMI Outputもあるので、こちらにパススルーすると、PYNQがIkaLogマシン+ビデオキャプチャ+HDMIスプリッタを兼ねるという、いままでIkaLogを利用するにあたって必要となる3つのアイテムをワンボードで実現できることになる。
Pynqのドキュメンテーションを読んでいると、じつは上記の設定でHDMIパススルーも実現できていることがわかった。上記の設定を行うとOut側がIn側のバッファからデータを受け取るようなかたちでパススルーしてくれる(プロセッサは通していないと思う……フレームバッファは通しているかも?)
というわけで、数時間でできちゃったIkaLog+PYNQ(キャプチャ機能+映像のみスプリッタ機能)。
Pynqで動くIkaLog、Project Inqと命名。Pynqの利用用途として思いついてはいたけども、思った以上に簡単に実装できてしまった。ここまでの成果については下記 WIki ページを見ていただければ再現できるはず。PSoCが可能にした、10Wで動作する #IkaLog Hardware(ARMアーキテクチャ、HDMIキャプチャ/スプリッタ内蔵)の Proof of Concept です。ご確認ください。リアルタイムで解析したデータはこちら https://t.co/2zbp1yl5bk pic.twitter.com/osoKH4S0W8— もつなべおじさん (@hasegaw) 2016年10月15日
https://github.com/hasegaw/IkaLog/wiki/en_Installation_Pynq
これをしばらく動かしてみるといくつか課題が見えてくる。
一つ目の課題は、HDMI Outputから出力された映像がたまに縦にずれたりする。たぶんHDMI映像の伝送が、ARMのDDR3メモリに置かれたフレームバッファを介していて、IkaLogが走っているとメモリ帯域やバス幅が足りなくなるんじゃないかと疑っている。
二つ目の課題は、HDMIのスプリッタ機能といっても HDMI 信号を音無しの DVI 信号としてピクセル情報に落とし、それを DVI 信号として HDMI ポートから出しているだけなので、音が消えてしまう。もちろんレイテンシの問題もあるし、キャプチャ機能はそのまま使うとしても、 HDMI Input から入ってきた信号をできるだけ忠実に HDMI Output に出力するよう変更したい。
Xilinx FPGAなのでHDMIのシリアル信号をISERDESE2で受けて、出力するときはOSERDESE2で送信している(はず)。これらを直結すればナノ秒レベルのディレイでシリアル信号をそのまま伝達できるだろうけど、ビデオキャプチャ機能も必要なので、dvi2rgb IPと共存することは考えないといけない。
とりあえずPYNQについてきたbase.bitは忘れて、dvi2rgb -> rgb2dvi でパススルーするデザインを作ってみた。

WiiU の信号が直接映らないのは相変わらずだけども、画像がたまに縦に1ドット間延びするような現象は解決した。ARMプロセッサ側のDDR3メモリを介さずに、受け取った信号をそのまま送出しているからだろう。
でも、やはり音のデータは消えてしまっている。
手元に高速ビデオ・インターフェース HDMI&DisplayPortのすべて という書籍があった。
これを読み返してみると、オーディオ信号はVSYNC直後のブランク期間などに入っているとのこと。ここが現状どうなっているかを調べると、色々解決しそう。 dvi2rgb がブランク期間中の信号を捨ててしまっているのではないかという想像だ。もし信号が捨てられていない事が分かればラッキーで、今度は送出側 rgb2dvi が信号を捨てていると考えればよさそう。
Integrated Logic Analyzer を追加して信号を眺めてみる。


案の定 dvi2rgb がブランク期間中の信号をゼロでマスクしているようだ。この 000000 になっているところに、本当はオーディオ信号も乗っているはず。ここにあるはずの信号も含めて rgb2dvi の OSERDESE2 に流し込んであげれば、きっとオーディオ含めてスプリッタとして動作してくれるだろう。
とりあえずの調査はここまで。
0 件のコメント:
コメントを投稿