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)
Asked
Active
Viewed 423 times
-2
-
Chaideo, in case you have additional information you can provide to make your question clearer, please [edit] your question to add them. – Yunnosch Feb 15 '20 at 11:03
2 Answers
1
I guess all your images are in the folder images. So you can use os
to gett all their filenames.
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)

Vardan Agarwal
- 2,023
- 2
- 15
- 27
-
actually i want to use multiple images in imread() line. I already provided import os and no need to give path separetly, thanks – Chaideo Feb 15 '20 at 10:34
-
imread() takes one image argument at a time, so you can't use it to read multiple images in one call without iterating one by one through the images name list. If you want a single-line solution, Vardan's solution could be compacted into a single line, but it would go contrary to good coding practices. – Dmitri S Feb 15 '20 at 18:28
-
need to create +500 images json files in one single line and done it for more images i solved the issue not for just single image file, btw thanks for your reply – Chaideo Mar 26 '20 at 10:08
0
anyone can use for loop add empty folder to direct all the json files directly to the same folder using basic addition '+' operator.
for i in range():
original_img = cv2.imread("/folder path(500+ images)/" + any_empty_folder[i])

Chaideo
- 3
- 4