Exemple #1
0
def _pdq_from_numpy_array(array: numpy.ndarray) -> PDQOutput:
    hash_vector, quality = pdqhash.compute(array)

    bin_str = "".join([str(x) for x in hash_vector])

    # binary to hex using format string
    # '%0*' is for padding up to ceil(num_bits/4),
    # '%X' create a hex representation from the binary string's integer value
    hex_str = "%0*X" % ((len(bin_str) + 3) // 4, int(bin_str, 2))
    hex_str = hex_str.lower()

    return hex_str, quality
Exemple #2
0
def pdq_from_file(path: pathlib.Path):
    """
    Given a path to a file return the PDQ Hash string in hex
    Current Supported file types: jpg
    """
    img_pil = Image.open(path)
    image = np.asarray(img_pil)
    hash_vector, quality = pdqhash.compute(image)

    bin_str = "".join([str(x) for x in hash_vector])

    # binary to hex using format string
    # '%0*' is for padding up to ceil(num_bits/4),
    # '%X' create a hex representation from the binary string's integer value
    hex_str = "%0*X" % ((len(bin_str) + 3) // 4, int(bin_str, 2))
    hex_str = hex_str.lower()

    return hex_str, quality
Exemple #3
0
 def _compute_with_quality(self, image):
     hash_vector, quality = pdqhash.compute(image)
     return hash_vector > 0, quality
Exemple #4
0
 def _compute(self, image):
     return pdqhash.compute(image)[0] > 0