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
21extern "C" {
22#include "libavcodec/avcodec.h" /* AVFrame */
23}
24#include "FrameAnalyzer.h"
25
26using AVFrame = struct AVFrame;
27class PGMConverter;
28class EdgeDetector;
29class TemplateFinder;
30
32{
33public:
34 /* Ctor/dtor. */
35 TemplateMatcher(std::shared_ptr<PGMConverter> pgmc,
36 std::shared_ptr<EdgeDetector> ed, TemplateFinder *tf,
37 const QString& debugdir);
38 ~TemplateMatcher(void) override;
39
40 /* FrameAnalyzer interface. */
41 const char *name(void) const override // FrameAnalyzer
42 { return "TemplateMatcher"; }
44 long long nframes) override; // FrameAnalyzer
46 long long frameno, long long *pNextFrame) override; // FrameAnalyzer
47 int finished(long long nframes, bool final) override; // FrameAnalyzer
48 int reportTime(void) const override; // FrameAnalyzer
49 FrameMap GetMap(unsigned int /*index*/) const override // FrameAnalyzer
50 { return m_breakMap; }
51
52 /* TemplateMatcher interface. */
53 int templateCoverage(long long nframes, bool final) const;
54 const FrameAnalyzer::FrameMap *getBreaks(void) const { return &m_breakMap; }
55 int adjustForBlanks(const BlankFrameDetector *blankFrameDetector, long long nframes);
56 int computeBreaks(FrameMap *breaks);
57
58private:
59 std::shared_ptr<PGMConverter> m_pgmConverter {nullptr};
60 std::shared_ptr<EdgeDetector> m_edgeDetector {nullptr};
62 const struct AVFrame *m_tmpl {nullptr}; /* template image */
63 int m_tmplRow {-1}; /* template location */
64 int m_tmplCol {-1}; /* template location */
65 int m_tmplWidth {-1}; /* template dimensions */
66 int m_tmplHeight {-1}; /* template dimensions */
67
68 /* Per-frame info. */
69 unsigned short *m_matches {nullptr}; /* matching pixels */
70 unsigned char *m_match {nullptr}; /* boolean result: 1/0 */
71
72 float m_fps {0.0F};
73 AVFrame m_cropped {}; /* pre-allocated buffer */
74 FrameAnalyzer::FrameMap m_breakMap; /* frameno => nframes */
75
76 /* Debugging */
77 int m_debugLevel {0};
78 QString m_debugDir;
79 QString m_debugData; /* filename */
80 MythPlayer *m_player {nullptr};
81 bool m_debugMatches {false};
82 bool m_debugRemoveRunts {false};
83 bool m_matchesDone {false};
84 std::chrono::microseconds m_analyzeTime {0us};
85};
86
87#endif /* !TEMPLATEMATCHER_H */
88
89/* vim: set expandtab tabstop=4 shiftwidth=4: */
AVFrame AVFrame
QMap< long long, long long > FrameMap
Definition: FrameAnalyzer.h:45
const char * name(void) const override
std::chrono::microseconds m_analyzeTime
int reportTime(void) const override
int computeBreaks(FrameMap *breaks)
TemplateMatcher(std::shared_ptr< PGMConverter > pgmc, std::shared_ptr< EdgeDetector > ed, TemplateFinder *tf, const QString &debugdir)
enum analyzeFrameResult analyzeFrame(const MythVideoFrame *frame, long long frameno, long long *pNextFrame) override
const struct AVFrame * m_tmpl
unsigned char * m_match
unsigned short * m_matches
TemplateFinder * m_templateFinder
FrameMap GetMap(unsigned int) const override
FrameAnalyzer::FrameMap m_breakMap
int templateCoverage(long long nframes, bool final) const
std::shared_ptr< PGMConverter > m_pgmConverter
int adjustForBlanks(const BlankFrameDetector *blankFrameDetector, long long nframes)
std::shared_ptr< EdgeDetector > m_edgeDetector
const FrameAnalyzer::FrameMap * getBreaks(void) const
enum analyzeFrameResult MythPlayerInited(MythPlayer *player, long long nframes) override
MythPlayer * m_player
int finished(long long nframes, bool final) override
~TemplateMatcher(void) override
QMap< int, FrameList * > FrameMap
Definition: mpeg2fix.h:118