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 <fvmodels/color/colormodel.h>
27 #include <fvfilters/segment.h>
28 
29 #include <fvutils/color/yuv.h>
30 #include <cstddef>
31 
32 namespace firevision {
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
37 /** @class FilterSegment <fvfilters/segment.h>
38  * Segmentation filter.
39  * Visually marks pixels of a given color and makes the segmentation visible.
40  * The pixels are marked with bright colors.
41  * @author Tim Niemueller
42  */
43 
44 /** Constructor.
45  * @param cm color model to use
46  * @param what what to mark
47  */
49  : Filter("FilterSegment")
50 {
51  this->cm = cm;
52  this->what = what;
53 }
54 
55 
56 void
58 {
59  register unsigned int h = 0;
60  register unsigned int w = 0;
61 
62  // y-plane
63  register unsigned char *yp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
64  // u-plane
65  register unsigned char *up = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
66  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
67  // v-plane
68  register unsigned char *vp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
69  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
70 
71  // destination y-plane
72  register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
73 
74  // line starts
75  unsigned char *lyp = yp; // y-plane
76  unsigned char *lup = up; // u-plane
77  unsigned char *lvp = vp; // v-plane
78  unsigned char *ldyp = dyp; // destination y-plane
79 
80  for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
81  for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) {
82  if ( (cm->determine(*yp++, *up, *vp) == what) ) {
83  *dyp++ = 255;
84  } else {
85  *dyp++ = 0;
86  }
87  if ( (cm->determine(*yp++, *up++, *vp++) == what) ) {
88  *dyp++ = 255;
89  } else {
90  *dyp++ = 0;
91  }
92  }
93  lyp += src_roi[0]->line_step;
94  lup += src_roi[0]->line_step / 2;
95  lvp += src_roi[0]->line_step / 2;
96  ldyp += dst_roi->line_step;
97  yp = lyp;
98  up = lup;
99  vp = lvp;
100  dyp = ldyp;
101  }
102 
103 }
104 
105 } // end namespace firevision
Color model interface.
Definition: colormodel.h:34
fawkes::upoint_t start
ROI start.
Definition: roi.h:119
unsigned int y
y coordinate
Definition: types.h:36
unsigned int x
x coordinate
Definition: types.h:35
unsigned int width
ROI width.
Definition: roi.h:121
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
Filter interface.
Definition: filter.h:35
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
FilterSegment(ColorModel *cm, color_t what)
Constructor.
Definition: segment.cpp:48
virtual void apply()
Apply the filter.
Definition: segment.cpp:57
unsigned int height
ROI height.
Definition: roi.h:123
unsigned int line_step
line step
Definition: roi.h:129
unsigned char * dst
Destination buffer.
Definition: filter.h:67
unsigned int pixel_step
pixel step
Definition: roi.h:131
ROI * dst_roi
Destination ROI.
Definition: filter.h:72
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.