Skip to content

Commit 08c3c53

Browse files
author
willzhen
committed
Adapt for centos compile
1 parent 60a3672 commit 08c3c53

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

CMakeLists.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ project (${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES CXX)
2121
set (OpenCV_FOUND 1)
2222
find_package (OpenCV REQUIRED)
2323

24-
set (OTHER_LIBS -llapack)
24+
# Manual set open library
25+
#include_directories(/xxx/opencv_tag_v3.2.0)
26+
#include_directories (/xxx/opencv_tag_v3.2.0/include)
27+
#link_directories(/xxx/opencv_tag_v3.2.0/lib)
28+
set (OTHER_LIBS -llapack -lblas -lgfortran)
2529

2630
set (CMAKE_CXX_STANDARD 11)
2731
set (CMAKE_CXX_STANDARD_REQUIRE ON)
@@ -41,8 +45,13 @@ set (DEPEND_FILE
4145
"src/cvcannyapi.cpp"
4246
)
4347

44-
add_library (${PACKAGE_NAME} ${DEPEND_FILE})
48+
set (Opencv_LIBS
49+
-lopencv_core
50+
-lopencv_imgproc
51+
-lopencv_highgui
52+
)
4553

54+
add_library (${PACKAGE_NAME} ${DEPEND_FILE})
4655
target_link_libraries(${PACKAGE_NAME} ${Opencv_LIBS} ${OTHER_LIBS})
4756

4857
set (PUBLIC_HDRS

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# ubuntu 的使用方法
66
1. 首先需要安装两个库的支持,opencv 库,这个可以搜一下网上的教程安装一下。第二个库是一个矩阵运算的库lapack,需要源码安装。
7-
先下载[lapack源码](https://github.com/Reference-LAPACK/lapack/archive/v3.9.0.tar.gz),这个库是gfortran写的,所以要先`sudo apt-get install gfortran`安装gfortran。
7+
先下载[lapack源码](https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.9.1.tar.gz),这个库是gfortran写的,所以要先`sudo apt-get install gfortran`安装gfortran。
88
然后
99
```
1010
tar -xzvf lapack-3.9.0.tar.gz && cd lapack-3.9.0
@@ -13,7 +13,8 @@ cmake ..
1313
make -j7
1414
sudo make install
1515
sudo ldconfig
16-
sudo cp sudo cp LAPACKE/include/*.h /usr/local/include/
16+
cd ..
17+
sudo cp LAPACKE/include/*.h /usr/local/include/
1718
```
1819

1920
2. 安装ellipse-detection库

src/detect.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool lsdgroups(const double *image, int row, int col, double scale, std::vector<
7272
max_vote = 1;
7373
} else if (cnt > max_vote){
7474
max_idx = line_id;
75-
max_vote = cnt;
75+
max_vote = cnt;
7676
}
7777
}
7878
}
@@ -108,8 +108,8 @@ bool lsdgroups(const double *image, int row, int col, double scale, std::vector<
108108
} else {
109109
downdir.rotation(PI_4);
110110
}
111-
112-
111+
112+
113113
std::unordered_map<int, int> vote;
114114
int max_vote = 0, max_idx = -1;
115115

@@ -127,7 +127,7 @@ bool lsdgroups(const double *image, int row, int col, double scale, std::vector<
127127
max_vote = 1;
128128
} else if (cnt > max_vote){
129129
max_idx = line_id;
130-
max_vote = cnt;
130+
max_vote = cnt;
131131
}
132132
}
133133
}
@@ -175,7 +175,7 @@ bool lsdgroups(const double *image, int row, int col, double scale, std::vector<
175175
return true;
176176
}
177177

