歪みなしカメラ画像の座標変換

OpenCV: Camera Calibration and 3D Reconstruction カメラ行列(内部パラメータ / intrinsic parameters) $$ A = \left( \begin{array}{ccc} f_x & 0 & c_x \ 0 & f_y & c_y \ 0 & 0 & 1 \end{array} \right) $$ 焦点距離 ( f_x, f_y ) 単位は画素(pixels) 2つの役割をもつ ピンホールカメラモデルにおける焦点距離(tex: f )(参考:ピンホールカメラモデル) 任意の単位で表される変換前の座標からコンピュータ上の画素の単位であるピクセル単位に変換する ピンホールカメラモデルでは1つの焦点距離(tex: f )しかなかったのに、なぜ(tex: f_x, f_y )と2つ含まれているのか 2つ目の役割(撮像素子の位置=実世界の距離からピクセル単位に変換)のため、撮像素子の特性(px/mm)がx、y方向で異なる場合を想定している(( f_x, f_y )はレンズの物理的な焦点距離 ( tex: f )(mm)と撮像素子の特性( c_x, c_y)の積。また、カメラ画像からそれぞれを独立に求めることはできない) 参考:computer vision - Why does the focal length in the camera intrinsics matrix have two dimensions? - Stack Overflow, Learning OpenCV 画像の中心 (c_x, c_y) 単位は画素(pixels) 射影変換行列(Perspective transform matrix, 外部パラメータ/ extrinsic parameters) 参考:2次元の射影変換行列 $$ [R|t] = \left( \begin{array}{cccc} r_{11} & r_{12} & r_{13} & t_x \ r_{21} & r_{22} & r_{23} & t_y \ \end{array} \right) $$ ...

2020年3月21日 · aoirint

ピンホールカメラモデル

Pinhole camera model - Wikipedia OpenCV: Camera Calibration and 3D Reconstruction 3次元空間をカメラで撮影したときの、「3次元空間(実世界)上の点の座標\((x, y, z)\)」と「2次元写真平面上の点の座標\((u, v)\)」の変換\((u, v) = T(x, y, z)\)を考える。 カメラの位置を3次元空間における原点\(O\)とする。 ここでカメラに固有なパラメータとして、焦点距離\(f (> 0)\)を導入する。焦点距離は、カメラ(原点\(O\))に入射した光が写真として実像を結ぶスクリーン(写真平面)までの距離である。この設定から、3次元空間上で写真平面(スクリーン)は\(z = -f\)にあるとわかる(写真平面をx-y平面と並行とし、z軸を3次元空間上の奥行きとする)。なお、\(f\)がより大きいカメラで撮影したとき、同じ距離にある被写体はより大きく写る(凸レンズ)。 (図はPinhole camera model - Wikipediaから引用。軸X1, X2, X3はx, y, zに、Y1, Y2はu, vに対応) 点P\((x, y, z)\)から原点Oを通過し、スクリーン上の点Q\((-u, -v, -f)\)に入射する光を考える。なお、実像は光軸を中心に上下左右に反転するため、このとき点Qは写真において座標\((u, v)\)にある。 点Pからxz平面上に落とした点P’\((x, 0, z)\)、点Qからxz平面上に落とした点Q’\((-u, 0, -f)\)を導入する。ここで、三角形POP’と三角形QOQ’は共通の角度を持つ相似な三角形である。この性質から、辺POと辺P’Oの長さの比\(x / z\)、辺QOと辺Q’Oの長さの比\((-u) / (-f)\)は等しい。すなわち、\(\frac{x}{z} = \frac{u}{f}\)。\(u\)について整理すると、\(u = f \frac{x}{z}\)。 (図はPinhole camera model - Wikipediaから引用。青線がスクリーン上の実像、赤線が実体。計算では図中の\(f\)を\(-f\)としている) ...

2020年3月21日 · aoirint

OpenCV FullScreen Window

