TShopping
標題:
Python opencv 如何獲取圖片列表及圖片大小
[打印本頁]
作者:
woff
時間:
2020-11-17 10:59
標題:
Python opencv 如何獲取圖片列表及圖片大小
先準備一目錄 byfish 裡面放了圖片
(, 下載次數: 11)
上傳
點擊文件名下載附件
代碼如下:
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
檔案
打開看看
(, 下載次數: 9)
上傳
點擊文件名下載附件
網頁設計,網站架設 ,網路行銷,網頁優化,SEO -
NetYea 網頁設計
歡迎光臨 TShopping (http://www.tshopping.com.tw/)
Powered by Discuz! X3.5