178-
bool getValidInitialEllipseSet(const uint8_t *image,
178+
bool getValidInitialEllipseSet(const uint8_t *image,
179179
const double *angles,
180180
int row, int col,
181181
std::vector<std::shared_ptr<Ellipse> > &ells,
@@ -228,15 +228,15 @@ bool getValidInitialEllipseSet(const uint8_t *image,
228228

229229
static bool meanShift(const std::vector<double> &data, std::vector<double> &init_data, int dims,
230230
double sigma, double windos_size, double accuracy_tolerance, int iter_times) {
231-
231+
232232
double temparr[8];
233233
int nquerrues = (int)init_data.size() / dims;
234234
int data_num = (int)data.size() / dims;
235235
double sigma2 = sigma * sigma;
236236
double radius2 = windos_size * windos_size;
237237
double tolerance = accuracy_tolerance;
238238
int maxiters = iter_times;
239-
239+
240240
std::vector<double> dis(data_num);
241241
for (int loop = 0; loop < nquerrues; ++loop) {
242242
int iters = 0;
@@ -273,7 +273,7 @@ static bool meanShift(const std::vector<double> &data, std::vector<double> &init
273273
init_data[loop * dims + d] /= denominator;
274274
temp += sqr(init_data[loop * dims + d] - temparr[d]);
275275
}
276-
276+
277277
if (sqrt(temp) < tolerance) {
278278
break;
279279
}
@@ -285,7 +285,7 @@ static bool meanShift(const std::vector<double> &data, std::vector<double> &init
285285

286286
static bool clusterByDistance(std::vector<double> &data, int dims, double distance_threshold,
287287
double number_control) {
288-
288+
289289
double threshold2 = distance_threshold * distance_threshold;
290290
int npoints = (int)data.size() / dims;
291291
if (npoints == 1) {
@@ -338,7 +338,7 @@ static bool cluster2DPoints(const std::vector<std::shared_ptr<Ellipse> > &ells,
338338
std::vector<Pointd> &cluster_center,
339339
double distance_tolerance,
340340
int data_type) {
341-
341+
342342
int nbinx, nbiny;
343343
double xmax, ymax, xmin, ymin;
344344
xmax = ymax = 0;
@@ -413,7 +413,7 @@ static bool cluster2DPoints(const std::vector<std::shared_ptr<Ellipse> > &ells,
413413
static bool cluster1DDatas(const std::vector<std::shared_ptr<Ellipse> > &ells,
414414
std::vector<double> &cluster_center,
415415
double distance_tolerance) {
416-
416+
417417
double val_max = 0;
418418
double val_min = DBL_MAX;
419419
std::vector<double> data;
@@ -430,7 +430,7 @@ static bool cluster1DDatas(const std::vector<std::shared_ptr<Ellipse> > &ells,
430430
if (nbins <= 0) {
431431
nbins = 1;
432432
}
433-
// first sum, second vote;
433+
// first sum, second vote;
434434
std::vector<std::pair<double, int> > bindata(nbins, std::make_pair(0.0, 0));
435435
for (auto &ell : ells) {
436436
int r = (int)floor((ell->phi - val_min) / val_delta * nbins + 0.5);
@@ -455,15 +455,15 @@ static bool cluster1DDatas(const std::vector<std::shared_ptr<Ellipse> > &ells,
455455

456456
// 均值漂移
457457
meanShift(data, cluster_center, 1, 1, distance_tolerance, 1e-6, 20);
458-
458+
459459
// 按照距离阈值聚类
460460
clusterByDistance(cluster_center, 1, distance_tolerance / 2, 40);
461461

462462
return true;
463463
}
464464

465465
bool generateEllipseCandidates(const uint8_t *image, const double *angles,
466-
int row, int col,
466+
int row, int col,
467467
std::vector<std::shared_ptr<Ellipse> > &ells, int polarity) {
468468

469469
std::vector<std::shared_ptr<Ellipse> > ells_init;
@@ -477,12 +477,12 @@ bool generateEllipseCandidates(const uint8_t *image, const double *angles,
477477

478478

479479
// 最外层椭圆中心聚类 第二层椭圆 phi 聚类 第三层椭圆长短轴聚类
480-
480+
481481
std::vector<Pointd> cluster_center;
482482
cluster2DPoints(ells_init, cluster_center, MIN_ELLIPSE_THRESHOLD_LENGTH, 0);
483483

484484
int center_num = (int)cluster_center.size();
485-
485+
486486
std::vector<std::vector<std::shared_ptr<Ellipse> > > ells_center(center_num);
487487

488488
// TODO(using KD tree optimization if necessary)
@@ -513,7 +513,7 @@ bool generateEllipseCandidates(const uint8_t *image, const double *angles,
513513

514514
std::sort(cluster_phi.begin(), cluster_phi.end());
515515
std::sort(ells_c.begin(), ells_c.end(),
516-
[](std::shared_ptr<Ellipse> &ea, std::shared_ptr<Ellipse> &eb) {
516+
[](const std::shared_ptr<Ellipse> &ea, const std::shared_ptr<Ellipse> &eb) {
517517
return ea->phi < eb->phi;
518518
});
519519
int p = 0;
@@ -636,7 +636,7 @@ static bool subdetect(double *angles, int row, int col, double min_cover_angle,
636636
if (issame) {
637637
continue;
638638
}
639-
639+
640640
double beta = PI * (1.5 * (ell->a + ell->b) - sqrt(ell->a * ell->b));
641641
int tbins = min(180, (int)floor(beta * tr));
642642
std::vector<Pixel> inliers_t;
@@ -733,7 +733,7 @@ static bool subdetect(double *angles, int row, int col, double min_cover_angle,
733733
return true;
734734
}
735735

736-
bool detectEllipse(const uint8_t *image, int row, int col,
736+
bool detectEllipse(const uint8_t *image, int row, int col,
737737
std::vector<std::shared_ptr<Ellipse> > &ells, int polarity, double width) {
738738

739739
// calc the gradient
@@ -749,9 +749,9 @@ bool detectEllipse(const uint8_t *image, int row, int col,
749749
double tr = 0.6;
750750
double distance_tolerance = MIN_ELLIPSE_THRESHOLD_LENGTH;
751751
double normal_tolerance = cos(PI / 12.0);
752-
753752

754-
753+
754+
755755
std::vector<Pixel> inliers_positive, inliers_negative, inliers_all;
756756
std::vector<std::shared_ptr<Ellipse> > ells_temp;
757757
for (auto &ell : ells) {

test/CMakeLists.txt

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
cmake_minimum_required (VERSION 2.4)
22

33
if (COMMAND cmake_policy)
4-
cmake_policy(SET CMP0003 NEW)
5-
endif(COMMAND cmake_policy)
4+
cmake_policy (SET CMP0003 NEW)
5+
endif (COMMAND cmake_policy)
66

77
set (OpenCV_FOUND 1)
88
find_package (OpenCV REQUIRED)
9+
# Manual set open library
10+
#include_directories (/xxx/opencv_tag_v3.2.0)
11+
#include_directories (/xxx/opencv_tag_v3.2.0/include)
12+
#link_directories (/xxx/opencv_tag_v3.2.0/lib)
13+
14+
set (Opencv_LIBS
15+
-lopencv_core
16+
-lopencv_imgproc
17+
-lopencv_highgui
18+
)
919

1020
project (tests)
1121

22+
1223
add_executable (testtype testtype.cpp)
1324
target_link_libraries (testtype ellipse_detection ${OpenCV_LIBS})
1425

@@ -22,4 +33,4 @@ add_executable (testinital testinital.cpp)
2233
target_link_libraries (testinital ellipse_detection ${OpenCV_LIBS})
2334

2435
add_executable (testdetect testdetect.cpp)
25-
target_link_libraries (testdetect ellipse_detection ${OpenCV_LIBS})
36+
target_link_libraries (testdetect ellipse_detection ${OpenCV_LIBS})

0 commit comments

Comments
 (0)