私的AI研究会 > PythonGUI
OpenCV 環境下の Python プログラム作成に必要な情報をまとめておく。
出典 → https://docs.opencv.org/3.1.0/dc/d46/group__highgui__qt.html#ga8e6806c75e016cf22d998b4d454b3bfd
# 画像表示 cv2.namedWindow(title, flags=cv2.WINDOW_AUTOSIZE | cv2.WINDOW_GUI_EXPANDED) cv2.imshow(title, frame)
# cvuiの初期化 cv2.namedWindow(WINDOW_NAME, flags=cv2.WINDOW_AUTOSIZE | cv2.WINDOW_GUI_NORMAL) cvui.init(WINDOW_NAME) : # 画像を描画する(cv2.imshowとおなじ) cvui.imshow(WINDOW_NAME, frame)
$ cd ~/workspace_py37/tryocr/ $ python3 cvui_test.py
cv2.imshow('window name', frame) # Window位置の変更 第1引数:Windowの名前 第2引数:x 第3引数:y cv2.moveWindow('window name', 100, 200)
img_h, img_w = image.shape[:2]
img_h, img_w = image.shape[:2] if (img_w > img_h): if (img_w > maxsize): height = round(img_h * (maxsize / img_w)) image = cv2.resize(image, dsize = (maxsize, height)) else: if (img_h > maxsize): width = round(img_w * (maxsize / img_h)) image = cv2.resize(image, dsize = (width, maxsize))
# スクリーンサイズを得る import tkinter def get_display_size(): root= tkinter.Tk() height= root.winfo_screenheight() width= root.winfo_screenwidth() root.destroy() return height, width monitor_height, monitor_width = get_display_size() print("width x height = %d x %d (pixels)" %(monitor_width, monitor_height))