联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-07-16 03:17

# -*- coding: utf-8 -*-

"""

Created on Wed Apr 18 09:39:58 2018


@author: Administrator

"""


import argparse

import glob


import cv2

import numpy as np

import os

images=cv2.imread("F:\opencv python\GSQ8.jpg")



def show_in_one(images, show_size=(300, 300), blank_size=2, window_name="merge"):

   small_h, small_w = images[0].shape[:2]

   column = int(show_size[1] / (small_w + blank_size))

   row = int(show_size[0] / (small_h + blank_size))

   shape = [show_size[0], show_size[1]]

   for i in range(2, len(images[0].shape)):

       shape.append(images[0].shape[i])


   merge_img = np.zeros(tuple(shape), images[0].dtype)


   max_count = len(images)

   count = 0

   for i in range(row):

       if count >= max_count:

           break

       for j in range(column):

           if count < max_count:

               im = images[count]

               t_h_start = i * (small_h + blank_size)

               t_w_start = j * (small_w + blank_size)

               t_h_end = t_h_start + im.shape[0]

               t_w_end = t_w_start + im.shape[1]

               merge_img[t_h_start:t_h_end, t_w_start:t_w_end] = im

               count = count + 1

           else:

               break

   if count < max_count:

       print("ingnore count %s" % (max_count - count))

   cv2.namedWindow(window_name)

   cv2.imshow(window_name, merge_img)



if __name__ == '__main__':

   parser = argparse.ArgumentParser(description='Demonstrate mouse interaction with images')

   parser.add_argument("-i", "--input", help="Input directory.")

   args = parser.parse_args()

   path = args.input

   if path is None:

       test_dir = "/home/android/Pictures/focus_cut"

       path = test_dir


   debug_images = []

   for infile in glob.glob(os.path.join(path, '*.*')):

       ext = os.path.splitext(infile)[1][1:]  # get the filename extenstion

       if ext == "png" or ext == "jpg" or ext == "bmp" or ext == "tiff" or ext == "pbm":

           print(infile)

           img = cv2.imread(infile)

           if img is None:

               continue

           else:

               debug_images.append(img)


   show_in_one(debug_images)

   cv2.waitKey(0)

   cv2.destroyWindow()


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp