很多站长朋友们都不太清楚php相似图片识别,今天小编就来给大家整理php相似图片识别,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 如何使用PHP实现图像比较 2、 php怎么做图片识别 3、 php+vue.js怎么用照片搜索相似照片 4、 php怎么实现根据图片搜索图片功能 5、 php如何实现,远程传一张照片回来,在数据库进行比对识别,有相同的就取出相关信息 如何使用PHP实现图像比较<?php
/**
* 图片相似度比较
*
* @version $Id: ImageHash.php 4429 2012-04-17 13:20:31Z jax $
* @author jax.hu
*
* <code>
* //Sample_1
* $aHash = ImageHash::hashImageFile('wsz.11.jpg');
* $bHash = ImageHash::hashImageFile('wsz.12.jpg');
* var_dump(ImageHash::isHashSimilar($aHash, $bHash));
*
* //Sample_2
* var_dump(ImageHash::isImageFileSimilar('wsz.11.jpg', 'wsz.12.jpg'));
* </code>
*/
class ImageHash {
/**取样倍率 1~10
* @access public
* @staticvar int
* */
public static $rate = 2;
/**相似度允许值 0~64
* @access public
* @staticvar int
* */
public static $similarity = 80;
/**图片类型对应的开启函数
* @access private
* @staticvar string
* */
private static $_createFunc = array(
IMAGETYPE_GIF =>'imageCreateFromGIF',
IMAGETYPE_JPEG =>'imageCreateFromJPEG',
IMAGETYPE_PNG =>'imageCreateFromPNG',
IMAGETYPE_BMP =>'imageCreateFromBMP',
IMAGETYPE_WBMP =>'imageCreateFromWBMP',
IMAGETYPE_XBM =>'imageCreateFromXBM',
);
/**从文件建立图片
* @param string $filePath 文件地址路径
* @return resource 当成功开启图片则传递图片 resource ID,失败则是 false
* */
public static function createImage($filePath){
if(!file_exists($filePath)){ return false; }
/*判断文件类型是否可以开启*/
$type = exif_imagetype($filePath);
if(!array_key_exists($type,self::$_createFunc)){ return false; }
$func = self::$_createFunc[$type];
if(!function_exists($func)){ return false; }
return $func($filePath);
}
php怎么做图片识别个人建议:楼主使用php进行图片识别,不如使用ocr文字识别技术来进行图片识别,这样更方便,请看下面的方法:
首先,在电脑上安装ocr文字识别软件(迅捷ocr文字识别软件)。
接着,运行ocr,选择上面的‘极速识别’功能。
然后,点击左上角的‘添加文件’,不需要识别的图片添加进去。
最后,点击操作下面的‘开始识别’按钮。
希望上方的方法可以帮助到你。
php+vue.js怎么用照片搜索相似照片需要工具:电脑、浏览器、搜索引擎
一、首先选择任意浏览器,点击打开。
二、然后打开搜索,可以看到搜索框有一个照相机的小图标。
三、点一下相机的小图标,会提示拖拽一张照片或者上传一张照片,这个根据自己的情况选择。
四、这里我们选择上传,选一张自己想找相似的图片,双击图片。
五、好了,这个时候就搜索出了图片的来源和出处,还有类似的图片。
php怎么实现根据图片搜索图片功能php爱好者 们很对php开发的追求是永不止步的,今天偶然想起来了 发下
php怎么实现相似图片的搜索呢?
其中的原理来解释下
1、缩小尺寸。将图片缩小到8×8的尺寸,总共64个像素。这一步的作用是去除图片的细节,只保留结构、明暗等基本信息,摒弃不同尺寸、比例带来的图片差异。
2、简化色彩。将缩小后的图片,转为64级灰度。也就是说,所有像素点总共只有64种颜色。
3、计算平均值。计算所有64个像素的灰度平均值。
4、比较像素的灰度。将每个像素的灰度,与平均值进行比较。大于或等于平均值,记为1;小于平均值,记为0。
5、计算哈希值。将上一步的比较结果,组合在一起,就构成了一个64位的整数,这就是这张图片的指纹。组合的次序并不重要,只要保证所有图片都采用同样次序就行了。得到指纹以后,就可以对比不同的图片,看看64位中有多少位是不一样的。
使用代码
hash($f);
}
return $isString ? $result[0] : $result;
}
public function checkIsSimilarImg($imgHash, $otherImgHash){
if (file_exists($imgHash) file_exists($otherImgHash)){
$imgHash = $this->run($imgHash);
$otherImgHash = $this->run($otherImgHash);
}
if (strlen($imgHash) !== strlen($otherImgHash)) return false;
$count = 0;
$len = strlen($imgHash);
for($i=0;$i<$len;$i++){
if ($imgHash{$i} !== $otherImgHash{$i}){
$count++;
}
}
return $count <= (5 * $rate * $rate) ? true : false;
}
public function hash($file){
if (!file_exists($file)){
return false;
}
$height = 8 * $this->rate;
$width = 8 * $this->rate;
$img = imagecreatetruecolor($width, $height);
list($w, $h) = getimagesize($file);
$source = $this->createImg($file);
imagecopyresampled($img, $source, 0, 0, 0, 0, $width, $height, $w, $h);
$value = $this->getHashValue($img);
imagedestroy($img);
return $value;
}
public function getHashValue($img){
$width = imagesx($img);
$height = imagesy($img);
$total = 0;
$array = array();
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
$gray = ( imagecolorat($img, $x, $y) >> 8 ) 0xFF;
if (!is_array($array[$y])){
$array[$y] = array();
}
$array[$y][$x] = $gray;
$total += $gray;
}
}
$average = intval($total / (64 * $this->rate * $this->rate));
$result = '';
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
if ($array[$y][$x] >= $average){
$result .= '1';
}else{
$result .= '0';
}
}
}
return $result;
}
public function createImg($file){
$ext = $this->getFileExt($file);
if ($ext === 'jpeg') $ext = 'jpg';
$img = null;
switch ($ext){
case 'png' : $img = imagecreatefrompng($file);break;
case 'jpg' : $img = imagecreatefromjpeg($file);break;
case 'gif' : $img = imagecreatefromgif($file);
}
return $img;
}
public function getFileExt($file){
$infos = explode('.', $file);
$ext = strtolower($infos[count($infos) - 1]);
return $ext;
}
}
调用方式如下:
require_once "Imghash.class.php";
$instance = ImgHash::getInstance();
$result = $instance->checkIsSimilarImg('chenyin/IMG_3214.png', 'chenyin/IMG_3212.JPG');
如果$result值为true, 则表明2个图片相似,否则不相似。
php如何实现,远程传一张照片回来,在数据库进行比对识别,有相同的就取出相关信息数据库,你可能保存有图片的文件名,大小,格式化,来本地文件路径,
把传过来的图片的这三个特征在数据库查找一下,如果存在,就几乎可以判断是同一个文件,
如果你要更准确一些,就用file_get_contents()把文件内容读出来进行对比。
关于php相似图片识别的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php相似图片识别 php图片文字识别源码的详细内容...