test_math_erodeAndGaussianBlurCommandTest.h 2.27 KB
Newer Older
Ahmed's avatar
Ahmed committed
1
2
3
4
5
6
7
#ifndef TEST_MATH_ERODEANDGAUSSIANBLURCOMMANDTEST
#define TEST_MATH_ERODEANDGAUSSIANBLURCOMMANDTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo"
#include "opencv2/imgproc.hpp"
Ahmed's avatar
Ahmed committed
8
#include "ConvHelper.h"
Ahmed's avatar
Ahmed committed
9
#include <vector>
Ahmed's avatar
Ahmed committed
10
using namespace arma;
Ahmed's avatar
Ahmed committed
11
using namespace std;
Ahmed's avatar
Ahmed committed
12
13
class test_math_erodeAndGaussianBlurCommandTest{
public:
Ahmed's avatar
Ahmed committed
14
Cube<unsigned char> src;
Ahmed's avatar
Ahmed committed
15
16
17
int erosion_elemIn;
colvec sizeY;
colvec two;
Ahmed's avatar
Ahmed committed
18
19
cv::Mat dst;
cv::Mat dst3;
Ahmed's avatar
Ahmed committed
20
21
Cube<unsigned char> outMatrix;
arma::Mat<unsigned char> out2Matrix;
Ahmed's avatar
Ahmed committed
22
23
void init()
{
Ahmed's avatar
Ahmed committed
24
src = Cube<unsigned char>(n, m, 3);
Ahmed's avatar
Ahmed committed
25
26
sizeY=colvec(3);
two=colvec(2);
Ahmed's avatar
Ahmed committed
27
outMatrix = Cube<unsigned char>(3, n, m);
Ahmed's avatar
Ahmed committed
28
out2Matrix=Mat<unsigned char>(2,m);
Ahmed's avatar
Ahmed committed
29
}
Ahmed's avatar
Ahmed committed
30
void erodeHelper(const Cube<unsigned char>& src, cv::Mat& dst, int erosion_elem, int iterations)
Ahmed's avatar
Ahmed committed
31
32
{
    int erosion_type = 0;
Ahmed's avatar
Ahmed committed
33
34
35
36
    if( erosion_elem == 0 ){ erosion_type = cv::MORPH_RECT; }
    else if( erosion_elem == 1 ){ erosion_type = cv::MORPH_CROSS; }
    else if( erosion_elem == 2) { erosion_type = cv::MORPH_ELLIPSE; }
    int erosion_size = erosion_elem;
Ahmed's avatar
Ahmed committed
37
    cv::Mat element = cv::getStructuringElement( erosion_type,
Ahmed's avatar
Ahmed committed
38
39
                            cv::Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                            cv::Point( -1, -1 ) );
Ahmed's avatar
Ahmed committed
40
    cv::Mat srcCV;
Ahmed's avatar
Ahmed committed
41
42
    srcCV = to_cvmat<unsigned char>(src);
    cv::erode( srcCV, dst, element, cv::Point(-1,-1), iterations );
Ahmed's avatar
Ahmed committed
43
}
Ahmed's avatar
Ahmed committed
44
void dilateHelper(const cv::Mat& src, cv::Mat& dst, int dilation_elem, int iterations)
Ahmed's avatar
Ahmed committed
45
46
{
    int dilation_type = 0;
Ahmed's avatar
Ahmed committed
47
48
49
50
51
52
53
54
    if( dilation_elem == 0 ){ dilation_type = cv::MORPH_RECT; }
    else if( dilation_elem == 1 ){ dilation_type = cv::MORPH_CROSS; }
    else if( dilation_elem == 2) { dilation_type = cv::MORPH_ELLIPSE; }
    int dilation_size = dilation_elem;
    cv::Mat element = cv::getStructuringElement( dilation_type,
                            cv::Size( 2*dilation_size + 1, 2*dilation_size+1 ),
                            cv::Point( -1, -1 ) );
    cv::dilate( src, dst, element, cv::Point(-1,-1), iterations );
Ahmed's avatar
Ahmed committed
55
}
Ahmed's avatar
Ahmed committed
56
void findContoursHelper(const cv::Mat& image, std::vector<std::vector<cv::Point>>& contours, int mode, int method)
Ahmed's avatar
Ahmed committed
57
58
59
{
    cv::findContours( image, contours, mode, method );
}
Ahmed's avatar
Ahmed committed
60
61
62
void execute()
{
erodeHelper(src, dst, erosion_elem, iterations);
Ahmed's avatar
Ahmed committed
63
dilateHelper(dst, dst3, dilation_elem, iterations);
Ahmed's avatar
Ahmed committed
64
findContoursHelper(dst3, contours);
Ahmed's avatar
Ahmed committed
65
66
67
68
}

};
#endif