def test_validation_for_overlapping_case(): tdir = tempfile.TemporaryDirectory() # Each image will have the center of the other # pasted in the top left corner. image1 = pht.read(pt.DEFAULT_TEST_IMAGES[0]) image2 = pht.read(pt.DEFAULT_TEST_IMAGES[1]) image1[:100, :100] = image2[100:200, 100:200] image2[:100, :100] = image1[100:200, 100:200] fp1 = os.path.join(tdir.name, 'test1.jpg') fp2 = os.path.join(tdir.name, 'test2.jpg') cv2.imwrite(fp1, image1[..., ::-1]) cv2.imwrite(fp2, image2[..., ::-1]) kp1, des1, dims1 = ldd.generate_image_descriptors(fp1) kp2, des2, dims2 = ldd.generate_image_descriptors(fp2) # These images should not match. assert not ldd.validate_match( kp1=kp1, kp2=kp2, des1=des1, des2=des2, dims1=dims1, dims2=dims2)
def load_and_preprocess(filepath, max_size=DEFAULT_MAX_SIZE): """Read, unletterbox, and resize an image. Args: filepath: The path to the file max_size: The maximum size for a dimension of the image """ image = pht.read(filepath) if image is None: LOGGER.warning("Failed to load image %s", filepath) return None res = pht.unletterbox(image) if res is None: return None (x1, x2), (y1, y2) = res image = image[y1:y2, x1:x2] image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) max_dimension = max(image.shape[:2]) if max_dimension > max_size: scale = max_size / max_dimension image = cv2.resize( image, (int(image.shape[1] * scale), int(image.shape[0] * scale))) return image