Opencv detect changes between two photos taken by different time

时光总嘲笑我的痴心妄想 提交于 2019-12-05 02:54:31

问题


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

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

  • there will be some slightly movement up down / left right there will be different length of the same object ( we are taking with line camera and the object moving in front of it so time to time speed of the object changing so the final image will be longer than the original)

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.

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

code :

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)

Edit 1

Link to test images


回答1:


A couple methods come to mind.

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

  2. This tutorial uses scikit-image for image differences

  3. 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.



来源:https://stackoverflow.com/questions/44785958/opencv-detect-changes-between-two-photos-taken-by-different-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!