Opencv检测不同时间拍摄的两张照片之间的变化 [英] Opencv detect changes between two photos taken by different time

查看:2497
本文介绍了Opencv检测不同时间拍摄的两张照片之间的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个项目的原始图像/照片。 (即雕塑)。

We have one original image / photo of the item. (ie sculpture).

我们有时会拍摄该项目的新照片。照片始终与物品的角度相同90度。但是

Time to time we are taking new photos of the item. Photo always taken same angle 90 degree to the item. but


  • 会有一些略微向上/向左的向上移动会有
    是同一个对象的不同长度(我们是使用线
    相机拍摄并且物体在它前面移动所以时间到达
    的时间速度对象改变因此最终图像将比
    原始版本更长)

此外,灯光也会发生变化,所以颜色和闪电也不一样。
项目上会不时出现泥土,不同的小物件。

Also lighting changes so colour and lightning also not same always. Time to time there will be a mud, different small objects on the item.

我很乐意为您的建议和解决方案用opencv检测并标记新图片上对象的不同部分。

I would love to your suggestions and solutions to detect and mark the different part of the object on the new picture with opencv.

我们尝试了相似的但是它显示了由于颜色,长度等差异而改变的所有部分。但是对象是相同的

We tried resemblejs but it shows all parts changed due to colour, length etc differences. But object is same

Thx

代码:

from skimage.measure import compare_ssim
import argparse
import imutils
import cv2
import numpy as np


ap = argparse.ArgumentParser()
ap.add_argument("-f", "--first", required=True,
    help="first input image")
ap.add_argument("-s", "--second", required=True,
    help="second")
args = vars(ap.parse_args())

imageA = cv2.imread(args["first"])
imageB = cv2.imread(args["second"])

grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)


(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 55).astype("uint8")
print("SSIM: {}".format(score))

thresh = cv2.threshold(diff, 0, 255,
    cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]

for c in cnts:
    (x, y, w, h) = cv2.boundingRect(c)
    cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 2)
    cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 2)

cv2.imshow("Diff", diff)
cv2.waitKey(0)

编辑1

链接以测试图片

推荐答案

我想到了几种方法。


  1. 计算帧之间的差异。 OpenCV提供 absdiff 这样做。从那里 findContours 然后 绘制 他们。

  1. Calculate the difference between frames. OpenCV offers absdiff for doing just that. From there findContours of the resulting difference matrix then draw them.

这个教程使用 scikit-image

您还可以查看 meanStdDev 来完成此任务。计算两帧的标准差并检查它是否超过某个阈值。

You could also look into meanStdDev to accomplish this. Calculate the standard deviation of two frames and check to see if it passes a certain threshold.

这篇关于Opencv检测不同时间拍摄的两张照片之间的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