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) override;
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 /*index*/) 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 *m_scores {nullptr}; /* pixel "edge" scores */
69 
70  int m_minContentRow {INT_MAX}; /* limits of content area of images */
71  int m_minContentCol {INT_MAX};
72  int m_maxContentRow1 {INT_MAX}; /* minrow + height ("maxrow + 1") */
73  int m_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_debugTemplate {false};
91  bool m_debugEdgeCounts {false};
92  bool m_debugFrames {false};
93  bool m_tmplValid {false};
94  bool m_tmplDone {false};
95  struct timeval m_analyzeTime {0,0};
96 };
97 
98 #endif /* !__TEMPLATEFINDER_H__ */
99 
100 /* vim: set expandtab tabstop=4 shiftwidth=4: */
const char * name(void) const override
enum analyzeFrameResult analyzeFrame(const VideoFrame *frame, long long frameno, long long *pNextFrame) override
long long m_endFrame
PGMConverter * m_pgmConverter
struct AVFrame AVFrame
int finished(long long nframes, bool final) override
~TemplateFinder(void) 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
unsigned int * m_scores
enum analyzeFrameResult MythPlayerInited(MythPlayer *player, long long nframes) override
int resetBuffers(int newwidth, int newheight)
EdgeDetector * m_edgeDetector
BorderDetector * m_borderDetector
QMap< long long, long long > FrameMap
Definition: FrameAnalyzer.h:43
unsigned int m_sampleTime
QString m_debugTmpl
QString m_debugDir
QString m_debugData
long long m_nextFrame