我正在研究全息視覺。我想將 4 個影像放在黑屏上。
我寫了這段代碼:
import numpy as np
import cv2
from screeninfo import get_monitors
if __name__ == '__main__':
screen = get_monitors()[0]
print(screen)
width, height = screen.width, screen.height
image = np.zeros((height, width, 3), dtype=np.float64)
image[:, :] = 0 # black screen
img = cv2.imread("newBen.png")
p = 0.25
w = int(img.shape[1])
h = int(img.shape[0])
new_img = cv2.resize(img, (w, h))
image[:h, :w] = new_img
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()
但是我的影像看起來像這樣。
我該如何解決?
uj5u.com熱心網友回復:
dtype
正常 RGB 影像的 是,uint8
不是float64
。
image = np.zeros((height, width, 3), dtype=np.uint8)
順便說一句:您不必設定image[:, :] = 0 # black screen
. 這已經由np.zeros
.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/468867.html