def test_crop_random():
# Given one sample image and the following parameters
image = helpers.get_one_sample_image()
parameters = {"dst_size" : (20, 20),
"n_patches" : 5,
}
# When perform crop_random()
patches = utils.crop_random(image, parameters["dst_size"], parameters["n_patches"])
# Then every patch should be included in an image.
match_cost = []
for patch in patches:
M = cv2.matchTemplate(image, patch, cv2.TM_SQDIFF)
min_cost, _, _, _ = cv2.minMaxLoc(M)
match_cost.append(min_cost)
assert np.array(match_cost).all() == 0, "utils.crop_random() unit test failed!!"
评论列表
文章目录