我想得到用相机拍摄的照片的图像差异。在
我尝试了许多使用python库的解决方案:opencv、image magic等
我发现图像比较的解决方案是为了提高精度:
拍摄图像的条件: 1摄像头永远不会移动(安装在固定支架上)。 2对象被手动放置在白纸上,因此对象永远不会正确对齐。(每次角度略有变化,因为是手动操作)
以下代码使用摄像头拍摄的图像示例:
图像示例1:白点:
图像样本2:作为原始图像
图像样本3:黑点
不提供可接受的白点打印输出,但应仅标记差异(缺陷):
目前我正在使用以下图像魔术命令来处理图像差异:
compare -highlight-color black -fuzz 5% -metric AE Image_1.png Image_2.png -compose src diff.png
代码:
差异后的输出不正确,因为比较是逐像素进行的,它不够智能,不能只标记真正的差异:
我提到的上述解决方案将工作以获得所需的差异作为输出,但没有库或图像魔术命令可用于此类图像比较。在
有没有任何python代码或Image magic命令可以执行此操作?
虽然您不希望逐点处理,但下面是一个使用Imagemagick的子图像搜索比较。它在剪掉黑色部分后填充一张图像,然后将较小的图像移动以找到与较大图像最匹配的位置。在
裁剪图像1:
裁剪和填充图像2:
^{pr2}$执行子图像搜索
现在移动并得到两个图像之间的差异
附加:
如果只想使用compare,那么需要在compare命令中添加-fuzz 15%:
生成两个图像。差异图像是第一个,所以请看diff-0.png
看起来你在做一些缺陷检测任务。我想到的第一个解决方案是图像配准技术。 首先尝试在相同的条件下拍摄图像(光线、相机角度和…)(您提供的图像之一大于2像素)。在
然后您应该注册两个图像,并将其中一个与另一个匹配,如下图所示
然后利用单应矩阵对其进行包裹,生成一个对齐的图像,在这种情况下,结果如下:
然后将对齐图像与查询图像的差值取阈值,得到:
正如我所说,如果你尝试更精确地拍摄你的帧,注册结果会更好,并导致更准确的性能。在
每个部分的代码:(主要取自here)。在
对于图像差异和阈值: alined=cv2.imread(“对齐.jpg“,0) alined=alined[:,:280]
^{pr2}$如果你有大量的图像,并想做缺陷检测任务,我建议使用去噪的自动编码器来训练一个深层的人工神经网络。阅读更多here。在
相关问题 更多 >
编程相关推荐