OKVIS ROS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CameraBase.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: Feb 3, 2015
30  * Author: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
31  *********************************************************************************/
32 
39 #include <iostream>
40 
42 namespace okvis {
44 namespace cameras {
45 
46 // Set the mask. It must be the same size as the image and
47 bool CameraBase::setMask(const cv::Mat & mask)
48 {
49  // check type
50  if (mask.type() != CV_8UC1) {
51  return false;
52  }
53  // check size
54  if (mask.rows != imageHeight_) {
55  return false;
56  }
57  if (mask.cols != imageWidth_) {
58  return false;
59  }
60  mask_ = mask;
61  return true;
62 }
63 
66 {
67  mask_.resize(0);
68  return true;
69 }
70 
71 // Was a nonzero mask set?
72 bool CameraBase::hasMask() const
73 {
74  return (mask_.data);
75 }
76 
77 // Get the mask.
78 const cv::Mat & CameraBase::mask() const
79 {
80  return mask_;
81 }
82 
83 bool CameraBase::isMasked(const Eigen::Vector2d& imagePoint) const
84 {
85  if (!isInImage(imagePoint)) {
86  return true;
87  }
88  if (!hasMask()) {
89  return false;
90  }
91  return mask_.at<uchar>(int(imagePoint[1]), int(imagePoint[0]));
92 }
93 
94 // Check if the keypoint is in the image.
95 bool CameraBase::isInImage(const Eigen::Vector2d& imagePoint) const
96 {
97  if (imagePoint[0] < 0.0 || imagePoint[1] < 0.0) {
98  return false;
99  }
100  if (imagePoint[0] >= imageWidth_ || imagePoint[1] >= imageHeight_) {
101  return false;
102  }
103  return true;
104 }
105 
106 } // namespace cameras
107 } // namespace okvis
108 
int imageHeight_
image height in pixels
Definition: CameraBase.hpp:350
bool removeMask()
stop masking
Definition: CameraBase.hpp:65
bool isInImage(const Eigen::Vector2d &imagePoint) const
Check if the keypoint is in the image.
Definition: CameraBase.hpp:95
int imageWidth_
image width in pixels
Definition: CameraBase.hpp:349
bool setMask(const cv::Mat &mask)
Set the mask. It must be the same size as the image and comply with OpenCV: 0 == masked, nonzero == valid. Type must be CV_8U1C.
Definition: CameraBase.hpp:47
bool hasMask() const
Was a nonzero mask set?
Definition: CameraBase.hpp:72
const cv::Mat & mask() const
Get the mask.
Definition: CameraBase.hpp:78
cv::Mat mask_
The mask – empty by default.
Definition: CameraBase.hpp:347
bool isMasked(const Eigen::Vector2d &imagePoint) const
Check if the keypoint is masked.
Definition: CameraBase.hpp:83