1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "precomp.hpp"
#include "opencv2/hfs.hpp"
#include "hfs_core.hpp"
namespace cv{ namespace hfs{
class HfsSegmentImpl CV_FINAL : public cv::hfs::HfsSegment{
public:
void setSegEgbThresholdI(float c) CV_OVERRIDE
{
core->hfsSettings.egbThresholdI = c;
}
float getSegEgbThresholdI() CV_OVERRIDE {
return core->hfsSettings.egbThresholdI;
}
void setMinRegionSizeI(int n) CV_OVERRIDE
{
core->hfsSettings.minRegionSizeI = n;
}
int getMinRegionSizeI() CV_OVERRIDE
{
return core->hfsSettings.minRegionSizeI;
}
void setSegEgbThresholdII(float c) CV_OVERRIDE
{
core->hfsSettings.egbThresholdII = c;
}
float getSegEgbThresholdII() CV_OVERRIDE {
return core->hfsSettings.egbThresholdII;
}
void setMinRegionSizeII(int n) CV_OVERRIDE
{
core->hfsSettings.minRegionSizeII = n;
}
int getMinRegionSizeII() CV_OVERRIDE
{
return core->hfsSettings.minRegionSizeII;
}
void setSpatialWeight(float w) CV_OVERRIDE
{
core->hfsSettings.slicSettings.coh_weight = w;
core->reconstructEngine();
}
float getSpatialWeight() CV_OVERRIDE
{
return core->hfsSettings.slicSettings.coh_weight;
}
void setSlicSpixelSize(int n) CV_OVERRIDE
{
core->hfsSettings.slicSettings.spixel_size = n;
core->reconstructEngine();
}
int getSlicSpixelSize() CV_OVERRIDE
{
return core->hfsSettings.slicSettings.spixel_size;
}
void setNumSlicIter(int n) CV_OVERRIDE
{
core->hfsSettings.slicSettings.num_iters = n;
core->reconstructEngine();
}
int getNumSlicIter() CV_OVERRIDE
{
return core->hfsSettings.slicSettings.num_iters;
}
HfsSegmentImpl(int height, int width,
float segEgbThresholdI, int minRegionSizeI, float segEgbThresholdII, int minRegionSizeII,
float spatialWeight, int spixelSize, int numIter)
{
core = Ptr<HfsCore>(new HfsCore(height, width,
segEgbThresholdI, minRegionSizeI, segEgbThresholdII, minRegionSizeII,
spatialWeight, spixelSize, numIter));
}
Mat performSegmentGpu(InputArray src, bool ifDraw = true) CV_OVERRIDE;
Mat performSegmentCpu(InputArray src, bool ifDraw = true) CV_OVERRIDE;
private:
Ptr<HfsCore> core;
};
Mat HfsSegmentImpl::performSegmentGpu(InputArray src, bool ifDraw) {
Mat src_ = src.getMat();
CV_Assert(src_.rows == core->hfsSettings.slicSettings.img_size.y);
CV_Assert(src_.cols == core->hfsSettings.slicSettings.img_size.x);
Mat seg;
int num_css = core->processImageGpu(src_, seg);
if(ifDraw){
Mat res;
core->drawSegmentationRes( seg, src_, num_css, res );
return res;
}else{
return seg;
}
}
Mat HfsSegmentImpl::performSegmentCpu(InputArray src, bool ifDraw) {
Mat src_ = src.getMat();
CV_Assert(src_.rows == core->hfsSettings.slicSettings.img_size.y);
CV_Assert(src_.cols == core->hfsSettings.slicSettings.img_size.x);
Mat seg;
int num_css = core->processImageCpu(src_, seg);
if (ifDraw) {
Mat res;
core->drawSegmentationRes(seg, src_, num_css, res);
return res;
}
else {
return seg;
}
}
Ptr<HfsSegment> HfsSegment::create(int height, int width, float segEgbThresholdI, int minRegionSizeI,
float segEgbThresholdII, int minRegionSizeII,
float spatialWeight, int spixelSize, int numIter)
{
return Ptr<HfsSegmentImpl>(new HfsSegmentImpl(height, width,
segEgbThresholdI, minRegionSizeI, segEgbThresholdII, minRegionSizeII,
spatialWeight, spixelSize, numIter));
}
}}