简体   繁体   中英

cv2.imshow() on a different screen

In a Python script using OpenCV, I would like to open named windows on different screens/displays.

I'm on Linux and X is set up such that I have two displays. I can control on which display named windows will open by default by setting the environment variable DISPLAY to :0.0 or :0.1 , respectively. However, what I would like to do is open one named window on :0.0 and one on :0.1 and be able to update each one continuously.

I've found Xlib , which lets me query for example which one is the default screen, but I cannot change it. Also, I can update environment variables doing something like os.environ['DISPLAY'] = ':0.0' , but, unsurprisingly, that doesn't have any effect on windows opened afterwards.

Using multiprocessing.Process seems to do the trick. The following will show the picture on :0.0 and :0.1 displays:

import os
import time
from multiprocessing import Process
import cv2

def f(display):
    os.environ['DISPLAY'] = display
    print(os.environ['DISPLAY'])
    a = cv2.imread('avatar.png')
    cv2.imshow('window on %s'%display, a)
    cv2.waitKey(1000)
    time.sleep(10)

Process(target=f, args=(':0.0',)).start()
Process(target=f, args=(':0.1',)).start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM