Aufgrund einer Wartung wird GitLab am 19.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 19.10. between 8:00 and 9:00 am.

test_math_erodeCommandTest.h 1.27 KB
Newer Older
Ahmed's avatar
Ahmed committed
1
2
3
4
5
6
7
#ifndef TEST_MATH_ERODECOMMANDTEST
#define TEST_MATH_ERODECOMMANDTEST
#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
using namespace arma;
Ahmed's avatar
Ahmed committed
10
using namespace std;
Ahmed's avatar
Ahmed committed
11
12
class test_math_erodeCommandTest{
public:
Ahmed's avatar
Ahmed committed
13
arma::Mat<unsigned char> src;
Ahmed's avatar
Ahmed committed
14
int erosion_elem;
15
int iterations;
Ahmed's avatar
Ahmed committed
16
arma::Mat<unsigned char> dst;
Ahmed's avatar
Ahmed committed
17
18
void init()
{
Ahmed's avatar
Ahmed committed
19
20
src=Mat<unsigned char>(n,m);
dst=Mat<unsigned char>(n,m);
Ahmed's avatar
Ahmed committed
21
}
Ahmed's avatar
Ahmed committed
22
void erodeHelper(const arma::Mat<unsigned char>& src, arma::Mat<unsigned char>& dst, int erosion_elem, int iterations)
Ahmed's avatar
Ahmed committed
23
24
{
    int erosion_type = 0;
Ahmed's avatar
Ahmed committed
25
26
27
28
    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
29
    cv::Mat element = cv::getStructuringElement( erosion_type,
Ahmed's avatar
Ahmed committed
30
31
                            cv::Size( 2*erosion_size + 1, 2*erosion_size+1 ),
                            cv::Point( -1, -1 ) );
Ahmed's avatar
Ahmed committed
32
33
    cv::Mat srcCV;
    cv::Mat dstCV;
Ahmed's avatar
Ahmed committed
34
35
36
    srcCV = to_cvmat<unsigned char>(src);
    cv::erode( srcCV, dstCV, element, cv::Point(-1,-1), iterations );
    dst = to_arma<unsigned char>(dstCV);
Ahmed's avatar
Ahmed committed
37
}
Ahmed's avatar
Ahmed committed
38
39
void execute()
{
40
erodeHelper(src, dst, erosion_elem, iterations);
Ahmed's avatar
Ahmed committed
41
42
43
44
}

};
#endif