Python making Hologram pyramid

Issue

I am studying on hologram vision. I want to placed 4 images onto black screen.

I wrote this code:

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()

But my image looking like this.

How can ı fix it?

Solution

The dtype of a normal RGB image is uint8, not float64.

image = np.zeros((height, width, 3), dtype=np.uint8)

Btw: You don’t have to set image[:, :] = 0 # black screen. This is already been done by np.zeros.

Answered By – Markus

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.