比较两个不同的图像并找出差异
我有一个网络摄像头,可以拍摄混凝土板的照片。现在我想检查平板上是否有物体。对象可以是任何东西,因此不能在类中枚举。不幸的是,我无法直接将网络摄像头图像与混凝土板上没有物体的图像进行比较,因为相机的图像在 x 和 y 方向上的移动可能很小,而且照明也不总是相同。所以我不能使用cv2.substract
。 我更喜欢前景和背景减法,其中背景只是我的混凝土板,前景是物体。但由于对象不会移动而是静止在平板上,因此我也无法使用 cv2.createBackgroundSubtractorMOG2() 。
图片如下所示:
没有任何物体的混凝土拍打:
与对象的耳光:
I have a webcam which takes pictures of a concrete slab. Now I want to check if there are objects on the slab or not. The objects could be anything and accordingly cannot be enumerated in a class. Unfortunately I cannot compare the webcam image directly with an image without objects on the concrete slab, because the image of the camera could shift minimally in x and y direction and the lighting is also not always the same. So I cannot use cv2.substract
.
I would prefer a foreground and background substract, where the background is just my concrete slab and the foreground is then the objects. But since the objects don´t move but lie still on the slab, I can´t use cv2.createBackgroundSubtractorMOG2()
either.
The Pictures look like this:
The Concrete slap without any objects:
The slap with Objects:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Python/OpenCV 中,您可以进行除法归一化以使照明均匀并使背景变白。然后做减法。然后使用形态学来清理小区域。然后找到轮廓并丢弃由于除法归一化和形态学之后留下的噪声造成的任何小区域。
以下是如何进行除法标准化。
输入 1:
输入 2:
图像 1 标准化:
图像 2 标准化:
对图像 1 进行阈值处理和形态学清理:
对图像 2 进行阈值处理和形态学清理:
在本例中,图像1 变成全白。所以它(和减法)并不是真正需要的。您只需要找到第二个图像结果的轮廓,并在必要时按面积丢弃微小区域。其余的都是你的对象。
In Python/OpenCV, you could do division normalization to even out the illumination and make the background white. Then do your subtraction. Then use morphology to clean up small regions. Then find contours and discard any small regions that are due to noise left after the division normalization and morphology.
Here is how to do division normalization.
Input 1:
Input 2:
Image 1 Normalized:
Image 2 Normalized:
Image 1 thresholded and morphology cleaned:
Image 2 thresholded and morphology cleaned:
In this case, Image 1 becomes completely white. So it (and subtraction) is not really needed. You just need to find contours for the second image result and if necessary discard tiny regions by area. The rest are your objects.