To automatically display a full screen image on an external screen

Asked 2 years ago, Updated 2 years ago, 79 views

I'm developing in C++ at Qt Creator.
I want to project a projection mapping image with a connected projector right after Qt is created, but I don't know how to automate it. I want to separate the desktop for work from the desktop for projection, so now I display the image window on my desktop and drag it to the right to maximize on the external screen.

import tkinter ask
import cv2
from PIL import Image, ImageTk
import pyautogui as pag

scr_w,scr_h=pag.size()

root=tk.Tk()
w=scr_w #horizontal length
h = scr_h # Vertical Length
x=scr_w#coordinate axis x
y=0#coordinate axis y

root.geometry('%dx%d+%d+%d'%(w,h,x,y))

result=cv2.imread("/Users/hoge/Desktop/result_pmi.png")
height, width, ch=result.shape
rgb_cv2_image=cv2.resize(result,dsize=(int(h/height*width),scr_h))
rgb_cv2_image = cv2.cvtColor(rgb_cv2_image, cv2.COLOR_BGR2RGB)

pil_image=Image.fromarray(rgb_cv2_image)
tk_image=ImageTk.PhotoImage(pil_image)

canvas=tk.Canvas(root, bg="white", height=h, width=w)
canvas.create_image((w-int(h/height*width))/2,0, image=tk_image, anchor=tk.NW)
canvas.place(x=0,y=0)
root.attributes('-fullscreen', True)
root.mainloop()

This python program
std::system("/opt/anaconda3/bin/python./test.py")
Call in

So far, I have been able to display it on the external screen, but scr_w,scr_h=pag.size() is not the size of the external screen, but the size of the work desktop, so I can't display the full screen on the external screen.

opencv qt qt-creator

2022-09-30 20:13

1 Answers

I was able to get the size of the multi-monitor with screeninfo and adapt the image size to the full screen

import tkinter ask
import cv2
from PIL import Image, ImageTk
import pyautogui as pag
import screeninfo
import re
import sys


m=screeninfo.get_monitors()
print(m)
m = str(m)
scr_w = re.findall("width=\d+",m)
scr_h=re.findall("height=\d+",m)
scr_w = re.findall("\d+",scr_w[1]
scr_h = re.findall("\d+", scr_h[1])

scr_w, scr_h = int(scr_w[0]), int(scr_h[0])

root=tk.Tk()
def close (event): Close with #esc key
    root.withdraw()#if you want to sing it back
    sys.exit()# if you want to exit the entirething

root.bind('<Escape>', close)
w=scr_w #horizontal length
h = scr_h # Vertical Length
x=scr_w#coordinate axis x
y=0#coordinate axis y

root.geometry('%dx%d+%d+%d'%(w,h,x,y))

result=cv2.imread("/Users/hoge/Desktop/result_pmi.png")
height, width, ch=result.shape
rgb_cv2_image=cv2.resize(result,dsize=(int(h/height*width),scr_h))
rgb_cv2_image = cv2.cvtColor(rgb_cv2_image, cv2.COLOR_BGR2RGB)

pil_image=Image.fromarray(rgb_cv2_image)
tk_image=ImageTk.PhotoImage(pil_image)

canvas=tk.Canvas(root, bg="black", height=h, width=w)
canvas.create_image((w-int(h/height*width))/2,0, image=tk_image, anchor=tk.NW)
canvas.place(x=0,y=0)
root.attributes('-fullscreen', True)
root.mainloop()


2022-09-30 20:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.