Fawkes API
Fawkes Development Version
segment.cpp
1
2
/***************************************************************************
3
* segment.cpp - Implementation of segmentation filter
4
* This filter can be used to draw the segmentation for a
5
* given object type to the Y-plane of the image
6
*
7
* Created: Mon Jun 27 11:37:57 2005
8
* Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
9
*
10
****************************************************************************/
11
12
/* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version. A runtime exception applies to
16
* this software (see LICENSE.GPL_WRE file mentioned below for details).
17
*
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU Library General Public License for more details.
22
*
23
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
24
*/
25
26
#include <fvfilters/segment.h>
27
#include <fvmodels/color/colormodel.h>
28
#include <fvutils/color/yuv.h>
29
30
#include <cstddef>
31
32
namespace
firevision {
33
34
/** @class FilterSegment <fvfilters/segment.h>
35
* Segmentation filter.
36
* Visually marks pixels of a given color and makes the segmentation visible.
37
* The pixels are marked with bright colors.
38
* @author Tim Niemueller
39
*/
40
41
/** Constructor.
42
* @param cm color model to use
43
* @param what what to mark
44
*/
45
FilterSegment::FilterSegment
(
ColorModel
*cm, color_t what) :
Filter
(
"FilterSegment"
)
46
{
47
this->cm = cm;
48
this->what = what;
49
}
50
51
void
52
FilterSegment::apply
()
53
{
54
unsigned
int
h = 0;
55
unsigned
int
w = 0;
56
57
// y-plane
58
unsigned
char
*yp =
src
[0] + (
src_roi
[0]->
start
.
y
*
src_roi
[0]->
line_step
)
59
+ (
src_roi
[0]->start.x *
src_roi
[0]->
pixel_step
);
60
// u-plane
61
unsigned
char
*up =
62
YUV422_PLANAR_U_PLANE(
src
[0],
src_roi
[0]->image_width,
src_roi
[0]->image_height)
63
+ ((
src_roi
[0]->
start
.
y
*
src_roi
[0]->
line_step
) / 2
64
+ (
src_roi
[0]->start.x *
src_roi
[0]->
pixel_step
) / 2);
65
// v-plane
66
unsigned
char
*vp =
67
YUV422_PLANAR_V_PLANE(
src
[0],
src_roi
[0]->image_width,
src_roi
[0]->image_height)
68
+ ((
src_roi
[0]->
start
.
y
*
src_roi
[0]->
line_step
) / 2
69
+ (
src_roi
[0]->start.x *
src_roi
[0]->
pixel_step
) / 2);
70
71
// destination y-plane
72
unsigned
char
*dyp =
73
dst
+ (
dst_roi
->
start
.
y
*
dst_roi
->
line_step
) + (
dst_roi
->
start
.
x
*
dst_roi
->
pixel_step
);
74
75
// line starts
76
unsigned
char
*lyp = yp;
// y-plane
77
unsigned
char
*lup = up;
// u-plane
78
unsigned
char
*lvp = vp;
// v-plane
79
unsigned
char
*ldyp = dyp;
// destination y-plane
80
81
for
(h = 0; (h <
src_roi
[0]->
height
) && (h < dst_roi->height); ++h) {
82
for
(w = 0; (w <
src_roi
[0]->
width
) && (w < dst_roi->width); w += 2) {
83
if
((cm->
determine
(*yp++, *up, *vp) == what)) {
84
*dyp++ = 255;
85
}
else
{
86
*dyp++ = 0;
87
}
88
if
((cm->
determine
(*yp++, *up++, *vp++) == what)) {
89
*dyp++ = 255;
90
}
else
{
91
*dyp++ = 0;
92
}
93
}
94
lyp +=
src_roi
[0]->
line_step
;
95
lup +=
src_roi
[0]->
line_step
/ 2;
96
lvp +=
src_roi
[0]->
line_step
/ 2;
97
ldyp +=
dst_roi
->
line_step
;
98
yp = lyp;
99
up = lup;
100
vp = lvp;
101
dyp = ldyp;
102
}
103
}
104
105
}
// end namespace firevision
firevision::ROI::width
unsigned int width
ROI width.
Definition:
roi.h:117
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition:
filter.h:61
firevision::FilterSegment::FilterSegment
FilterSegment(ColorModel *cm, color_t what)
Constructor.
Definition:
segment.cpp:45
firevision::ColorModel::determine
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.
firevision::ROI::height
unsigned int height
ROI height.
Definition:
roi.h:119
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition:
filter.h:66
firevision::ColorModel
Color model interface.
Definition:
colormodel.h:32
firevision::FilterSegment::apply
virtual void apply()
Apply the filter.
Definition:
segment.cpp:52
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition:
types.h:37
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition:
roi.h:127
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition:
filter.h:68
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition:
roi.h:115
firevision::ROI::line_step
unsigned int line_step
line step
Definition:
roi.h:125
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition:
types.h:36
firevision::Filter
Filter interface.
Definition:
filter.h:33
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition:
filter.h:63
src
libs
fvfilters
segment.cpp
Generated by
1.8.20