MythTV  master
TemplateFinder.h
Go to the documentation of this file.
1 /*
2  * TemplateFinder
3  *
4  * Attempt to infer the existence of a static template across a series of
5  * images by looking for stable edges. Some ideas are taken from
6  * http://thomashargrove.com/logo-detection/
7  *
8  * By operating on the edges of images rather than the image data itself, both
9  * opaque and transparent templates are robustly located (if they exist).
10  * Hopefully the "core" portion of animated templates is sufficiently large and
11  * stable enough for animated templates to also be discovered.
12  *
13  * This TemplateFinder only expects to successfully discover non- or
14  * minimally-moving templates. Templates that change position during the
15  * sequence of images will cause this algorithm to fail.
16  */
17 
18 #ifndef __TEMPLATEFINDER_H__
19 #define __TEMPLATEFINDER_H__
20 
21 extern "C" {
22 #include "libavcodec/avcodec.h" /* AVFrame */
23 }
24 #include "FrameAnalyzer.h"
25 
26 class PGMConverter;
27 class BorderDetector;
28 class EdgeDetector;
29 
31 {
32 public:
33  /* Ctor/dtor. */
35  MythPlayer *player, int proglen, const QString& debugdir);
36  ~TemplateFinder(void);
37 
38  /* FrameAnalyzer interface. */
39  const char *name(void) const override // FrameAnalyzer
40  { return "TemplateFinder"; }
42  long long nframes) override; // FrameAnalyzer
43  enum analyzeFrameResult analyzeFrame(const VideoFrame *frame,
44  long long frameno, long long *pNextFrame) override; // FrameAnalyzer
45  int finished(long long nframes, bool final) override; // FrameAnalyzer
46  int reportTime(void) const override; // FrameAnalyzer
47  FrameMap GetMap(unsigned int) const override // FrameAnalyzer
48  { FrameMap map; return map; }
49 
50  /* TemplateFinder implementation. */
51  const struct AVFrame *getTemplate(int *prow, int *pcol,
52  int *pwidth, int *pheight) const;
53 
54 private:
55  int resetBuffers(int newwidth, int newheight);
56 
60 
61  unsigned int m_sampleTime {20 * 60}; /* amount of time to analyze */
62  int m_frameInterval; /* analyze every <Interval> frames */
63  long long m_endFrame {0}; /* end of logo detection */
64  long long m_nextFrame {0}; /* next desired frame */
65 
66  int m_width {-1}; /* dimensions of frames */
67  int m_height {-1}; /* dimensions of frames */
68  unsigned int *scores {nullptr}; /* pixel "edge" scores */
69 
70  int mincontentrow {INT_MAX}; /* limits of content area of images */
71  int mincontentcol {INT_MAX};
72  int maxcontentrow1 {INT_MAX}; /* minrow + height ("maxrow + 1") */
73  int maxcontentcol1 {INT_MAX}; /* mincol + width ("maxcol + 1") */
74 
75  AVFrame m_tmpl; /* logo-matching template */
76  int m_tmplrow {-1};
77  int m_tmplcol {-1};
78  int m_tmplwidth {-1};
79  int m_tmplheight {-1};
80 
81  AVFrame m_cropped; /* cropped version of frame */
82  int m_cwidth {-1}; /* cropped width */
83  int m_cheight {-1}; /* cropped height */
84 
85  /* Debugging. */
86  int m_debugLevel {0};
87  QString m_debugdir;
88  QString m_debugdata; /* filename: template location */
89  QString m_debugtmpl; /* filename: logo template */
90  bool m_debug_template {false};
91  bool m_debug_edgecounts {false};
92  bool m_debug_frames {false};
93  bool m_tmpl_valid {false};
94  bool m_tmpl_done {false};
95  struct timeval m_analyze_time;
96 };
97 
98 #endif /* !__TEMPLATEFINDER_H__ */
99 
100 /* vim: set expandtab tabstop=4 shiftwidth=4: */
const char * name(void) const override
QString m_debugtmpl
enum analyzeFrameResult analyzeFrame(const VideoFrame *frame, long long frameno, long long *pNextFrame) override
long long m_endFrame
struct AVFrame AVFrame
PGMConverter * m_pgmConverter
QString m_debugdata
int finished(long long nframes, bool final) override
TemplateFinder(PGMConverter *pgmc, BorderDetector *bd, EdgeDetector *ed, MythPlayer *player, int proglen, const QString &debugdir)
FrameMap GetMap(unsigned int) const override
int reportTime(void) const override
const struct AVFrame * getTemplate(int *prow, int *pcol, int *pwidth, int *pheight) const
enum analyzeFrameResult MythPlayerInited(MythPlayer *player, long long nframes) override
int resetBuffers(int newwidth, int newheight)
EdgeDetector * m_edgeDetector
BorderDetector * m_borderDetector
unsigned int m_sampleTime
struct timeval m_analyze_time
QString m_debugdir
QMap< long long, long long > FrameMap
Definition: FrameAnalyzer.h:44
long long m_nextFrame
unsigned int * scores