求出一组数据的众数

 

 

依照众数的长宽比、尺寸,定视频的长宽比、尺寸

 

 

import os, time, glob
import cv2

os_sep = os.sep
this_file_abspath = os.path.abspath(__file__)
this_file_dirname, this_file_name = os.path.dirname(this_file_abspath), os.path.abspath(__file__).split(os_sep)[
    -1]

f_v = '{}{}'.format(int(time.time()), 'saveVideo.avi')
f_img_d = '{}{}{}{}{}'.format(this_file_dirname, os_sep, 'mypng', os_sep, '*.jpg')
imgs, img_size_d = glob.glob(f_img_d), {}
for i in imgs:
    img = cv2.imread(i)
    w_h_s = '{},{}'.format(img.shape[1], img.shape[0])
    if w_h_s not in img_size_d:
        img_size_d[w_h_s] = 1
    else:
        img_size_d[w_h_s] += 1

mode_img_size_wh=sorted(img_size_d.items(), key=lambda img_size_d: img_size_d[0],reverse=True) [0][0].split(',')

  

posted @ 2018-04-09 16:40  papering  阅读(194)  评论(0编辑  收藏  举报