这是我想做的:
我定期用网络摄像头拍照。就像时间流逝一样。然而,如果没有什么真正的改变,也就是说,图片看起来几乎相同,我不想存储最新的快照。
我想有某种方法可以量化这种差异,我必须根据经验确定一个阈值。
我追求的是简单而不是完美。 我用的是python。
这是我想做的:
我定期用网络摄像头拍照。就像时间流逝一样。然而,如果没有什么真正的改变,也就是说,图片看起来几乎相同,我不想存储最新的快照。
我想有某种方法可以量化这种差异,我必须根据经验确定一个阈值。
我追求的是简单而不是完美。 我用的是python。
当前回答
I have been having a lot of luck with jpg images taken with the same camera on a tripod by (1) simplifying greatly (like going from 3000 pixels wide to 100 pixels wide or even fewer) (2) flattening each jpg array into a single vector (3) pairwise correlating sequential images with a simple correlate algorithm to get correlation coefficient (4) squaring correlation coefficient to get r-square (i.e fraction of variability in one image explained by variation in the next) (5) generally in my application if r-square < 0.9, I say the two images are different and something happened in between.
这是强大的和快速的在我的实现(Mathematica 7)
这是值得玩转的部分,你感兴趣的图像,并通过裁剪所有的图像到那个小区域,否则一个远离相机但重要的变化将被错过。
我不知道如何使用Python,但我确信它也有相关性,不是吗?
其他回答
给出的大多数答案都不涉及照明水平。
在进行比较之前,我首先将图像归一化到标准的光照水平。
下面是我写的一个函数,它以2个图像(文件路径)作为参数,并返回两个图像“像素”组件之间的平均差值。这对我确定视觉上“相等”的图像(当它们不==相等时)非常有效。
(我发现8个是判断图像本质上是否相同的一个很好的限制。)
(如果不添加预处理,图像必须具有相同的尺寸。)
from PIL import Image
def imagesDifference( imageA, imageB ):
A = list(Image.open(imageA, r'r').convert(r'RGB').getdata())
B = list(Image.open(imageB, r'r').convert(r'RGB').getdata())
if (len(A) != len(B)): return -1
diff = []
for i in range(0, len(A)):
diff += [abs(A[i][0] - B[i][0]), abs(A[i][1] - B[i][1]), abs(A[i][2] - B[i][2])]
return (sum(diff) / len(diff))
I have been having a lot of luck with jpg images taken with the same camera on a tripod by (1) simplifying greatly (like going from 3000 pixels wide to 100 pixels wide or even fewer) (2) flattening each jpg array into a single vector (3) pairwise correlating sequential images with a simple correlate algorithm to get correlation coefficient (4) squaring correlation coefficient to get r-square (i.e fraction of variability in one image explained by variation in the next) (5) generally in my application if r-square < 0.9, I say the two images are different and something happened in between.
这是强大的和快速的在我的实现(Mathematica 7)
这是值得玩转的部分,你感兴趣的图像,并通过裁剪所有的图像到那个小区域,否则一个远离相机但重要的变化将被错过。
我不知道如何使用Python,但我确信它也有相关性,不是吗?
一个简单的解决方案:
将图像编码为jpeg格式,并寻找文件大小的实质性变化。
我曾经用视频缩略图实现过类似的东西,并且取得了很大的成功和可伸缩性。
使用SSIM测量两幅图像之间的结构相似指数度量。