MythTV  master
TemplateMatcher.h
Go to the documentation of this file.
1 /*
2  * TemplateMatcher
3  *
4  * Decide whether or not an image matches a given template.
5  *
6  * This TemplateMatcher is tuned to yield very few false positives, at the cost
7  * of slightly more false negatives.
8  *
9  * After all images are analyzed, attempt to remove the mis-categorized images
10  * based on inter-image information (e.g., minimum sequence lengths of template
11  * matching or non-matching).
12  *
13  * This TemplateMatcher only expects to successfully match templates in a fixed
14  * location. It would be trivial to add code to search the entire frame for a
15  * template known to change locations, but at a very large cost of time.
16  */
17 
18 #ifndef __TEMPLATEMATCHER_H__
19 #define __TEMPLATEMATCHER_H__
20 
21 extern "C" {
22 #include "libavcodec/avcodec.h" /* AVFrame */
23 }
24 #include "FrameAnalyzer.h"
25 
26 typedef struct AVFrame AVFrame;
27 class PGMConverter;
28 class EdgeDetector;
29 class TemplateFinder;
30 
32 {
33 public:
34  /* Ctor/dtor. */
36  const QString& debugdir);
37  ~TemplateMatcher(void);
38 
39  /* FrameAnalyzer interface. */
40  const char *name(void) const override // FrameAnalyzer
41  { return "TemplateMatcher"; }
43  long long nframes) override; // FrameAnalyzer
44  enum analyzeFrameResult analyzeFrame(const VideoFrame *frame,
45  long long frameno, long long *pNextFrame) override; // FrameAnalyzer
46  int finished(long long nframes, bool final) override; // FrameAnalyzer
47  int reportTime(void) const override; // FrameAnalyzer
48  FrameMap GetMap(unsigned int) const override // FrameAnalyzer
49  { return m_breakMap; }
50 
51  /* TemplateMatcher interface. */
52  int templateCoverage(long long nframes, bool final) const;
53  const FrameAnalyzer::FrameMap *getBreaks(void) const { return &m_breakMap; }
54  int adjustForBlanks(const BlankFrameDetector *blankFrameDetector, long long nframes);
55  int computeBreaks(FrameMap *breaks);
56 
57 private:
61  const struct AVFrame *m_tmpl {nullptr}; /* template image */
62  int m_tmplrow {-1}; /* template location */
63  int m_tmplcol {-1}; /* template location */
64  int m_tmplwidth {-1}; /* template dimensions */
65  int m_tmplheight {-1}; /* template dimensions */
66 
67  /* Per-frame info. */
68  unsigned short *m_matches {nullptr}; /* matching pixels */
69  unsigned char *m_match {nullptr}; /* boolean result: 1/0 */
70 
71  float m_fps {0.0F};
72  AVFrame m_cropped {}; /* pre-allocated buffer */
73  FrameAnalyzer::FrameMap m_breakMap; /* frameno => nframes */
74 
75  /* Debugging */
76  int m_debugLevel {0};
77  QString m_debugdir;
78  QString m_debugdata; /* filename */
79  MythPlayer *m_player {nullptr};
80  bool m_debug_matches {false};
81  bool m_debug_removerunts {false};
82  bool m_matches_done {false};
83  struct timeval m_analyze_time {0,0};
84 };
85 
86 #endif /* !__TEMPLATEMATCHER_H__ */
87 
88 /* vim: set expandtab tabstop=4 shiftwidth=4: */
89 
FrameAnalyzer::FrameMap m_breakMap
int reportTime(void) const override
struct AVFrame AVFrame
unsigned short * m_matches
FrameMap GetMap(unsigned int) const override
enum analyzeFrameResult analyzeFrame(const VideoFrame *frame, long long frameno, long long *pNextFrame) override
int adjustForBlanks(const BlankFrameDetector *blankFrameDetector, long long nframes)
enum analyzeFrameResult MythPlayerInited(MythPlayer *player, long long nframes) override
PGMConverter * m_pgmConverter
const FrameAnalyzer::FrameMap * getBreaks(void) const
const struct AVFrame * m_tmpl
TemplateFinder * m_templateFinder
int computeBreaks(FrameMap *breaks)
unsigned char * m_match
QMap< int, FrameList * > FrameMap
Definition: mpeg2fix.h:115
EdgeDetector * m_edgeDetector
int templateCoverage(long long nframes, bool final) const
TemplateMatcher(PGMConverter *pgmc, EdgeDetector *ed, TemplateFinder *tf, const QString &debugdir)
const char * name(void) const override
MythPlayer * m_player
int finished(long long nframes, bool final) override
QMap< long long, long long > FrameMap
Definition: FrameAnalyzer.h:44