TShopping

 找回密碼
 註冊
搜索
查看: 855|回復: 0
打印 上一主題 下一主題

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2020-11-17 10:59:03 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
先準備一目錄 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 網頁設計

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-25 20:14 , Processed in 0.092323 second(s), 25 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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