php – 使用Picasa API自动进行脸部检测,以提取单个图像

前端之家收集整理的这篇文章主要介绍了php – 使用Picasa API自动进行脸部检测,以提取单个图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
(对于与应用程序相关的答案,已经有一个类似的问题被问及超级用户的问题.问题在此发布,以收集相同的可编程解决方案)

在我的工作地点,护照尺寸的照片被扫描在一起,然后切成单独的图片,并保存与唯一的文件编号.目前我们使用Paint.net手动选择,剪切和保存图片.

扫描文档Picasa截图:
(来自:谷歌图像搜索多个来源,公平)

例如在Picasa 3.8中,点击查看>人,所有的脸都被显示出来,我被要求命名,我可以自动保存这些个人图片,名称不同的图片

更新

所有我想做的是将上面的图片转换为个人图片.

在上图中,我已经显示了Picasa 3.8如何检测到图像,并提示我将其命名.我不需要脸部识别,我只需要脸部检测. Picasa检测到单个图像,并在RHS上显示它们.这些单独的图像是我需要的. Picasa创建一个.ini文件,它保存包含单个面的坐标的十六进制值.

这些个人面孔是我感兴趣的如果我可以有坐标,我可以从图片中裁剪所需的图像.

SAMPLE.jpg

ini内容

[SAMPLE.jpg]
faces=rect64(c18f4c8ef407851e),d4ff0a020be5c3c0;rect64(534a06d429ae627),dff6163dfd9d4e41;rect64(b9c100fae46b3046),e1059dcf6672a2b3;rect64(7b5105daac3a3cf4),4fc7332c107ffafc;rect64(42a036a27062a6c),ef86c3326c143248;rect64(31f4efe3bd68fd8),90158b3d3b65dc9b;rect64(327904e0614d390d),43cbda6e92fcb63e;rect64(4215507584ae9b8c),15b6a967e857f334;rect64(895d4efeb8b68425),5c4ff70ac70b27d3
backuphash=3660

* ini文件似乎正在将脸标签的坐标保存为每个标签的rect64(534a06d429ae627),dff6163dfd9d4e41.
来自Picasa Help Site用户Technonath

@oedious wrote:- This is going to be
somewhat technical,so hang on.
* The number encased in rect64() is a 64-bit hexadecimal number.
* Break that up into four 16-bit numbers.
* Divide each by the maximum unsigned 16-bit number (65535) and you’ll have
four numbers between 0 and 1.
* The four numbers remaining give you relative coordinates for the face
rectangle: (left,top,right,bottom).
* If you want to end up with absolute coordinates,multiple the left and
right by the image width and the top
and bottom by the image height.

上面的报价谈到了在rect64()中包含的数字,逗号后的括号内的数字呢?

我问过一个相关的问题.答案也可以帮助你.
Get four 16bit numbers from a 64bit hex value

Note: The
ini details are the same which picasa
generated for the particular image.

Plus the question has been updated multiple times and may not be clear enough.

Picasa Help site有一些回应,我问同样的问题
来自该线程的答案之一是根据ini文件中的十六进制值获取坐标.以下代码在C#从esac从帮助网站.我可以在PHP中做同样的工作吗?

public static RectangleF GetRectangle(string hashstr)
{
    UInt64 hash = UInt64.Parse(hashstr,System.Globalization.NumberStyles.HexNumber);
    byte[] bytes = BitConverter.GetBytes(hash);

    UInt16 l16 = BitConverter.ToUInt16(bytes,6);
    UInt16 t16 = BitConverter.ToUInt16(bytes,4);
    UInt16 r16 = BitConverter.ToUInt16(bytes,2);
    UInt16 b16 = BitConverter.ToUInt16(bytes,0);

    float left = l16 / 65535.0F;
    float top = t16 / 65535.0F;
    float right = r16 / 65535.0F;
    float bottom = b16 / 65535.0F;

    return new RectangleF(left,right - left,bottom - top);
}

PHP代码尝试将64位转换为1到0之间的数字

<?PHP
$dim = getimagesize("img.jpg");    
$hex64=array();
$b0="c18f4c8ef407851e";
$hex64[]=substr($b0,4);
$hex64[]=substr($b0,4,8,12,4);
$width=$dim[0];
$height=$dim[1];
foreach($hex64 as $hex16){
$dec=hexdec($hex16);
$divide=65536;
$mod=$dec%$divide;
$result=$dec/$divide;
$cordinate1=$result*$width;
$cordinate2=$result*$height;
echo "Remainder 1 : ".$mod." ; Result 1 :  ".$result."<br/>CO-ORDINATES : <B>".$cordinate1." ".$cordinate2."</B><br/>";
}
?>

输出

Remainder 1 : 49551 ; Result 1 :
0.75608825683594 CO-ORDINATES : 371.99542236328 396.94633483887 Remainder 1 : 19598 ; Result 1 :
0.29904174804688 CO-ORDINATES : 147.12854003906 156.99691772461 Remainder 1 : 62471 ; Result 1 :
0.95323181152344 CO-ORDINATES : 468.99005126953 500.4467010498 Remainder 1 : 34078 ; Result 1 :
0.51998901367188 CO-ORDINATES : 255.83459472656 272.99423217773

所以我也有坐标,@Nirmal有shown how to crop them.现在接下来的步骤是解析picasa.ini的十六进制代码文件名,并整合代码. Picasa当前没有通过api(或Do they?)提供十六进制代码.如果是这样,事情会更好.

所以我们正在接近一个解决方案.谢谢大家,我希望我可以奖赏每个人(我不能,但不要害怕,并期待你的代表的一个尖峰)

要回答picasa问题,请参阅picasa论坛上的此回复
http://www.google.com/support/forum/p/Picasa/thread?tid=36ae553a7b49088e&hl=en

@oedious wrote:- This is going to be somewhat technical,so hang on. * The number encased in rect64() is a 64-bit hexadecimal number. * Break that up into four 16-bit numbers. * Divide each by the maximum unsigned 16-bit number (65535) and you’ll have four numbers between 0 and 1. * The four numbers remaining give you relative coordinates for the face rectangle: (left,bottom). * If you want to end up with absolute coordinates,multiple the left and right by the image width and the top and bottom by the image height.

猜你在找的PHP相关文章