4

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

Prometheus
  • 105
  • 1
  • 2
  • 8

1 Answers1

4

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.

eshirima
  • 3,837
  • 5
  • 37
  • 61
  • Thanks for your help. Camera fixed anime camera. So same object has ways different length due to speed of object and different orientation small for x y axis and also z depth. What you suggest to than otherwise the tutorial you mentioned shows all changed in same object. Many thanks – Prometheus Jun 29 '17 at 15:08
  • Sorry but I didn't quite understand what you meant by _Camera fixed anime camera_ – eshirima Jun 29 '17 at 15:18
  • It's a android word corrections mistake. Sorry. I meant line scan camera. ☺ – Prometheus Jun 29 '17 at 15:42
  • Oh okay.. So just to clarify I understood your comment, you're saying that the same object can have different lengths? I understand the orientation but how can the same object have different lengths from one video frame to another? 2: Have you tried any of my suggested methods? They do cover orientation as well. Personally, I've used absdiff and even find Contours to track an object. Granted, they are very basic methods but they worked with orientation as well – eshirima Jun 29 '17 at 15:48
  • When the objects has a different speed than we have slightly changed lenght. How can I send you privately some sample images ? To give you better idea. – Prometheus Jun 29 '17 at 15:51
  • If images, just post them [here](http://imgur.com/). If its a folder of files, then I'd recommend you post them on [GDrive](https://www.google.com/drive/) or any cloud storage of your preference. For either options, you'll end up having to post the URL back here – eshirima Jun 29 '17 at 15:57
  • you can download from here : https://drive.google.com/drive/folders/0By_QG_ODrMu3aXJicXJmRGhPM0U?usp=sharing – Prometheus Jun 29 '17 at 16:31
  • What differences exactly am I looking at? Or what differences do you see in those images? – eshirima Jun 29 '17 at 17:06
  • One of them longer than the other and slightly more visible area. – Prometheus Jun 29 '17 at 17:43
  • Do you mind sharing your results on my suggested methods? – eshirima Jun 29 '17 at 18:08
  • Let me produce and share the images with you. Problema iş the scala and the visible part of the object. – Prometheus Jun 29 '17 at 18:23
  • results in the https://drive.google.com/drive/folders/0By_QG_ODrMu3aXJicXJmRGhPM0U?usp=sharing . archive-2 results. python code also in the same folder. – Prometheus Jun 29 '17 at 20:33
  • Hi I think main problem is to align the images . How I can align these type of images using homography ? basicly it seems to extract key points from source image and use it against to the destination image to get aligned image to use for calculating differences. ? Any help for sample code ? – Prometheus Jul 04 '17 at 10:31
  • You went with the feature extraction method? If I understand your question, you want to draw the source image keypoints onto the destination image correct? – eshirima Jul 04 '17 at 12:11
  • I succesfully aligned images (registered). now I have illimunation and color changes problem left – Rahibe Meryem Sep 08 '18 at 12:19