python3.7 + opencv4.2.0 全屏循环显示文件夹中所有图像,图像分辨率等于屏幕分辨率,屏幕四周出现白色像素边框
window_name = "Pattern"
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow(window_name, img)
cv2.waitKey(100)
所显示图像与显示器分辨率大小相同,但屏幕显示出来四周有很窄的白色像素边框,图像显示内容也经过了压缩
网上思路:
import win32api, win32gui
window_name = "Pattern"
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
hwndMain = win32gui.FindWindow(None, window_name)
rgb = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 0))
GCLP_HBRBACKGROUND = -10
win32api.SetClassLong(hwndMain, GCLP_HBRBACKGROUND, rgb)
cv2.imshow(window_name, img)
cv2.waitKey(100)
虽然边框被去除,但是显示出的图像经过处理,不为图像原始分辨率:与有白色像素边框时所显示的 内容经压缩的图像 相同
去除白色边框,显示正确分辨率的图像。
或者不用opencv,能正确全屏for循环显示文件夹中所有图像正确分辨率的方法也可
import numpy as np
import cv2
import screeninfo
if __name__ == '__main__':
screen_id = 2
is_color = False
# get the size of the screen
screen = screeninfo.get_monitors()[screen_id]
width, height = screen.width, screen.height
# create image
if is_color:
image = np.ones((height, width, 3), dtype=np.float32)
image[:10, :10] = 0 # black at top-left corner
image[height - 10:, :10] = [1, 0, 0] # blue at bottom-left
image[:10, width - 10:] = [0, 1, 0] # green at top-right
image[height - 10:, width - 10:] = [0, 0, 1] # red at bottom-right
else:
image = np.ones((height, width), dtype=np.float32)
image[0, 0] = 0 # top-left corner
image[height - 2, 0] = 0 # bottom-left
image[0, width - 2] = 0 # top-right
image[height - 2, width - 2] = 0 # bottom-right
window_name = 'projector'
cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow(window_name, screen.x - 1, screen.y - 1)
cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN,
cv2.WINDOW_FULLSCREEN)
cv2.imshow(window_name, image)
cv2.waitKey()
cv2.destroyAllWindows()
"""
Created on Thu Jun 22 16:44:27 2017
@author: sakurai
"""
import numpy as np
import cv2
import screeninfo
if name == 'main':
screen_id = 2
is_color = False
screen = screeninfo.get_monitors()[screen_id]
width, height = screen.width, screen.height
if is_color:
image = np.ones((height, width, 3), dtype=np.float32)
image[:10, :10] = 0 # black at top-left corner
image[height - 10:, :10] = [1, 0, 0] # blue at bottom-left
image[:10, width - 10:] = [0, 1, 0] # green at top-right
image[height - 10:, width - 10:] = [0, 0, 1] # red at bottom-right
else:
image = np.ones((height, width), dtype=np.float32)
image[0, 0] = 0 # top-left corner
image[height - 2, 0] = 0 # bottom-left
image[0, width - 2] = 0 # top-right
image[height - 2, width - 2] = 0 # bottom-right
window_name = 'projector'
cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow(window_name, screen.x - 1, screen.y - 1)
cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN,
cv2.WINDOW_FULLSCREEN)
cv2.imshow(window_name, image)
cv2.waitKey()
cv2.destroyAllWindows()