View Full Version : Help! - Logo detection.....
MrTibs
13th August 2003, 16:09
I'm trying to add logo detectio to my filter but can't seem to find an acurate way to detect if the logo is there. Does anyone have any ideas how I can do this?
E-Male
13th August 2003, 16:12
i tried something like this, but i had much too less experience
i don't think there is a way to detect logos without the use of much resources
the filter must compare many frames, and what it the same in all frames (with some threshold) is a logo
i hope for some better ideas from the more experienced programmers
Leuf
14th August 2003, 12:23
I know it seems cool for the filter to be able to do this itself, but the reality is that it only takes a few minutes to look in the capture and find the frame numbers. Whatever detection scheme you come up with is going to add more to the encoding time than it takes to do it manually (this may be a worthwhile tradeoff for many people though) But if there is movement in the frame under the logo when it is fading in or out, how are you ever going to get that detected?
Also the stations are very consistent with what time their logo comes in, it may not be the same for each commercial break, but say if you're capturing a series the next week it will be the same +/- 5 frames depending on where you made your commercial cut at each break point. So I find that I can set up a script that will work with only a few minutes tinkering each week. I suppose you could come up with some user defined presets to do this, but I don't see how that has any significant advantage.
The more important problem to deal with, imo, is properly handling a fadein/out of the logo, once you've got where it starts/ends determined either manually or automatically. This is something I never bothered with in x-logo, I just interpolate over it for the fade.
MrTibs
14th August 2003, 16:41
Thanks for your comments and suggestions!
Actually I tried to do what you suggested but the movie I recorded had something like 15 commercial breaks with the logo missing before and after the break for about 30 seconds. The trim command to deal with this became huge. It is likely that this is an extreme case but I figured that I take a crack at logo detection anyway. (fadein/out is about 6 frames)
My filter doesn't interpolate but rather tries to reverse the alpha-blending. An interesting side effect of my method is that when the logo is not present (or fades), over-correction appears. (i.e. the logo is black instead of white) Thus my logo detection method is actually trying to detect over-correction (i.e. a black logo) I don't care if the logo is there or not, I only care if you can see the over correction. So far I'm getting "OK" results but it isn't ready for release yet.
As for processing time, I agree that I should at least allow for it to be turned off. Lets face it, no matter what I come up with, it will fail at times and as you said, it will slow down the filter.
One more question: Does anyone know how to get the original frame number of a frame? (If I could detect where the commercials have been removed, I could allow for the time when the logo is missing.)
More suggestions and/or comments are welcome!
WarpEnterprises
16th August 2003, 22:42
What do you mean with the original frame number?
The number before Trim?
MrTibs
18th August 2003, 04:28
Yes, I ment the frame number before a trim command. For example, let say there is a commercial starting at frame 1000 and ending at frame 2000, after I trim out the commercial the actual frame numbers played through the avs script would be 998,999,2001,2002, ... Or course if I could somehow know the original frame numbers I would be able to detect trim statements and I would have a better way of checking for commerical breaks.
WarpEnterprises
18th August 2003, 08:01
No chance that way. The filter gets (or better fetches) independent frames.
The only way could be some watermarking by another filter done directly after the source, e.g. change some bits in the very first picture line.
(neuron2 uses that to communicate between 2 filters).
MrTibs
18th August 2003, 17:23
I was thinking that I may have to do the same thing. Could you tell me how neron2 does it? (What filter he does this with, so that I can look at the source...)
BTW, isn't there a text sting variable that I can write to to allow communication between filters?
WarpEnterprises
18th August 2003, 21:16
2) no, you can't change a variable at runtime
1) I think in decomb he does it, it's called something like "passing hints": he uses some least significant bits to mark that there is a hinting present and some more bits for the actual data.
I can't find the thread ATM but it's in the forum somewhere...
Kurosu
18th August 2003, 21:34
Well, variables declared in a script are evaluated during script parsing AFAIK. But can't env->GetVar() and env->AddVar() (or SetVar(), I don't recall) do that job? I do think that works.
See the discussion I had on this forum about such functions. The filter ScriptClip shows directly that a variable modified inside a filter is really changed in the environment. Only the reference to it as such (for instance subtitle(string(frames))), being evaluated before any frame is even requested, doesn't work.
However, you can't pass complex structures that way, only arrays at best (and I guess some problem could appear there).
WarpEnterprises
18th August 2003, 21:49
what is the scope (the range of validity) of the env pointer?
Is this defined e.g. the same for the whole script or only for the current plugin?
Since a plugin only "gets" a env-pointer, how can I be sure that it is the same for another plugin function?
If I understood right, ScriptClip calls the function in the SAME env that it modified, and that is (?) not the same as two different functions.
Si
18th August 2003, 22:40
@Mr Tibs
Checkout this (http://neuron2.net/ipw-web/bulletin/bb/viewtopic.php?t=37&highlight=hint) for some basic info.
I've added code to use it in my PFR filter using Donald#s Utilities.h/cpp files in his Decomb source
regards
Simon
Kurosu
18th August 2003, 23:29
Since a plugin only "gets" a env-pointer, how can I be sure that it is the same for another plugin function?
Right, but that's the point: it's a pointer, a smart way to actually pass the whole object and modify it; its scope really is a matter, but if it's as limited as you think it is, then the above functions are almost useless. I'm waiting for either Sh0dan, Bidoche or anybody that had time to check, to comment on this.
AFAIK, most common script languages work by copying environment and launching child processes with this copy, but allow those child processes to modify back the environment whenever it's explicitly invoked (and I hope it is the case here).
[edit]
btw, considering how avisynth works, the variable would only be modified for filters before the current filter modifying the variable (at frame n), or next filters when they are processing frame n+1.
Bidoche
19th August 2003, 01:12
@WarpEnterprises, Kurosu
There is one and only one env per script.
The rendering behavior is to create a new env, and invoke Import on it with the script.
That is the only point where envs are created.
And for your plugin issue, can you explain what you mean ? I don't follow you.
MrTibs
19th August 2003, 16:35
I admit I don't quite follow some of this so perhaps we could get a little specific so here is an example:
TemporalLumaGraph: I would like to create an array (string) of the luma values of a pixel over 250 frames. If I could modify an enviroment variable, I could use the string to keep the history of the pixel rather than calling up 250 frames each time.
On the other hand I could create a filter that returns a string rather than a frame and do this:
HistoryString=PixelLuma(clip,x,y,HistoryString)
Graph(clip,HistoryString)
But...a single filter would be best.
Bidoche
19th August 2003, 17:33
If I could modify an enviroment variable, I could use the string to keep the history of the pixel rather than calling up 250 frames each time.
And why should env be needed to save an history ?
Everybody can setup its own variables in its own filter for him to use, it's generally more efficient.
HistoryString=PixelLuma(clip,x,y,HistoryString)How can you pass as param a var which was not created yet ?
MrTibs
19th August 2003, 19:27
OK, would this work?
HistoryString=''
HistoryString=PixelLuma(clip,x,y,HistoryString)
Graph(clip,HistoryString)
As for history, I didn't think I could keep a variable active between frames...I'll have to investigate.
Bidoche
19th August 2003, 22:16
There is no reason you could not have variables in filters.
class MyFilter : public IClip {
map<int, value> history; //where value is the type of the data you want to keep for each frame
//....
virtual __stdcall PVideoFrame GetFrame(int n, IScriptEnvironment* env)
{
//get frame f
//get value v from f you want to save
history[n] = v;
return f;
}
//methods to read the history
//...
};
This work fine.
WarpEnterprises
20th August 2003, 07:14
MrTibs, only to make sure: do you want to code a filter in C or write a script that does the job?
MrTibs
20th August 2003, 16:37
Well, that is the question. I wish I knew Avisynth scripting much better. I think that script functions are preferred because they are easy to modify by anyone and thus can undergo faster/better development.
Now were would I get good tutorials for Avisynth scrpting?
BTW, I did manage to create a method to detect the presence of the logo. What I did was compare the logo edge locations of the logo template frame with the current frame. If I found edges on the current frame in the same locations -> the logo is present! This method seems to work pretty well but does fail when the logo is very hard to see. (i.e. a white logo on a nearly white background) In ref. to Leuf's concerns, the logo detection method is a separate filter that works like MaskMixed. (i.e. If logo is present, replace frame with cleaned frame)
Bidoche
20th August 2003, 18:57
Your history is something that has a sense at render.
Parsing takes place before it, so you can't have it in a variable.
MrTibs
22nd August 2003, 21:07
@Bidoche
I'm sorry, I don't understand your comment. Are you saying that if put inside a filter, the history string would maintain its value between frames or are you saying that my script suggestion wouldn't work? Forgive me, I am not a C++ developer.
Bidoche
23rd August 2003, 10:41
1st point: Why are you talking about an history string at all ?
Do you enjoy manipulating strings so much that you decided to maintain an history in this format.... I certainly don't.
2nd point: For the history to exist in the script, it will have to make a full render of the passed clip.
It is possible, but extremely unadvised to request frames at parse time...
I mean, I don't think you want to wait 30' or more for the script to start loading.
Are you saying that if put inside a filter,I suggest you put into a clip, not a filter. A filter is a function/command who returns clips.
The confusion seem to be widely made, but they are not the same thing.
the history string would maintain its value between framesClips go nowhere between frames requests, of course the history will stay.
or are you saying that my script suggestion wouldn't work?I say it can't work as you seem to think it will :
Apparently you want to use your string as a communication channel between clips, that is not possible.
Forgive me, I am not a C++ developer.Then I suggest you learn :p
MrTibs
2nd September 2003, 21:47
Thanks for your comments.
I am looking for a way to keep a history of the brightness of a pixel. I was trying to create a temporal version of my Lumagraph filter. (So that I could watch the value of a pixel change as movement occurs.) The idea of using a string was based on some reading I did somewhere that Avisynth has global string variables. (NO I don't "enjoy" working with stings.) My past attempts at creating a filter that plotted the history of a pixel failed because when I accessed the last frame to add to the existing graph, Avisynth would return an unmodifed version of the frame - thus no history. (i.e. calling the past frame seemed to return the original source frame not frame modified by the present filter.) All of this lead to this discussion.
As for learning C++: my comment was intended to give respect to those who have a great deal experience programming in C++ and who can truthfully call themselves C++ developers. (I am not so stupid to assume that I "know" C++ because my code compiled.) Avisynth (and C++)is a hobby and falls outside my first responsibility: to provide for my family. (I do something else for a living.) I realize that my questions may seem dumb but in my attempt to learn, I choose to look stupid and get answers rather than look smart(er) and be un-teachable.
Bidoche
2nd September 2003, 22:27
Well, my suggestion as a C++ developper (I do that for a living :p) was that :#include <map>
#using std::map;
class MyHistoryFilter : public IClip {
map<int, value> history; //where value is the type of the data you want to keep for each frame
//....
virtual __stdcall PVideoFrame GetFrame(int n, IScriptEnvironment* env)
{
//get frame f
//get value v from f you want to save
history[n] = v;
return f;
}
value GetValue(int n, IScriptEnvironment* env)
{
map<int, value>::iterator it = history.find(n);
if ( it != history.end() )
return *it;
//value is not cached
GetFrame(n, env); //just to update history
return history[n]
}
};And to call directly GetValue from the clip that draw the graph
If you don't understand that map thing, and I guess you don't (with 95% people here)you can learn about it here :
http://www.sgi.com/tech/stl/Map.html
Si
3rd September 2003, 19:43
OT I realize that my questions may seem dumb but in my attempt to learn, I choose to look stupid and get answers rather than look smart(er) and be un-teachable.
Excuse me , thats my patented approach - you'll be hearing from my solictor in the morning
;) ;) ;)
regards
Simon
Duck11
20th January 2006, 15:35
Add logo to video (http://geovid.com/VidLogo/)
Wilbert
10th February 2006, 10:58
@Duck11, nukacola
Stop spamming this board.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.