5#include "libmythbase/mythconfig.h"
7#ifndef __cpp_size_t_suffix
18#include "libavutil/imgutils.h"
31 const int TRUNCATION = 4;
32 const double sigma = 0.5;
33 const double TWO_SIGMA2 = 2 * sigma * sigma;
36 m_maskRadius = std::max(2, (
int)std::round(TRUNCATION * sigma));
40 m_mask =
new double[mask_width];
46 val = exp(-(rr * rr) / TWO_SIGMA2);
51 for (
int ii = 0; ii < mask_width; ii++)
57 av_freep(
reinterpret_cast<void*
>(&
m_edges.data[0]));
58 av_freep(
reinterpret_cast<void*
>(&
m_convolved.data[0]));
59 av_freep(
reinterpret_cast<void*
>(&
m_s2.data[0]));
60 av_freep(
reinterpret_cast<void*
>(&
m_s1.data[0]));
76 av_freep(
reinterpret_cast<void*
>(&
m_s1.data[0]));
77 av_freep(
reinterpret_cast<void*
>(&
m_s2.data[0]));
78 av_freep(
reinterpret_cast<void*
>(&
m_convolved.data[0]));
79 av_freep(
reinterpret_cast<void*
>(&
m_edges.data[0]));
86 const int padded_height = newheight + (2 *
m_maskRadius);
91 av_freep(
reinterpret_cast<void*
>(&
m_convolved.data[0]));
93 av_freep(
reinterpret_cast<void*
>(&
m_s2.data[0]));
95 av_freep(
reinterpret_cast<void*
>(&
m_s1.data[0]));
99 if (av_image_alloc(
m_s1.data,
m_s1.linesize,
100 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
102 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
103 "av_image_alloc s1 failed");
107 if (av_image_alloc(
m_s2.data,
m_s2.linesize,
108 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
110 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
111 "av_image_alloc s2 failed");
116 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
118 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
119 "av_image_alloc convolved failed");
124 newwidth, newheight, AV_PIX_FMT_GRAY8, IMAGE_ALIGN) < 0)
126 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
127 "av_image_alloc edges failed");
131#ifdef __cpp_size_t_suffix
132 m_sgm =
new unsigned int[1UZ * padded_width * padded_height];
133 m_sgmSorted =
new unsigned int[1UZ * newwidth * newheight];
135 m_sgm =
new unsigned int[1_UZ * padded_width * padded_height];
136 m_sgmSorted =
new unsigned int[1_UZ * newwidth * newheight];
167 const int pgmwidth = pgm->linesize[0];
168 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)
struct CannyEdgeDetector::@72 m_exclude
~CannyEdgeDetector(void) override
#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)