普通に表示すると、ウインドウに枠がつく. 枠を表示したくないときは、このページのプログラムを使用する.
システム Python を使うことができる(その場合,Python のインストールは行わない)
システム Python を用いるときは,pip, setuptools の更新は次のコマンドで行う.
sudo apt -y update sudo apt -y install python3-pip python3-setuptools
Ubuntu で,システム Python 以外の Python をインストールしたい場合は pyenv が便利である: 別ページで説明している.
Python の URL: http://www.python.org/
【Python, pip の使い方】
Python, pip は,次のコマンドで起動できる.
【Python 開発環境のインストール】
JupyterLab, spyder, nteract (Python 開発環境) のインストールは, Windows でコマンドプロンプトを管理者として実行し, 次のコマンドを実行.
python -m pip install -U pip setuptools jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder
詳しくは,: 別ページで説明している.
JupyterLab, spyder, nteract (Python 開発環境) のインストール: : 別ページで説明している.
コマンドプロンプトで次のコマンドを実行
python -m pip install -U opencv-python
端末で次のコマンドを実行
sudo apt -y update sudo apt -y install libopencv-dev python3-opencv
端末で次のコマンドを実行
sudo apt -y update sudo apt -y install libopencv-dev python3-opencv python3-opencv-apps
USB接続できるビデオカメラを準備し,パソコンに接続しておく.
import cv2
import numpy as np
import win32gui
import win32con
x = 0
y = 0
width = 640
height = 480
cv2.namedWindow("camera")
v = cv2.VideoCapture(0)
a = win32gui.FindWindow(None,"camera")
win32gui.SetWindowLong(a, win32con.GWL_STYLE, win32con.WS_POPUP)
print(a)
while(v.isOpened()):
r, f = v.read()
if ( r == False ):
break
cv2.imshow("camera", f)
win32gui.SetWindowPos(a, win32con.HWND_TOPMOST, x, y, width, height, win32con.SWP_SHOWWINDOW)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
v.release()
cv2.destroyAllWindows()
※ 止めたいとき,右上の「x」をクリックしない.画面の中をクリックしてから,「q」のキーを押して閉じる
import cv2
import numpy as np
import win32gui
import win32con
x = 0
y = 0
scale = 0.5
cv2.namedWindow("camera")
v = cv2.VideoCapture(0)
a = win32gui.FindWindow(None,"camera")
win32gui.SetWindowLong(a, win32con.GWL_STYLE, win32con.WS_POPUP)
print(a)
while(v.isOpened()):
r, f = v.read()
if ( r == False ):
break
f = cv2.rotate(f, cv2.ROTATE_90_COUNTERCLOCKWISE)
height = f.shape[0]
width = f.shape[1]
f = cv2.resize(f , (int(width*scale), int(height*scale)))
cv2.imshow("camera", f)
win32gui.SetWindowPos(a, win32con.HWND_TOPMOST, x, y, width, height, win32con.SWP_SHOWWINDOW)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
v.release()
cv2.destroyAllWindows()
※ 止めたいとき,右上の「x」をクリックしない.画面の中をクリックしてから,「q」のキーを押して閉じる