Xubuntu 14.04で次のPythonコードを使用して、セカンダリモニタのプレゼンテーションのように./picsディレクトリに格納された画像を表示しようとしています。更新中にデスクトップを表示せずにプレゼンテーションのような画像を表示
from PyQt4 import QtCore, QtGui
import sys
import os
import multiprocessing as mp
import time
def displayImage(impath):
app = QtGui.QApplication(sys.argv)
window = QtGui.QMainWindow()
# Select monitor
screenres = QtGui.QApplication.desktop().screenGeometry(1);
window.move(QtCore.QPoint(screenres.x(), screenres.y()))
window.resize(screenres.width(), screenres.height())
# Set the image to be shown
pic = QtGui.QLabel(window)
pic.setGeometry(0, 0, 1960, 1080)
pic.setPixmap(QtGui.QPixmap(impath))
window.showFullScreen()
app.exec_()
return
def controller(imdir):
# List the contents of the directory
im_paths = os.listdir(imdir)
# Keep only image files
pc = list(im_paths)
for p in pc:
print p
if not p.split('.')[-1] in [ 'jpg', 'JPG', 'png', 'PNG' ]:
im_paths.remove(p)
if not im_paths:
return 1
# Start showing the images by calling project function as a new process (multiprocessing module)
for f in im_paths:
print 'Showing image:', p, '...'
# Run project process
p = mp.Process(target=displayImage, args=(imdir+f,))
p.start()
# Keep dispaying image for 3 seconds
time.sleep(2)
p.terminate()
return 0
if __name__ == '__main__':
controller('./pics/')
exit(0)
問題
時間間隔は、ときAが終了した画像を表示するプロセスとアプリケーションが何も表示されませんし、ためにどこまで来て画像Bを表示するプロセス までありますユーザーエクスペリエンスを破壊するデスクトップが表示される瞬間です。
Qt4を使ってイメージを表示する方法はありますか?
PS。 matplotlibおよび/またはopencvを含む回答が受け入れられるかもしれませんが、私は、まっすぐ進む道がQtを経由していると思います。
ちょっと質問:あなたが表示するすべてのイメージに対して新しいQApplicationを起動し、単に「Pixmap」でイメージを更新するだけではなく、起動するのはなぜですか?初期化には時間がかかります。そして1つのイメージを表示している間に、新しい '' QPixmap''を作り、 '' QPixmap.swap''を使って '' x''秒後に切り替えるのですか? – alexblae
こんにちは!私はQtを経験していないので、最適な解決策が何であるか想像できません。あなたの答えは素敵なアイデアのようです!それで、私はそれに取り組んでいます。 QPixmap.swapメソッドの使用例を教えてください。 – funk