ProcessingChain.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, LABUST, UNIZG-FER
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the LABUST nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 #ifndef PROCESSINGCHAIN_HPP_
00035 #define PROCESSINGCHAIN_HPP_
00036 #include <labust/blueview/trackerfwd.hpp>
00037 #include <labust/blueview/CConverter.hpp>
00038 #include <labust/blueview/PrefilterPolicy.hpp>
00039 #include <labust/blueview/ThresholdPolicy.hpp>
00040 #include <labust/blueview/LabelPolicy.hpp>
00041 #include <labust/blueview/AssociatePolicy.hpp>
00042 #include <labust/blueview/TrackerROI.hpp>
00043 
00044 #include <opencv2/highgui/highgui.hpp>
00045 
00046 namespace labust
00047 {
00048         namespace blueview
00049         {
00054                 template<
00055                         class Prefilter = SimpleAdjust,
00056                         class Threshold = SimpleThreshold,
00057                         class Label = SimpleLabel,
00058                         class Associate = DirectAssociate>
00059                 class ProcessingChain
00060                 {
00061                 public:
00065                         ProcessingChain():
00066                         tracklet(new TrackedFeature),
00067                         hasTarget(false),
00068                         foundVehicle(false){};
00069 
00074                         TrackedFeaturePtr processROI(const TrackerROI& roi)
00075                         {
00076                                 if (true)
00077                                 {
00078                                         //Calculation of the new position
00079                                   //Tracklet position update, calculate new x,y,z based on last known positiom
00080                                         this->ccon.llz2xy(roi.headData,this->tracklet);
00081                                         CConverter::meter2pixel(roi,this->tracklet);
00082                                         //Do the same conversion to the target
00083                                         if (this->hasTarget)
00084                             {
00085                               this->ccon.llz2xy(roi.headData,target);
00086                               CConverter::meter2pixel(roi,target);
00087                             }
00088 
00089                             cv::Mat disp = roi.roi.clone();
00090                             cv::circle(disp,this->tracklet->pposition,10,cv::Scalar(65536));
00091                             cv::imshow("Expected",disp*500);
00092 
00093                             //From here things are the similar to the old version
00094                             //Calculate the pixel region (3x3) meters
00095                             MatPtr roiImg(new cv::Mat(roi.roi));
00096                             //Do adjustment
00097                             MatPtr prefiltered = Prefilter::prefilter(roiImg);
00098                             MatPtr binary = Threshold::threshold(prefiltered,0.65);
00099                             TrackedFeatureVecPtr features = Label::label(binary);
00100 
00101                             this->foundVehicle = Associate::associate(features, roi.headData, tracklet.get(), target.get());
00102 
00103                             cv::imshow("Adjusted",*prefiltered);
00104                             cv::imshow("Binary",*binary);
00105 
00106                             CConverter::pixel2meter(roi,tracklet);
00107                             this->ccon.xy2llz(roi.headData,tracklet);
00108 
00109                             return TrackedFeaturePtr(new TrackedFeature(*tracklet));
00110                           }
00111 
00112                                 return TrackedFeaturePtr();
00113                         }
00114 
00115                         inline bool isTracking(){return foundVehicle;};
00116 
00117                         void setPosition(const SonarHead& cnt)
00118                         {
00119                           tracklet->position.x = cnt.range*cos((cnt.bearing - cnt.panAngle)*M_PI/180);
00120                           tracklet->position.y = cnt.range*sin((cnt.bearing - cnt.panAngle)*M_PI/180);
00121                           this->ccon.xy2llz(cnt,tracklet);
00122                           foundVehicle = true;
00123                         }
00124 
00125                 private:
00129                         CConverter ccon;
00133                         TrackedFeaturePtr tracklet, target;
00137                         bool hasTarget, foundVehicle;
00138                 };
00139         }
00140 }
00141 
00142 /* PROCESSINGCHAIN_HPP_ */
00143 #endif


target_detector
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:36:05