普通に表示すると、ウインドウに枠がつく. 枠を表示したくないときは、このページのプログラムを使用する.
【サイト内の OpenCV 関連ページ】
【OpenCV の公式情報】
Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Python で OpenCV を動かすためのもの.
OpenCV Python のインストールは:別ページ »で説明1~2 コマンドの実行でインストールできる.
USB接続できるビデオカメラを準備し,パソコンに接続しておく.
OpenCV による動画表示を行う.
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) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
※ 止めたいとき,右上の「x」をクリックしない.画面の中をクリックしてから,「q」のキーを押して閉じる
OpenCV による動画表示を行う.
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) # Press Q to exit if cv2.waitKey(1) & 0xFF == ord('q'): break v.release() cv2.destroyAllWindows()
※ 止めたいとき,右上の「x」をクリックしない.画面の中をクリックしてから,「q」のキーを押して閉じる