100,000 pictures, how to find two similar pictures?

Source: Internet
Author: User
100,000 photos, how to find two similar pictures??? Urgent and urgent
The company has a project, need to protect customer's design information, customer information are pictures, how to find two similar pictures from 10w, these two pictures from the same camera shooting, is more like, like face recognition technology, how to achieve similar, than must be similar to two, Can be a similar number of pictures, later we will be artificial comparison?

------to solve the idea----------------------
/**
* Generate fingerprints
* $filename picture file name, can be URL. Only the type of image supported by GD
* $k sampled number of dots
* $retmode return Format: 2 binary represents 1 array 26 binary representation
**/
function Producefingerprint ($filename, $k =8, $retmode =0) {
$sim = imagecreatefromstring (file_get_contents ($filename));
$dim = Imagecreate ($k, $k);
Imagecopyresized ($dim, $sim, 0, 0, 0, 0, $k, $k, Imagesx ($sim), Imagesy ($sim));
Imagetruecolortopalette ($sim, True, 64);
ImageFilter ($sim, Img_filter_grayscale);

for ($x =0; $x < $k; $x + +) for ($y =0; $y < $k; $y + +) {
$c = Imagecolorat ($dim, $x, $y);
$p [] = Array_sum (Imagecolorsforindex ($dim, $c))/3;
}
$avl = Array_sum ($p)/count ($p);
$r = ";
foreach ($p as $v) $r. = $v >= $avl? 1:0;

if ($retmode = = 0) return $r;
$p = Array_map (' Bindec ', Str_split ($r, 8));
if ($retmode = = 1) return $p;
if ($retmode = = 2) {
Array_unshift ($p, '%02x%02x%02x%02x%02x%02x%02x%02x ');
Return Call_user_func_array (' sprintf ', $p);
}
return false;
}

Use this function to generate a fingerprint for each picture, save to the database backup

When checking, the fingerprint is the same as the picture, which does not have to say
Calculation of similarity
$p 1 = producefingerprint ($f 1, $k);
$p 2 = Producefingerprint ($f 2, $k);
$n = Count (Array_diff_assoc (Str_split ($p 1), Str_split ($p 2));
Echo 1-$n/strlen ($p 1);

------to solve the idea----------------------
Similarity (a value less than or equal to 1), the threshold is up to you
Generally think
0.95 very Similar
0.9 Similar
0.85 similar
It's not like it's a little.
------to solve the idea----------------------
Similarity I have tested, photo shooting angle, light and shade on the similarity effect is great!
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.