你好我是python的新手,我想知道如何從計算機上的目錄加載圖像到python變量。 我在磁盤上的文件夾中有一組圖像,我想在循環中顯示這些圖像。如何從Python中的計算機上的目錄加載圖像
1
A
回答
0
您可以使用PIL(Python Imaging Library)http://www.pythonware.com/products/pil/來加載圖像。 然後,您可以製作一個腳本來讀取目錄中的圖像並將它們加載到python中,如下所示。
#!/usr/bin/python
from os import listdir
from PIL import Image as PImage
def loadImages(path):
# return array of images
imagesList = listdir(path)
loadedImages = []
for image in imagesList:
img = PImage.open(path + image)
loadedImages.append(img)
return loadedImages
path = "/path/to/your/images/"
# your images in an array
imgs = loadImages(path)
for img in imgs:
# you can show every image
img.show()
0
您可以使用glob和imageio python包實現相同。下面是python 3中的代碼:
import glob
import imageio
for image_path in glob.glob("<your image directory path>\\*.png"):
im = imageio.imread(image_path)
print (im.shape)
print (im.dtype)
相關問題
- 1. 我如何在JAVAFX中加載計算機目錄圖像
- 2. 如何從用戶計算機加載圖像
- 3. 計算目錄中的圖像
- 4. 從XAP目錄中加載圖像
- 5. 如何從Jquery的Image目錄中隨機加載單個圖像?
- 6. 從php目錄中加載隨機圖像
- 7. 如何使用python在LAN上的計算機上打開目錄/文件夾?
- 8. 的Javascript從目錄中隨機圖像
- 9. jQuery - 從目錄加載隨機圖片
- 10. 加載目錄中的所有圖像
- 11. 如何從本地目錄中以C++加載圖像
- 12. 加載圖像到閃存從目錄
- 13. Android:從特定目錄加載圖像
- 14. 如何計算在圖像視圖中加載圖像所用的時間
- 15. 預加載圖像目錄
- 16. 將圖像添加到從目錄加載的TreeView中
- 17. 如何在Python Pillow上加載圖像?
- 18. 如何在Python中使用Wmi從活動目錄獲取計算機列表
- 19. 從不同目錄加載png圖像Python Pygame
- 20. 未從目錄中的母版頁加載的圖像
- 21. 如何從pyside qwebview的本地計算機加載JavaScript?
- 22. CSS-你如何在用戶的計算機上引用圖像?
- 23. 加載活動目錄用戶及其關聯計算機
- 24. 無法從我的計算機上的本地目錄中加載文件,java程序
- 25. 如何從計算機向Android手機發送連續圖像
- 26. 從目錄中隨機獲取圖像?
- 27. 如何使用jquery從目錄加載圖像
- 28. 如何從文檔目錄加載圖像/ IPHONE
- 29. 如何使用flash從目錄加載圖像?
- 30. 如何從一個目錄加載所有圖像
非常感謝,那樣做:) – Aditya