LoginSignup
0
1

More than 5 years have passed since last update.

Python2 + eog > 複数の画像をeogで開く | overlay_image_171003_execとの組合わせ例

Last updated at Posted at 2017-10-03
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)

Pythonスクリプトから複数画像をeogで開く。

code

test_eog_files_171003.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import subprocess as sb
import os
import time

#on Python 2.6.6
#coding rule: PEP8

IMG_CMD = "eog"


def debug_show_single_image(afile):
    # require wait to open each image in eog
    chkcmd = IMG_CMD + " " + afile
    print(chkcmd)
    sb.Popen(chkcmd.split())
    time.sleep(1)

alist = "gray.png", "blue.png", "red.png"

for elem in alist:
    debug_show_single_image(elem)

run
$python test_eog_files_171003.py 

上記を実行すると3つのeogのウィンドウが開く。

waitを入れないと1つのeogウィンドウしか開かない。

使用例

composite_171003.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import glob
import sys
import subprocess as sb
import os
import time

# v0.1 Oct. 03, 2017
#   - add debug_show_single_image()
#   - add invoke_script()
#   - add get_filename()
#   - add remove_symlinks()


def invoke_script(ascript):
    #scd: script directory
    scd = os.path.dirname(os.path.realpath(__file__))
    acmd = scd + "/" + ascript
    print(acmd)
    sb.call(acmd.split())


def debug_show_single_image(afile):
    # require wait to open each image in eog
    chkcmd="eog " + afile
    print(chkcmd)
    sb.Popen(chkcmd.split())
    time.sleep(1)


res = sorted(glob.glob("png*/*_06.png"), key=os.path.getmtime)
for elem in res:
    print(elem)
    full_len = len(elem)
    #print(full_len)

    wo_hh = elem[:full_len - 7]  # 7: to remove "_hh.png"
    print(wo_hh)

    acmd = "overlay_image_171003_exec "
    for postfix in "_24.png", "_18.png", "_12.png", "_06.png":
        debug_show_single_image(wo_hh + postfix)
        #
        acmd += wo_hh + postfix + " "
    acmd += "wrk.png"
    acmd += ""
    invoke_script(acmd)
    debug_show_single_image("wrk.png")

    sys.exit()  # debug

データを用意して実行すると、4つのeogウィンドウが開き、それらの合成のwrk.pngがeogで開く。

関連

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1