2

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

Community
  • 1
  • 1
Robert Jones
  • 587
  • 7
  • 25
  • I think the differences caused by JPEG encoding are doing you in and masking the differing content of the images. I differenced the images using ImageMagick and the result is awful... http://thesetchells.com/diff.jpg Can you obtain loss-less images such as PNG? – Mark Setchell Dec 18 '15 at 09:36
  • 1
    If I change my ImageMagick command to ignore up to 15% differences between pixels in the two images, like this... `compare f1.jpg f2.jpg -fuzz 15% -compose src -highlight-color red diff2.jpg` ... it improves to this... http://thesetchells.com/diff2.jpg – Mark Setchell Dec 18 '15 at 09:45
  • @MarkSetchell The original image is in PNG format but in order to upload the image on stackoverflow, I had to compress it as JPG because the size was > 2Mo. I added the original ones on my post – Robert Jones Dec 18 '15 at 10:32

1 Answers1

1

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

alexisrozhkov
  • 1,623
  • 12
  • 18
  • Yes this does the trick to have the whole differences. What I didn't specify here, is that I want to be able to capture every single differences and store them in Opencv Mat. This means I would like to detect one difference at the time and push it back in a Mat vector. The goal is to scan every single matrix individually looking for characters. – Robert Jones Dec 18 '15 at 10:44
  • 1
    Instead of asking questions incrementally it may be better to prepare one big question with all needed information. This way people won't have to search the information scattered around that is relevant to your real task. So, does that mean that you want to find inter-frame differences, find some clusters of changes, extract them and then feed to some OCR routine? – alexisrozhkov Dec 18 '15 at 10:48
  • Well that is actually what I wanted but then I've been told to create new posts each time I was asking another question associated to the main subject. I am not an expert with stackoverflow so I'm sorry for not doing things correctly here. To answer your question, what you said is exactly what I've been trying to do: find inter-frame differences, find some clusters of changes, extract them and then feed to some OCR routine. – Robert Jones Dec 18 '15 at 11:00
  • 1
    @DylanAlvaro if I'm the one who told you so, you misunderstood me. I told you to ask a new question, because you cannot ask something and then add new constraints/features in the same question, as this would invalidate current answers. You should post a complete question with exactly what you want to achieve and all needed info. As per this question, this post perfectly answers the question as stated now. Changing the requirements now would invalidate this question, and should be avoided. Bottom line: ask a new **complete** question – Miki Dec 18 '15 at 12:09
  • I understand what you mean, I just created a whole new complete post http://stackoverflow.com/questions/34356060/opencv-ocr-looking-for-characters-in-the-interframes-differences-of-a-video and I hope this one will be good. – Robert Jones Dec 18 '15 at 12:47