找回密碼
 註冊
搜索
查看: 1107|回復: 0

[教學] Python opencv 如何獲取圖片列表及圖片大小

[複製鏈接]
發表於 2020-11-17 10:59:03 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
先準備一目錄 byfish 裡面放了圖片

Python opencv 獲取 圖片列表 圖片大小

Python opencv  獲取 圖片列表 圖片大小


代碼如下:
  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 檔案
打開看看

Python opencv 獲取 圖片列表 圖片大小

Python opencv  獲取 圖片列表 圖片大小



網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計
 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-5-1 04:14 , Processed in 0.023177 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表