先準備一目錄 byfish 裡面放了圖片 
Python opencv  獲取 圖片列表 圖片大小 
 
 
 
代碼如下: 
- import os
 
 - import cv2
 
 - import numpy as np
 
  
- pic_floder = 'byfish'
 
 - # open floder
 
 - i = 0
 
 - with open(pic_floder+'.txt', 'w') as f:
 
 -     # search floder pic name
 
 -     for img in os.listdir(pic_floder):
 
 -         # get pic width and height
 
 -         img_hw = cv2.imread(pic_floder+"/"+img)
 
 -         sp = img_hw.shape
 
 - #         print(sp)
 
 - #         sz1 = sp[0]#height(rows) of image
 
 - #         sz2 = sp[1]#width(colums) of image
 
 - #         sz3 = sp[2]#the pixels value is made up of three primary colors
 
 - #         print('width: %d \nheight: %d \nnumber: %d' %(sz1,sz2,sz3))
 
 - #            pic_floder, img_name,img_num,rectX,rectY,rectW,rectH
 
 -         line = pic_floder+'/'+img+'  1    0    0    '+str(sp[1])+'  '+str(sp[0])+'\n'
 
 -         f.write(line)
 
 -         i += 1
 
 - #計算圖片數量
 
 - print(i)
 
  複製代碼 
 
結果會建立 byfish.txt 檔案 
打開看看 
Python opencv  獲取 圖片列表 圖片大小 
 
 
 
 
網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計 
 |