TShopping

標題: Python opencv 如何獲取圖片列表及圖片大小 [打印本頁]

作者: woff    時間: 2020-11-17 10:59
標題: Python opencv 如何獲取圖片列表及圖片大小
先準備一目錄 byfish 裡面放了圖片


代碼如下:
  1. import os
  2. import cv2
  3. import numpy as np

  4. pic_floder = 'byfish'
  5. # open floder
  6. i = 0
  7. with open(pic_floder+'.txt', 'w') as f:
  8.     # search floder pic name
  9.     for img in os.listdir(pic_floder):
  10.         # get pic width and height
  11.         img_hw = cv2.imread(pic_floder+"/"+img)
  12.         sp = img_hw.shape
  13. #         print(sp)
  14. #         sz1 = sp[0]#height(rows) of image
  15. #         sz2 = sp[1]#width(colums) of image
  16. #         sz3 = sp[2]#the pixels value is made up of three primary colors
  17. #         print('width: %d \nheight: %d \nnumber: %d' %(sz1,sz2,sz3))
  18. #            pic_floder, img_name,img_num,rectX,rectY,rectW,rectH
  19.         line = pic_floder+'/'+img+'  1    0    0    '+str(sp[1])+'  '+str(sp[0])+'\n'
  20.         f.write(line)
  21.         i += 1
  22. #計算圖片數量
  23. print(i)
複製代碼


結果會建立 byfish.txt 檔案
打開看看



網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計





歡迎光臨 TShopping (http://www.tshopping.com.tw/) Powered by Discuz! X3.2