test_math_erodeAndGaussianBlurCommandTest.h 2.16 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
15
16
17
cube src;
int erosion_elemIn;
colvec sizeY;
colvec two;
Ahmed's avatar
Ahmed committed
18
cube dst;
Ahmed's avatar
Ahmed committed
19
20
cube outMatrix;
mat out2Matrix;
Ahmed's avatar
Ahmed committed
21
22
void init()
{
Ahmed's avatar
Ahmed committed
23
src = cube(n, m, 3);
Ahmed's avatar
Ahmed committed
24
25
sizeY=colvec(3);
two=colvec(2);
Ahmed's avatar
Ahmed committed
26
dst = cube(n, m, 3);
Ahmed's avatar
Ahmed committed
27
28
outMatrix = cube(3, n, m);
out2Matrix=mat(2,m);
Ahmed's avatar
Ahmed committed
29
}
Ahmed's avatar
Ahmed committed
30
void erodeHelper(cube src, cube dst, int erosion_elem, int iterations)
Ahmed's avatar
Ahmed committed
31
32
33
34
35
36
{
    int erosion_type = 0;
    if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
    else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
    else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
    erosion_size = erosion_elem;
Ahmed's avatar
Ahmed committed
37
    mat element = cv::getStructuringElement( erosion_type,
Ahmed's avatar
Ahmed committed
38
39
                            Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                            Point( -1, -1 ) );
Ahmed's avatar
Ahmed committed
40
    cv::erode( src, dst, element, Point(-1,-1), iterations );
Ahmed's avatar
Ahmed committed
41
}
Ahmed's avatar
Ahmed committed
42
43
44
45
46
47
48
void dilateHelper(cube src, cube dst, int dilation_elem, int iterations)
{
    int dilation_type = 0;
    if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
    else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
    else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
    dilation_size = dilation_elem;
Ahmed's avatar
Ahmed committed
49
    mat element = cv::getStructuringElement( dilation_type,
Ahmed's avatar
Ahmed committed
50
51
                            Size( 2*dilation_size + 1, 2*dilation_size+1 ),
                            Point( -1, -1 ) );
Ahmed's avatar
Ahmed committed
52
    cv::dilate( src, dst, element, Point(-1,-1), iterations );
Ahmed's avatar
Ahmed committed
53
}
Ahmed's avatar
Ahmed committed
54
55
56
void execute()
{
erodeHelper(src, dst, erosion_elem, iterations);
Ahmed's avatar
Ahmed committed
57
cube dst2=cube(270,340,3);
Ahmed's avatar
Ahmed committed
58
erodeHelper(src, dst2, erosion_elem, iterations);
Ahmed's avatar
Ahmed committed
59
60
61
62
63
64
erodeHelper(src, dst, erosion_elem, iterations);
dilateHelper(dst, dst3, dilation_elem, iterations);
cube src4 = (det(src));
erodeHelper(src4, dst, erosion_elem, iterations);
erodeHelper(src, dst, erosion_elem, iterations);
dilateHelper(dst, dst3, dilation_elem, iterations);
Ahmed's avatar
Ahmed committed
65
cv::findContours(dst3, contours, method, mode);
Ahmed's avatar
Ahmed committed
66
67
68
69
}

};
#endif