25 #include <fvfilters/morphology/segenerator.h> 27 #include <utils/math/angle.h> 29 #include <fvutils/draw/drawer.h> 30 #include <fvutils/color/colorspaces.h> 31 #include <fvutils/writers/png.h> 32 #include <fvutils/writers/fvraw.h> 61 unsigned int *proposed_center_x,
unsigned int *proposed_center_y,
62 float slope_angle_rad)
71 if ( height == 0 )
return NULL;
72 if ( width == 0)
return NULL;
75 unsigned char *tmp = (
unsigned char *)malloc(colorspace_buffer_size(YUV422_PLANAR, width, height));
76 memset(tmp, 0, colorspace_buffer_size(YUV422_PLANAR, width, height));
83 if ( (a == M_PI/2) || (a == -M_PI/2) ) {
90 if ( a > M_PI / 2) a -= M_PI;
91 if ( a < - M_PI / 2) a += M_PI;
93 int y = (int)roundf(((
float)width - 1.f) * tan( a ));
106 unsigned char *se = (
unsigned char *)malloc(width * height);
107 memcpy(se, tmp, width * height);
122 if ( (proposed_center_x != NULL) && (proposed_center_y != NULL) ) {
123 unsigned int min_x = width;
124 unsigned int max_x = 0;
125 unsigned int min_y = height;
126 unsigned int max_y = 0;
127 for (
unsigned int h = 0; h < height; ++h) {
128 for (
unsigned int w = 0; w < width; ++w) {
129 if ( se[ h * width + w ] != 0 ) {
130 if ( w < min_x ) min_x = w;
131 if ( w > max_x ) max_x = w;
132 if ( h < min_y ) min_y = h;
133 if ( h > max_y ) max_y = h;
138 *proposed_center_x = min_x + (max_x - min_x) / 2;
139 *proposed_center_y = min_y + (max_y - min_y) / 2;
155 unsigned char *se = (
unsigned char *)malloc(width * height);
156 memset(se, 1, width * height);
169 SEGenerator::drawSE(
unsigned char *yuv422planar_buffer,
unsigned char *mask,
unsigned int width,
unsigned int height)
171 memset(yuv422planar_buffer, 128, colorspace_buffer_size(YUV422_PLANAR, width, height) );
172 for (
unsigned int h = 0; h < height; ++h) {
173 for (
unsigned int w = 0; w < width; ++w) {
174 if ( mask[ h * width + w ] != 0 ) {
175 yuv422planar_buffer[ h * width + w ] = 255;
190 SEGenerator::drawSEbw(
unsigned char *yuv422planar_buffer,
unsigned char *mask,
unsigned int width,
unsigned int height)
192 memset(yuv422planar_buffer, 128, colorspace_buffer_size(YUV422_PLANAR, width, height) );
193 memset(yuv422planar_buffer, 255, width * height );
194 for (
unsigned int h = 0; h < height; ++h) {
195 for (
unsigned int w = 0; w < width; ++w) {
196 if ( mask[ h * width + w ] != 0 ) {
197 yuv422planar_buffer[ h * width + w ] = 0;
static void drawSE(unsigned char *yuv422planar_buffer, unsigned char *mask, unsigned int width, unsigned int height)
Draw structuring element.
virtual void write()
Write to file.
void draw_line(unsigned int x_start, unsigned int y_start, unsigned int x_end, unsigned int y_end)
Draw line.
static void drawSEbw(unsigned char *yuv422planar_buffer, unsigned char *mask, unsigned int width, unsigned int height)
Draw structuring element.
static unsigned char * square(unsigned int width, unsigned int height)
Generate square structuring element.
float normalize_mirror_rad(float angle_rad)
Normalize angle in radian between -PI (inclusive) and PI (exclusive).
FvRaw Writer implementation.
void set_buffer(unsigned char *buffer, unsigned int width, unsigned int height)
Set the buffer to draw to.
static unsigned char * linear(unsigned int width, unsigned int height, unsigned int *proposed_center_x, unsigned int *proposed_center_y, float slope_angle_rad)
Generate linear structuring element.
virtual void write()
Write to file.
virtual void set_filename(const char *filename)
Set filename.
virtual void set_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer.
virtual void set_dimensions(unsigned int width, unsigned int height)
Set dimensions of image in pixels.
void set_color(unsigned char y, unsigned char u, unsigned char v)
Set drawing color.