Robert Jones
Robert Jones

Reputation: 597

OpenCV: Getting precise differences between two frames with little changes

According to this post OCR & OpenCV: Difference between two frames on high resolution images, I am now able to correctly detect differences between two frames of a video with OpenCV.

I'm now trying to tune this algorithm with different data. Typically on the three following pictures I only get the green lines as differences and not the text at all (which is what is the most interesting). I'm trying to understand better how things work for this.

1st image:

TestImg1

2nd image:

TestImg2

3rd image: ResultImg

As you can see I only have those green lines and never the text (at the best I can have just ONE letter when decreasing the countours[i].size() from the algorithm on the quoted post)

Original PNG images : 1st image 2nd image

Upvotes: 2

Views: 2680

Answers (1)

alexisrozhkov
alexisrozhkov

Reputation: 1632

If you are using code from the answer to your linked question - this is quite expected. The answerer advices you to remove noise, find contours and extract area in the convex hull of the closed contour. But most of your differences, which are small and thin, will be removed after this kind of filtering.

Try doing a simple subtraction of your input images - it will likely be better. If not - post result here and we will try to improve it.

Edit:

This simple code seems to do the job:

#include <opencv2/opencv.hpp>

using namespace cv;

int main() {
  Mat a = imread("a.jpg");
  Mat b = imread("b.jpg");

  Mat diff;
  absdiff(a, b, diff);      

  imwrite("c.jpg", diff);
  imshow("diff", diff);

  waitKey();

  return 0;
}

Result: enter image description here

Upvotes: 1

Related Questions