70 #ifndef INCLUDED_RealtimeLaplacian_h_GUID_1ECD4EFB_BF33_479D_0ED7_890BF096056E 71 #define INCLUDED_RealtimeLaplacian_h_GUID_1ECD4EFB_BF33_479D_0ED7_890BF096056E 77 #include <opencv2/core/core.hpp> 78 #include <opencv2/imgproc/imgproc.hpp> 93 int borderType = cv::BORDER_DEFAULT)
94 : kSize_(kSize), destDepth_(destDepth), scale_(scale),
95 delta_(delta), borderType_(borderType) {}
97 void apply(cv::InputArray mySrc, cv::OutputArray myDst) {
98 if (kSize_ == 1 || kSize_ == 3) {
101 cv::Laplacian(mySrc, myDst, destDepth_, kSize_, scale_, delta_,
105 cv::Mat src = mySrc.getMat();
109 setup_ = doesImageMatchCache(src);
114 srcDepth_ = src.depth();
115 srcChannels_ = src.channels();
118 srcType_ = src.type();
124 myDst.create(src.size(), CV_MAKETYPE(destDepth_, src.channels()));
126 cv::Mat dst = myDst.getMat();
130 int y = fx_->start(src), dsty = 0, dy = 0;
132 const uchar *sptr = src.data + y * src.step;
134 for (; dsty < src.rows; sptr += dy0_ * src.step, dsty += dy) {
135 fx_->proceed(sptr, (
int)src.step, dy0_, d2x_.data,
137 dy = fy_->proceed(sptr, (
int)src.step, dy0_, d2y_.data,
142 cv::Mat dstripe = dst.rowRange(dsty, dsty + dy);
143 d2x_.rows = d2y_.rows =
146 d2x_.convertTo(dstripe, destType_, scale_, delta_);
152 bool doesImageMatchCache(cv::Mat
const &src)
const {
154 return (srcDepth_ == src.depth()) &&
155 (srcChannels_ == src.channels()) && (srcCols_ == src.cols) &&
156 (srcRows_ == src.rows) && (srcType_ == src.type());
159 return std::max<int>({CV_32F, destDepth_, srcDepth_});
163 int ktype = std::max(CV_32F, std::max(destDepth_, srcDepth_));
164 int wdepth = srcDepth_ == CV_8U && kSize_ <= 5
166 : srcDepth_ <= CV_32F ? CV_32F : CV_64F;
167 workType_ = CV_MAKETYPE(wdepth, srcChannels_);
170 cv::getDerivKernels(kd_, ks_, 2, 0, kSize_,
false, ktype);
172 destType_ = CV_MAKETYPE(destDepth_, srcChannels_);
174 std::min(std::max((
int)(STRIPE_SIZE /
175 (cv::getElemSize(srcType_) * srcCols_)),
178 fx_ = cv::createSeparableLinearFilter(
179 srcType_, workType_, kd_, ks_, cv::Point(-1, -1), 0,
181 fy_ = cv::createSeparableLinearFilter(
182 srcType_, workType_, ks_, kd_, cv::Point(-1, -1), 0,
188 d2x_ = cv::Mat(dy0_ + kd_.rows - 1, srcCols_, workType_);
189 d2y_ = cv::Mat(dy0_ + kd_.rows - 1, srcCols_, workType_);
195 const int destDepth_;
198 const int borderType_;
208 int srcChannels_ = 0;
220 cv::Ptr<cv::FilterEngine> fx_;
221 cv::Ptr<cv::FilterEngine> fy_;
227 static const size_t STRIPE_SIZE = 1 << 14;
232 #endif // INCLUDED_RealtimeLaplacian_h_GUID_1ECD4EFB_BF33_479D_0ED7_890BF096056E The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
A class designed for real-time use of a Laplacian on similar images over and over, based on the OpenCV implementation but avoiding duplicate work and using persistent temporary storage when possible.
Definition: RealtimeLaplacian.h:89
void apply(cv::InputArray mySrc, cv::OutputArray myDst)
Definition: RealtimeLaplacian.h:97
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48