尝试在 opencv imread 函数中使用多个图像但没有得到

Trying to use multiple images in opencv imread function but not getting

import pprint as pp

original_img = cv2.imread("/content/drive/My Drive/images/image1.jpg") #here i want to use multiple images atleast 250 images.

original_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2RGB)
results = tfnet2.return_predict(original_img)
print(results)

我猜你所有的图片都在文件夹图片中。所以你可以使用 os 来获取他们所有的文件名。

import os
pth = "/content/drive/My Drive/images" # make sure it is correct
images = os.listdir(pth)
for image in images:
    image_path = os.path.join(pth, image)
    original_img = cv2.imread(image_path)
    original_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2RGB)
    results = tfnet2.return_predict(original_img)
    print(results)

任何人都可以使用 for 循环添加空文件夹,使用基本加法“+”运算符将所有 json 文件直接定向到同一文件夹。

我在范围内():

original_img = cv2.imread("/文件夹路径(500+张图片)/" + any_empty_folder[i])