-
Notifications
You must be signed in to change notification settings - Fork 53
/
corealgmatlab.cpp
41 lines (35 loc) · 1.38 KB
/
corealgmatlab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Copyright 2017 onlyliu([email protected]). */
/* */
/* part of source code come from https://github.com/qibao77/cornerDetect */
/* Automatic Camera and Range Sensor Calibration using a single Shot */
/* this project realize the papar: Automatic Camera and Range Sensor */
/* Calibration using a single Shot */
#include "corealgmatlab.h"
using namespace cv;
corealgmatlab::corealgmatlab()
{
}
corealgmatlab::~corealgmatlab()
{
}
Mat corealgmatlab::conv2(const Mat &img, const Mat& ikernel, ConvolutionType type)
{
Mat dest;
Mat kernel;
flip(ikernel, kernel, -1);
Mat source = img;
if (CONVOLUTION_FULL == type)
{
source = Mat();
const int additionalRows = kernel.rows - 1, additionalCols = kernel.cols - 1;
copyMakeBorder(img, source, (additionalRows + 1) / 2, additionalRows / 2, (additionalCols + 1) / 2, additionalCols / 2, BORDER_CONSTANT, Scalar(0));
}
Point anchor(kernel.cols - kernel.cols / 2 - 1, kernel.rows - kernel.rows / 2 - 1);
int borderMode = BORDER_CONSTANT;
filter2D(source, dest, img.depth(), kernel, anchor, 0, borderMode);
if (CONVOLUTION_VALID == type)
{
dest = dest.colRange((kernel.cols - 1) / 2, dest.cols - kernel.cols / 2).rowRange((kernel.rows - 1) / 2, dest.rows - kernel.rows / 2);
}
return dest;
}