Skip to content

Commit 7c8345a

Browse files
committed
Mainly fix matlab bugs
1 parent 32dc9c2 commit 7c8345a

File tree

7 files changed

+46
-8
lines changed

7 files changed

+46
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ We proposed a fast ellipse detection method based on arc adjacency matrix. We ha
66
<img src="measuretool/aamed.jpg" width="900px" />
77
</div>
88

9+
:blush:**The binaries for Matlab and Python can be downloaded from the latest release.**
910

1011

1112
## 1 Compile our Codes

matlab/mexAAMED.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
1616
// Get the data;
1717
double drows = *(double *)mxGetPr(prhs[0]);
1818
double dcols = *(double *)mxGetPr(prhs[1]);
19-
19+
if (drows <=0 || dcols <=0)
20+
{
21+
mexErrMsgTxt("drows or dcols must be larger than 0!!");
22+
}
2023
AAMED *_aamed = new AAMED(std::round(drows), std::round(dcols));
2124
int pointer_size = sizeof(_aamed);
2225

matlab/mexSetAAMEDParameters.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
2626
double theta_arc = *(double*)mxGetPr(prhs[1]);
2727
double lambda_arc = *(double*)mxGetPr(prhs[2]);
2828
double T_val = *(double*)mxGetPr(prhs[3]);
29+
2930
_aamed->SetParameters(theta_arc, lambda_arc, T_val);
3031

3132
}

matlab/mexdestoryAAMED.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,36 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
66
{
77
if(nrhs!=1)
88
{
9-
mexErrMsgTxt("There is only 1 input AAMED pointer.");
9+
mexErrMsgTxt("There only needs the AAMED pointer.");
1010
}
1111
if(nlhs!=0)
1212
{
1313
mexErrMsgTxt("No return value.");
1414
}
1515

1616
// Get the data;
17-
unsigned char *_pt = (unsigned char *)mxGetPr(prhs[0]);
1817
AAMED *_aamed = NULL;
18+
if(mxGetNumberOfElements(prhs[0]) != sizeof(_aamed))
19+
mexErrMsgTxt("Wrong AAMED Pointer.");
20+
21+
unsigned char *_pt = (unsigned char *)mxGetPr(prhs[0]);
22+
1923
int pointer_size = sizeof(_aamed);
2024
unsigned char *_pt_aamed = (unsigned char *)&_aamed;
2125
for(int i = 0; i < pointer_size; i++)
2226
{
2327
_pt_aamed[i] = _pt[i];
2428
}
25-
_aamed->release();
26-
//delete[] _aamed;
29+
if(_aamed == 0)
30+
mexWarnMsgTxt("input parm is a null pointer(0)");
31+
else
32+
{
33+
delete _aamed;
34+
for(int i = 0; i < pointer_size; i++)
35+
{
36+
_pt[i] = 0;
37+
}
38+
}
39+
2740

2841
}

matlab/mexdetectImagebyAAMED.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,27 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
2525
unsigned char * _imgmatlab = (unsigned char *)mxGetPr(prhs[1]);
2626
int irows = mxGetM(prhs[1]);
2727
int icols = mxGetN(prhs[1]);
28+
if(!_aamed->checkInputImage(irows, icols))
29+
{
30+
mexWarnMsgTxt("The rows(cols) of the image must be large than drows(dcols)");
31+
plhs[0] = mxCreateDoubleMatrix(0,5,mxREAL);
32+
return;
33+
}
34+
2835
cv::Mat imgG(irows, icols, CV_8UC1);
2936
unsigned char * _img = (unsigned char*)imgG.data;
37+
3038
for(int i = 0; i < irows; i++)
3139
{
3240
for(int j = 0; j < icols; j++)
3341
{
34-
_img[i * icols + j] = _imgmatlab[j * icols + i];
42+
_img[i * icols + j] = _imgmatlab[j * irows + i];
3543
}
3644
}
45+
3746
_aamed->run_FLED(imgG);
3847
int elp_num = _aamed->detEllipses.size();
48+
3949
plhs[0] = mxCreateDoubleMatrix(elp_num,5,mxREAL);
4050
double *_elp = (double *)mxGetPr(plhs[0]);
4151
for(int i = 0; i < elp_num; i++)

src/FLED.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ void FLED::release()
8282
lA.release();
8383

8484
}
85-
85+
bool FLED::checkInputImage(int rows, int cols)
86+
{
87+
if (rows > dROWS || cols > dCOLS)
88+
return false;
89+
else
90+
return true;
91+
}
8692
void FLED::run_AAMED_WithoutCanny(Mat Img_G)
8793
{
8894

src/FLED.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ class FLED
4343
FLED(int drows, int dcols);
4444
void SetParameters(double theta_fsa, double length_fsa, double T_val);
4545
vector<cv::RotatedRect> detEllipses;
46-
46+
~FLED()
47+
{
48+
release();
49+
}
4750

4851

4952
void SetParameters(double T_dp, double theta_fsa, double length_fsa, double T_val, int grad_num);
5053
void initFrame();
5154
void release();// release data;
55+
bool checkInputImage(int rows, int cols);
5256
void run_FLED(Mat Img_G);
5357
void run_AAMED_WithoutCanny(Mat Img_G);
5458
public:// Draw Data and Write Information Functions

0 commit comments

Comments
 (0)