# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True,
help="path to input directory of images")
args = vars(ap.parse_args())
# initialize the results list
print("[INFO] computing colorfulness metric for dataset...")
results = []
# loop over the image paths
for imagePath in paths.list_images(args["images"]):
# load the image, resize it (to speed up computation), and
# compute the colorfulness metric for the image
image = cv2.imread(imagePath)
image = imutils.resize(image, width=250)
C = image_colorfulness(image)
# display the colorfulness score on the image
cv2.putText(image, "{:.2f}".format(C), (40, 40),
cv2.FONT_HERSHEY_SIMPLEX, 1.4, (0, 255, 0), 3)
# add the image and colorfulness metric to the results list
results.append((image, C))
# sort the results with more colorful images at the front of the
# list, then build the lists of the *most colorful* and *least
# colorful* images
print("[INFO] displaying results...")
results = sorted(results, key=lambda x: x[1], reverse=True)
mostColor = [r[0] for r in results[:25]]
leastColor = [r[0] for r in results[-25:]][::-1]
# construct the montages for the two sets of images
mostColorMontage = build_montages(mostColor, (128, 128), (5, 5))
leastColorMontage = build_montages(leastColor, (128, 128), (5, 5))
在第2行和第3行上分别构建了色彩最丰富和最不丰富的蒙太奇。这里我们指出,蒙太奇中的所有图像将被调整为128 x 128,图像将有5列5行。
现在我们已经组装好了蒙太奇,我们将在屏幕上显示每个蒙太奇。