JeVoisBase  1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
BlobDetector.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2018 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
21 #include <opencv2/core/core.hpp>
22 
23 // This code was loosely inspired by:
24 
25 // https://raw.githubusercontent.com/kylehounslow/opencv-tuts/master/object-tracking-tut/objectTrackingTut.cpp
26 
27 // Written by Kyle Hounslow 2013
28 
29 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
30 // documentation files (the "Software") , to deal in the Software without restriction, including without limitation the
31 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
32 // permit persons to whom the Software is furnished to do so, subject to the following conditions:
33 //
34 // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
35 // Software.
36 //
37 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
38 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
39 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
40 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 
42 namespace blobdetector
43 {
44  static jevois::ParameterCategory const ParamCateg("BlobDetector Options");
45 
46  //! Parameter \relates ObjectTracker
47  JEVOIS_DECLARE_PARAMETER(hrange, jevois::Range<unsigned char>, "Range of H values for HSV window (0=red/do not "
48  "use because of wraparound, 30=yellow, 45=light green, 60=green, 75=green cyan, 90=cyan, "
49  "105=light blue, 120=blue, 135=purple, 150=pink)",
50  jevois::Range<unsigned char>(10, 245), ParamCateg);
51 
52  //! Parameter \relates ObjectTracker
53  JEVOIS_DECLARE_PARAMETER(srange, jevois::Range<unsigned char>, "Range of S (saturation) values for HSV window",
54  jevois::Range<unsigned char>(10, 245), ParamCateg);
55 
56  //! Parameter \relates ObjectTracker
57  JEVOIS_DECLARE_PARAMETER(vrange, jevois::Range<unsigned char>, "Range of V (brightness) values for HSV window",
58  jevois::Range<unsigned char>(10, 245), ParamCateg);
59 
60  //! Parameter \relates ObjectTracker
61  JEVOIS_DECLARE_PARAMETER(maxnumobj, size_t, "Max number of objects to declare a clean image",
62  10, ParamCateg);
63 
64  //! Parameter \relates ObjectTracker
65  JEVOIS_DECLARE_PARAMETER(objectarea, jevois::Range<unsigned int>, "Range of object area (in pixels) to track",
66  jevois::Range<unsigned int>(20*20, 100*100), ParamCateg);
67 
68  //! Parameter \relates ObjectTracker
69  JEVOIS_DECLARE_PARAMETER(erodesize, size_t, "Erosion structuring element size (pixels)",
70  3, ParamCateg);
71 
72  //! Parameter \relates ObjectTracker
73  JEVOIS_DECLARE_PARAMETER(dilatesize, size_t, "Dilation structuring element size (pixels)",
74  8, ParamCateg);
75 }
76 
77 
78 
79 //! Simple color-based object/blob detection/tracking
80 /*! This component isolates pixels within a given HSV range (hue, saturation, and value of color pixels), does some
81  cleanups, and extracts object contours. It sends information about object centers over serial.
82 
83  This algorithm usually works best with the camera sensor set to manual exposure, manual gain, manual color balance,
84  etc so that HSV color values are reliable.
85 
86  This code was loosely inspired by:
87  https://raw.githubusercontent.com/kylehounslow/opencv-tuts/master/object-tracking-tut/objectTrackingTut.cpp written
88  by Kyle Hounslow, 2013.
89 
90  For more information, see \jvmod{ObjectTracker}
91 
92  \ingroup components */
94  public jevois::Parameter<blobdetector::hrange, blobdetector::srange, blobdetector::vrange,
95  blobdetector::maxnumobj, blobdetector::objectarea,
96  blobdetector::erodesize, blobdetector::dilatesize>
97 {
98  public:
99 
100  //! Constructor
102 
103  //! Virtual destructor for safe inheritance
104  virtual ~BlobDetector();
105 
106  //! Detect blobs, each is represented as a contour (vector of (x,y) coordinates)
107  std::vector<std::vector<cv::Point> > detect(cv::Mat const & imghsv);
108 };
jevois::ParameterRegistry::Component
friend friend class Component
jevois::Range
BlobDetector::detect
std::vector< std::vector< cv::Point > > detect(cv::Mat const &imghsv)
Detect blobs, each is represented as a contour (vector of (x,y) coordinates)
Definition: BlobDetector.C:29
BlobDetector::~BlobDetector
virtual ~BlobDetector()
Virtual destructor for safe inheritance.
Definition: BlobDetector.C:25
JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg)
jevois::Component
jevois::ParameterCategory
Component.H
blobdetector
Definition: BlobDetector.H:42
BlobDetector
Simple color-based object/blob detection/tracking.
Definition: BlobDetector.H:93