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)roundf(TRUNCATION * sigma));
34 int mask_width = 2 * m_maskRadius + 1;
37 m_mask =
new double[mask_width];
39 m_mask[m_maskRadius] = val;
41 for (
int rr = 1; rr <= m_maskRadius; rr++)
43 val = exp(-(rr * rr) / TWO_SIGMA2);
44 m_mask[m_maskRadius + rr] = val;
45 m_mask[m_maskRadius - rr] = val;
48 for (
int ii = 0; ii < mask_width; ii++)
54 av_freep(&m_edges.data[0]);
55 av_freep(&m_convolved.data[0]);
56 av_freep(&m_s2.data[0]);
57 av_freep(&m_s1.data[0]);
66 if (m_ewidth == newwidth && m_eheight == newheight)
74 av_freep(&m_s1.data[0]);
75 av_freep(&m_s2.data[0]);
76 av_freep(&m_convolved.data[0]);
77 av_freep(&m_edges.data[0]);
83 const int padded_width = newwidth + 2 * m_maskRadius;
84 const int padded_height = newheight + 2 * m_maskRadius;
86 if (av_image_alloc(m_s1.data, m_s1.linesize,
87 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN))
89 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
90 "av_image_alloc s1 failed");
94 if (av_image_alloc(m_s2.data, m_s2.linesize,
95 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN))
97 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
98 "av_image_alloc s2 failed");
102 if (av_image_alloc(m_convolved.data, m_convolved.linesize,
103 padded_width, padded_height, AV_PIX_FMT_GRAY8, IMAGE_ALIGN))
105 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
106 "av_image_alloc convolved failed");
110 if (av_image_alloc(m_edges.data, m_edges.linesize,
111 newwidth, newheight, AV_PIX_FMT_GRAY8, IMAGE_ALIGN))
113 LOG(VB_COMMFLAG, LOG_ERR,
"CannyEdgeDetector::resetBuffers "
114 "av_image_alloc edges failed");
118 m_sgm =
new unsigned int[1_UZ * padded_width * padded_height];
119 m_sgmSorted =
new unsigned int[1_UZ * newwidth * newheight];
122 m_eheight = newheight;
127 av_freep(&m_convolved.data[0]);
129 av_freep(&m_s2.data[0]);
131 av_freep(&m_s1.data[0]);
140 m_exclude.width = width;
141 m_exclude.height = height;
156 const int pgmwidth = pgm->linesize[0];
157 const int padded_height = pgmheight + 2 * m_maskRadius;
159 if (resetBuffers(pgmwidth, pgmheight))
163 m_mask, m_maskRadius))
168 m_exclude.row + m_maskRadius, m_exclude.col + m_maskRadius,
169 m_exclude.width, m_exclude.height),
170 m_sgmSorted, percentile,
171 m_exclude.row, m_exclude.col, m_exclude.width, m_exclude.height))