Python 制作全息图金字塔
Python making Hologram pyramid
我正在研究全息视觉。我想把 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()
但我的图像看起来像这样。
我该如何解决?
普通RGB图像的dtype
是uint8
,不是float64
。
image = np.zeros((height, width, 3), dtype=np.uint8)
顺便说一句:您不必设置 image[:, :] = 0 # black screen
。 np.zeros
.
已完成此操作
我正在研究全息视觉。我想把 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()
但我的图像看起来像这样。
我该如何解决?
普通RGB图像的dtype
是uint8
,不是float64
。
image = np.zeros((height, width, 3), dtype=np.uint8)
顺便说一句:您不必设置 image[:, :] = 0 # black screen
。 np.zeros
.