Reputation: 1
My program is testing only one picture example_01.png, I want to test all images that I put in my folder examples so how can I do that ? thanks
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-f", "--face", type=str,
default="face_detector",
help="path to face detector model directory")
ap.add_argument("-m", "--model", type=str,
default="mask_detector.model",
help="path to trained face mask detector model")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
# load our serialized face detector model from disk
print("[INFO] loading face detector model...")
prototxtPath = os.path.sep.join([args["face"], "deploy.prototxt"])
weightsPath = os.path.sep.join([args["face"],
"res10_300x300_ssd_iter_140000.caffemodel"])
net = cv2.dnn.readNet(prototxtPath, weightsPath)
# load the face mask detector model from disk
print("[INFO] loading face mask detector model...")
model = load_model(args["model"])
# load the input image from disk, clone it, and grab the image spatial
# dimensions
image = cv2.imread(args["image"])
orig = image.copy()
(h, w) = image.shape[:2]
Call:
python detect_mask_image.py --image examples/example_01.png
Upvotes: 0
Views: 1216
Reputation: 200
def main(args):
# Prepare an image
directory = 'example'
img_path_list =[]
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
# checking if it is a file
if os.path.isfile(f):
print(f)
# print(type)
img_path_list.append(f)
print(img_path_list)
args.image = img_path_list
print(args.image, "**") #list of Frames path
print(args.image[0])
print(type(args.image[0]))
for i,j in enumerate(args.image):
image = load_image(args.image[i], transform)
image_tensor = image.to(device)
# Generate an caption from the image
feature = encoder(image_tensor)
sampled_ids = decoder.sample(feature)
sampled_ids = sampled_ids[0].cpu().numpy() # (1, max_seq_length) -> (max_seq_length)
# Convert word_ids to words
captions = []
sampled_caption = []
for word_id in sampled_ids:
word = vocab.idx2word[word_id]
sampled_caption.append(word)
if word == '<end>':
break
sentence = ' '.join(sampled_caption)
# Print out the image and the generated caption
print("*****************************************")
print (sentence)
captions.append(sentence)
print("*****************************************")
image = Image.open(args.image[i], "rb")
plt.imshow(np.asarray(image))
Upvotes: 1
Reputation: 301
Did you try os.list_dir(pathName)? By this function you can list all the photos which are present in a directory "path"
You can convert the result from this to list and loop through all the images!
#!/usr/bin/python
import os, sys
# Open a file
path = "/var/www/html/"
dirs = os.listdir( path )
# This would print all the files and directories
for file in dirs:
print file
Code from - https://www.tutorialspoint.com/python/os_listdir.htm
Upvotes: 0