My Project
ConnectedComponents.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef CONNECTEDCOMPONENTS_H
25 #define CONNECTEDCOMPONENTS_H
26 
33 #include "Alvar.h"
34 #include "Camera.h"
35 #include "Line.h"
36 #include "Util.h"
37 
38 namespace alvar {
39 
43 enum ALVAR_EXPORT LabelingMethod { CVSEQ };
44 
48 class ALVAR_EXPORT Labeling
49 {
50 protected:
51  Camera *cam;
52  int thresh_param1, thresh_param2;
53 
54 public:
58  cv::Mat gray;
62  cv::Mat bw;
63 
67  std::vector<std::vector<PointDouble>> blob_corners;
68 
72  enum ThresholdMethod { THRESH, ADAPT };
73 
76 
79 
83  void
84  SetCamera(Camera *camera)
85  {
86  cam = camera;
87  }
88 
92  virtual void LabelSquares(cv::Mat &image, bool visualize = false) = 0;
93 
94  bool CheckBorder(const std::vector<cv::Point> &contour, int width, int height);
95 
96  void
97  SetThreshParams(int param1, int param2)
98  {
99  thresh_param1 = param1;
100  thresh_param2 = param2;
101  }
102 };
103 
107 class ALVAR_EXPORT LabelingCvSeq : public Labeling
108 {
109 protected:
110  int _n_blobs;
111  int _min_edge;
112  int _min_area;
113  bool detect_pose_grayscale;
114 
115 public:
116  LabelingCvSeq();
117  ~LabelingCvSeq();
118 
119  void SetOptions(bool _detect_pose_grayscale = false);
120 
121  void LabelSquares(cv::Mat &image, bool visualize = false);
122 
123  // TODO: Releases memory inside, cannot return CvSeq*
124  std::vector<std::vector<cv::Point>> LabelImage(cv::Mat &image, int min_size, bool approx = false);
125 };
126 
127 } // namespace alvar
128 
129 #endif
This file defines library export definitions, version numbers and build information.
This file implements a camera used for projecting points and computing homographies.
This file implements a parametrized line.
This file implements generic utility functions and a serialization interface.
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
Labeling class that uses OpenCV routines to find connected components.
void LabelSquares(cv::Mat &image, bool visualize=false)
Labels image and filters blobs to obtain square-shaped objects from the scene.
Base class for labeling connected components from binary image.
cv::Mat gray
Pointer to grayscale image that is thresholded for labeling.
virtual void LabelSquares(cv::Mat &image, bool visualize=false)=0
Labels image and filters blobs to obtain square-shaped objects from the scene.
void SetCamera(Camera *camera)
Sets the camera object that is used to correct lens distortions.
cv::Mat bw
Pointer to binary image that is then labeled.
ThresholdMethod
Two alternatives for thresholding the gray image. ADAPT (adaptive threshold) is only supported curren...
std::vector< std::vector< PointDouble > > blob_corners
Vector of 4-length vectors where the corners of detected blobs are stored.
Main ALVAR namespace.
Definition: Alvar.h:174