classifier.cpp

00001 
00002 /***************************************************************************
00003  *  classifier.cpp - Abstract class defining a classifier
00004  *
00005  *  Created: Mon Dec 10 11:35:36 2007
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <classifiers/classifier.h>
00025 #include <cstring>
00026 #include <cstdlib>
00027 
00028 namespace firevision {
00029 #if 0 /* just to make Emacs auto-indent happy */
00030 }
00031 #endif
00032 
00033 /** @class Classifier <classifiers/classifier.h>
00034  * Classifier to extract regions of interest.
00035  * The classifier finds regions of interest (ROI) by some a priori knowledge
00036  * like known colors or shapes. The list of ROIs returned by classify() _must_
00037  * be disjunct, meaning that no ROIs overlap each other.
00038  * Do appropriate merging or shrinking of the ROIs. See the ReallySimpleClassifier
00039  * for an example.
00040  * @author Tim Niemueller
00041  *
00042  * @fn std::list< ROI > * Classifier::classify() = 0
00043  * Classify image.
00044  * The current buffer is processed and scanned for the features the classifier
00045  * has been written and initialized for. It returns a list of disjunct regions
00046  * of interest.
00047  * @return disjunct list of extracted regions of interest
00048  */
00049 
00050 
00051 /** Constructor.
00052  * @param name classifier name
00053  */
00054 Classifier::Classifier(const char *name)
00055 {
00056   __name  = strdup(name);
00057   _src    = NULL;
00058   _width  = 0;
00059   _height = 0;
00060 }
00061 
00062 
00063 /** Destructor. */
00064 Classifier::~Classifier()
00065 {
00066   free(__name);
00067 }
00068 
00069 
00070 /** Set source buffer.
00071  * @param yuv422_planar a YUV422 planar buffer with the source image to
00072  * classify. The classifier may NOT modify the image in any way. If that is
00073  * required the classifier shall make a copy of the image.
00074  * @param width width of buffer in pixels
00075  * @param height height of buffer in pixels
00076  */
00077 void
00078 Classifier::set_src_buffer(unsigned char *yuv422_planar, unsigned int width,
00079                            unsigned int height)
00080 {
00081   _src    = yuv422_planar;
00082   _width  = width;
00083   _height = height;
00084 }
00085 
00086 
00087 /** Get name of classifier.
00088  * @return name of classifier.
00089  */
00090 const char *
00091 Classifier::name() const
00092 {
00093   return __name;
00094 }
00095 
00096 } // end namespace firevision