I am trying to detect a TV channel logo inside a video file, so simply given an input .mp4 video, detect if it has that logo present in all (or most) of frames or not (or maybe what percentage of frames include that logo). My aim is to classify ad and video portions (I noticed ads do not have the logo).

We have that logo in advance and the location is always fixed, so I believe the problem can be trivial to just a matching problem.

What is the best way to achieve this? Is there any tools or libraries that I can use for this?

enter image description here enter image description here


1 Answer 1


If you know where the logo is then you can detect its presence, fairly quickly, with cross-correlation...with a little bit more work.

Detecting the presence of "things" using cross-correlation is a way to do template matching, where we are trying to find a specific pattern in a longer "duration" signal.

In this case, the logo is the pattern and the longer "duration" (or surface in the case of an image) is the whole frame.

The question now becomes, how do you recover the pattern? How do you recover the logo, so that you can then search for that particular target?

There are two ways to do this:

  1. It is already available: In which case, you just download a copy of the logo, resize it to the approximate size you expect the logo to be in the frame and then use cross-correlation to find it.

  2. It is not available and it has to be recovered by the frame itself: To recover the logo, use averaging. Take a large number of frames (say 30-50 seconds of video), and average their pixel values. The key idea here is that the logo does not "move" from its position. Therefore, the pixels that correspond to the logo will have a stable value while the pixels that correspond to the background will be taking "random" values from whatever the camera happens to pan to. When you average, the stable values will retain their magnitude and the random values will have considerable lower values. The reason I am telling you to average such a long duration is because the second image is showing a frame from a talk-show. In that one, the camera, the subject or its background are not expected to move too much, therefore, it is likely that if you average for a short duration you might "pick up" a bit of the background too. In that case, you might have to recover the logo from a different part of the video. The bottom line is that this process will give you the form of the logo. You might have to apply thresholding to get rid of those "background" pixels to get a proper "mask" image.

Once you have that small "logo" image, you can then pick up a random frame from your video feed, crop it around the approximate location of the logo and then take that part of the frame and cross-correlate it with the logo. If the logo IS present in the frame, you will get a much stronger cross-correlation peak at its approximate centre than if the logo is not present. You can then apply a threshold to detect this strong peak. If the peak is above that threshold then the logo is present, if not, then the logo is not present. That's the concept and different platforms will have different implementations (e.g. here is the same thing in Python).

Hope this helps.

  • $\begingroup$ Thanks for your description. Yes, I have the logo simply cropping from LAFF screenshot above. That python code looks promising. I'm new to python, is there ready-to-run code for that? $\endgroup$
    – Tina J
    Commented Dec 6, 2017 at 16:34
  • $\begingroup$ Glad you found it useful, you can accept the question as "answered" via the check-mark on the left too. This will stop it from being re-circulated as unanswered. As far as code is concerned, I do not know. I have not searched for something like this before but I would be surprised if someone had not done something like this. This way of finding "patches" by cross correlation is a fairly standard technique. $\endgroup$
    – A_A
    Commented Dec 6, 2017 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.