15#include "libavutil/imgutils.h"
28 const int TRUNCATION = 4;
29 const double sigma = 0.5;
30 const double TWO_SIGMA2 = 2 * sigma * sigma;
33 m_maskRadius = std::max(2, (
int)std::round(TRUNCATION * sigma));
37 m_mask =
new double[mask_width];
43 val = exp(-(rr * rr) / TWO_SIGMA2);
48 for (
int ii = 0; ii < mask_width; ii++)
54 av_freep(
reinterpret_cast<void*
>(&
m_edges.data[0]));
55 av_freep(
reinterpret_cast<void*
>(&
m_convolved.data[0]));
56 av_freep(
reinterpret_cast<void*
>(&
m_s2.data[0]));
57 av_freep(
reinterpret_cast<void*
>(&
m_s1.data[0]));
73 av_freep(
reinterpret_cast<void*
>(&
m_s1.data[0]));
74 av_freep(
reinterpret_cast<void*
>(&
m_s2.data[0]));
75 av_freep(
reinterpret_cast<void*
>(&
m_convolved.data[0]));
76 av_freep(
reinterpret_cast<void*
>(&
m_edges.data[0]));
83 const int padded_height = newheight + (2 *
m_maskRadius);
88 av_freep(
reinterpret_cast<void*
>(&
m_convolved.data[0]));
90 av_freep(
reinterpret_cast<void*
>(&
m_s2.data[0]));
92 av_freep(
reinterpret_cast<void*
>(&
m_s1.data[0]));
96 if (av_image_alloc(
m_s1.data,
m_s1.linesize,
97 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
99 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
100 "av_image_alloc s1 failed");
104 if (av_image_alloc(
m_s2.data,
m_s2.linesize,
105 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
107 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
108 "av_image_alloc s2 failed");
113 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
115 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
116 "av_image_alloc convolved failed");
121 newwidth, newheight, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
123 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
124 "av_image_alloc edges failed");
128 m_sgm =
new unsigned int[1_UZ * padded_width * padded_height];
129 m_sgmSorted =
new unsigned int[1_UZ * newwidth * newheight];
159 const int pgmwidth = pgm->linesize[0];
160 const int padded_height = pgmheight + (2 *
m_maskRadius);
int setExcludeArea(int row, int col, int width, int height) override
const AVFrame * detectEdges(const AVFrame *pgm, int pgmheight, int percentile) override
unsigned int * m_sgmSorted
int resetBuffers(int newwidth, int newheight)
~CannyEdgeDetector(void) override
struct CannyEdgeDetector::@76 m_exclude
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
int edge_mark_uniform_exclude(AVFrame *dst, int dstheight, int extramargin, const unsigned int *sgm, unsigned int *sgmsorted, int percentile, int excluderow, int excludecol, int excludewidth, int excludeheight)
unsigned int * sgm_init_exclude(unsigned int *sgm, const AVFrame *src, int srcheight, int excluderow, int excludecol, int excludewidth, int excludeheight)
int pgm_convolve_radial(AVFrame *dst, AVFrame *s1, AVFrame *s2, const AVFrame *src, int srcheight, const double *mask, int mask_radius)
static QString cleanup(const QString &str)