Python - PythonのOpenCVでフルスクリーン表示|teratail import cv2 cv2.namedWindow('screen', cv2.WINDOW_NORMAL) cv2.setProperty('screen', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. python-opencvでQt plugin “cocoa"が見つからないというエラー - Qiita 黒画面 import cv2 import numpy as np # Change here WIDTH = 1920 HEIGHT = 1080 # For secondary monitor, LEFT = 0 TOP = 0 screen = np.zeros((HEIGHT, WIDTH), dtype=np.uint8) cv2.namedWindow('screen', cv2.WINDOW_NORMAL) cv2.moveWindow('screen', LEFT, TOP) cv2.setWindowProperty('screen', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.imshow('screen', screen) cv2.waitKey(0) For dynamic image size, ...

2020年3月20日 · aoirint

Remote editing with Atom (rmate, sshfs)

rmate AtomでSSH越しのファイルを編集する - Qiita Install rmate in remote. Install remote-atom as Atom package in local. Configure “remote forwarding” of rmate port in local (local:port -> remote:port). Open Atom in local. Execute rmate file.txt in remote (ssh). Atom in local will show the file, and you can edit it. rmate cannot be used for Atom Tree View (Project View). But tree command in ssh is useful for viewing project file entries. ...

2020年3月19日 · aoirint

PortAudio, pyaudio

PortAudio: PortAudio API Overview Host API ALSA (Ubuntu) Core Audio (Mac) Device Speaker Mic Stream sample rate (num of samples per second) sample format (num of bytes of a sample, integer or float) PyAudio Documentation — PyAudio 0.2.11 documentation Audio device detection w/ pyaudio brew install portaudio pip3 install pyaudio macOSにpyaudioをインストールする - Qiita Check Host APIs import pyaudio pa = pyaudio.PyAudio() api_count = pa.get_host_api_count() print('Host API:', api_count) for i in range(api_count): api_info = pa.get_host_api_info_by_index(i) print(api_info) device_count = api_info['deviceCount'] for j in range(device_count): device_info = pa.get_device_info_by_host_api_device_index(i, j) print(device_info) pa.terminate() Host API: 1 {'index': 0, 'structVersion': 1, 'type': 5, 'name': 'Core Audio', 'deviceCount': 2, 'defaultInputDevice': 0, 'defaultOutputDevice': 1} {'index': 0, 'structVersion': 2, 'name': 'Built-in Microphone', 'hostApi': 0, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.0029478458049886623, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.01310657596371882, 'defaultHighOutputLatency': 0.1, 'defaultSampleRate': 44100.0} {'index': 1, 'structVersion': 2, 'name': 'Built-in Output', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.007800453514739229, 'defaultHighInputLatency': 0.1, 'defaultHighOutputLatency': 0.017959183673469388, 'defaultSampleRate': 44100.0} Check Devices import pyaudio pa = pyaudio.PyAudio() device_count = pa.get_device_count() print('Device:', device_count) for i in range(device_count): device_info = pa.get_device_info_by_index(i) print(device_info) pa.terminate() Device: 2 {'index': 0, 'structVersion': 2, 'name': 'Built-in Microphone', 'hostApi': 0, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.0029478458049886623, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.01310657596371882, 'defaultHighOutputLatency': 0.1, 'defaultSampleRate': 44100.0} {'index': 1, 'structVersion': 2, 'name': 'Built-in Output', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.007800453514739229, 'defaultHighInputLatency': 0.1, 'defaultHighOutputLatency': 0.017959183673469388, 'defaultSampleRate': 44100.0} Stream ※ waveだけ鳴らせればいい場合はwaveモジュールを使ってください(参照) ...

2020年3月19日 · aoirint

systemd service

テンプレート(一般ユーザ権限、bashrc使用) [Unit] Description=My Service [Service] Type=simple User=user Group=user Restart=always WorkingDirectory=WORKING_DIR ExecStart=/bin/bash -c "COMMAND" [Install] WantedBy=multi-user.target sudo ln -s my_service.service /etc/systemd/system/ sudo systemctl enable my_service sudo systemctl restart my_service # After you edit service file sudo systemctl daemon-reload # Check log sudo systemctl status my_service If you are using python, maybe you need to set environment PYTHONUNBUFFERED=1 to see log. # In [Service] Section Environment="PYTHONUNBUFFERED=1" Environment="KEY=VALUE" Systemdを使ってさくっと自作コマンドをサービス化してみる - Qiita systemd サービスユニット覚書 - Qiita Systemd メモ書き - Qiita Systemd Unit File チートシート - Qiita

2020年3月19日 · aoirint

Ubuntu, TigerVNC

Setup VNC via ssh on Ubuntu Desktop. Install TigerVNC. # Ubuntu 18.04 sudo apt install tigervnc-scraping-server # Ubuntu 16.04 sudo apt install tigervncserver Set password. vncpasswd startVNC.sh #!/bin/bash x0tigervncserver PasswordFile=~/.vnc/passwd Display=:0 configure LocalForward LOCALPORT localhost:5900 in ~/.ssh/config. TigerVNCのクライアントはあんまり機能が多くない RealVNC社のクライアントはWindows, Linux, Mac, Mobileにリリースされてて便利 https://www.realvnc.com/en/connect/download/viewer/ つまずかない!?TigerVNCでリモートデスクトップ - Qiita

2020年3月18日 · aoirint

tar 圧縮

解凍tar -xfはよく使うので覚えるけど、圧縮のほうが覚えられん.. [Linux]ファイルの圧縮、解凍方法 - Qiita tar.gz tar -zcf compressed.tar.gz FILES extractとcompressかな おまけ zip zip -r compressed.zip DIR unzip compressed.zip

2020年3月17日 · aoirint

Flask, sqlalchemy

Flask ウェブアプリケーションフレームワーク Flask を使ってみる - Qiita Flaskで任意のデータを引数として受け取る方法 - Qiita python - redirect while passing arguments - Stack Overflow #url_for API — Flask 0.10.1 documentation python - How to serve static files in Flask - Stack Overflow python - Unable to retrieve files from send_from_directory() in flask - Stack Overflow python - Flaskで変数を文字列ではなくHTMLのタグとして読み込ませたい - スタック・オーバーフロー sqlalchemy 【PythonのORM】SQLAlchemyで基本的なSQLクエリまとめ - Qiita Object Relational Tutorial — SQLAlchemy 1.3 Documentation Python: SQLAlchemy + mysqlclient (MySQLdb) でマルチバイト文字を扱う - CUBE SUGAR CONTAINER Transactions and Connection Management — SQLAlchemy 1.3 Documentation Object Relational Tutorial — SQLAlchemy 1.3 Documentation SQLAlchemy で Delete するには? - Qiita Basic Relationship Patterns — SQLAlchemy 1.3 Documentation python - How to remove all items from many-to-many collection in SqlAlchemy? - Stack Overflow python - Flask-SQLAlchemy - model has no attribute ‘foreign_keys’ - Stack Overflow python - sqlalchemy dynamic filtering - Stack Overflow tagify Tagify - demo python-markdown Library Reference — Python-Markdown 3.2.1 documentation Extensions — Python-Markdown 3.2.1 documentation MathJax Getting Started — MathJax 2.7 documentation Combined Configurations — MathJax 2.7 documentation highlight.js How to use highlight.js highlight.js demo highlight.js/src/styles at master · highlightjs/highlight.js highlightjs-line-numbers.js - cdnjs.com - The best FOSS CDN for web related libraries to speed up your websites! wcoder/highlightjs-line-numbers.js: Line numbering plugin for Highlight.js Ace Editor Ace - The High Performance Code Editor for the Web ace/lib/ace/theme at master · ajaxorg/ace javascript - How do I get value from ACE editor? - Stack Overflow Unique/Random ID [Python] UUIDを生成するuuid.uuid4()はどうやってUUIDを生成しているのか? | Developers.IO #os.urandom os — 雑多なオペレーティングシステムインタフェース — Python 3.8.2 ドキュメント os.urandom(NUM_BYTES).hex()

2020年3月16日 · aoirint

Python Dockerfile

FROM python:3 RUN mkdir /code WORKDIR /code COPY requirements.txt /code/ RUN pip install -r requirements.txt

2020年3月16日 · aoirint