Skip to content

Commit 760a1a0

Browse files
committed
page segmentation improved
1 parent 2568253 commit 760a1a0

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

app/src/main/cmake/DocScan.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ END
5151
//
5252

5353
VS_VERSION_INFO VERSIONINFO
54-
FILEVERSION 1,0,0,26647
54+
FILEVERSION 1,0,0,26652
5555
PRODUCTVERSION 1,0,0,26472
5656
FILEFLAGSMASK 0x3fL
5757
#ifdef _DEBUG
@@ -69,7 +69,7 @@ BEGIN
6969
BEGIN
7070
VALUE "CompanyName", "TU Wien"
7171
VALUE "FileDescription", "flowView - a visualization tool for FCS data and AutoGating"
72-
VALUE "FileVersion", "1.0.0.26647"
72+
VALUE "FileVersion", "1.0.0.26652"
7373
VALUE "InternalName", "flowView.exe"
7474
VALUE "LegalCopyright", "(C) 2015 TU Wien, Computer Vision Lab, Markus Diem"
7575
VALUE "OriginalFilename", "flowView.exe"

app/src/main/cmake/src-test/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int argc, char** argv) {
4848
}
4949

5050
std::string path = argv[1];
51-
//path = "C:/VSProjects/DocScan/img/tests/test.png";
51+
path = "C:/VSProjects/DocScan/img/tests/test.png";
5252

5353
// test the focus measure module
5454
if (!testFocusMeasure(path))
@@ -57,7 +57,7 @@ int main(int argc, char** argv) {
5757
std::cout << "[SUCCESS] focus measure succesfull..." << std::endl;
5858

5959
std::string oPath = argc > 2 ? argv[2] : "";
60-
//oPath = "C:/VSProjects/DocScan/img/tests/test-res.png";
60+
oPath = "C:/VSProjects/DocScan/img/tests/test-res.png";
6161

6262
// test the page segmentation module
6363
if (!testPageSegmentation(path, oPath))
@@ -138,8 +138,8 @@ bool testPageSegmentation(const std::string& filePath, const std::string& output
138138
cv::imwrite(outputPath, dstImg);
139139
}
140140

141-
double illVal = dsc::DkIllumination::apply(img, pageRects[0]);
142-
std::cout << "illumination value: " << illVal << std::endl;
141+
//double illVal = dsc::DkIllumination::apply(img, pageRects[0]);
142+
//std::cout << "illumination value: " << illVal << std::endl;
143143

144144
//std::cout << "test page segmentation not implemented..." << std::endl;
145145
return true;

app/src/main/jni/PageSegmentation.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,34 @@ void DkPageSegmentation::compute() {
9797
if (scale > 0.8f || scale <= 0.0f)
9898
scale = 1.0f;
9999

100-
findRectangles(mImg, mRects);
100+
findRectanglesLab(mImg, mRects);
101101

102102

103103
std::cout << "[DkPageSegmentation] " << mRects.size() << " rectangles found resize factor: " << scale << std::endl;
104104
}
105105

106-
void DkPageSegmentation::findRectangles(const cv::Mat& img, std::vector<DkPolyRect>& rects) const {
106+
void DkPageSegmentation::findRectanglesLab(const cv::Mat & img, std::vector<DkPolyRect>& rects) const {
107+
107108

108109
cv::Mat imgLab;
109110
cv::cvtColor(img, imgLab, CV_RGB2Lab); // luminance channel is better than grayscale
110111

111-
int ch[] = {0, 0};
112-
cv::Mat imgL(img.size(), CV_8UC1);
113-
mixChannels(&imgLab, 1, &imgL, 1, ch, 1);
114-
cv::normalize(imgL, imgL, 255, 0, cv::NORM_MINMAX);
115-
imgLab.release(); // early release
112+
for (int idx = 0; idx < img.channels(); idx++) {
113+
114+
int ch[] = {idx, 0};
115+
cv::Mat imgL(img.size(), CV_8UC1);
116+
cv::mixChannels(&imgLab, 1, &imgL, 1, ch, 1);
117+
std::vector<DkPolyRect> cr;
118+
findRectangles(imgL, rects);
119+
std::cout << rects.size() << " after channel " << idx << std::endl;
120+
}
121+
122+
}
123+
124+
void DkPageSegmentation::findRectangles(const cv::Mat& img, std::vector<DkPolyRect>& rects) const {
125+
126+
cv::Mat imgL;
127+
cv::normalize(img, imgL, 255, 0, cv::NORM_MINMAX);
116128

117129
// downscale
118130
if (scale != 1.0f)
@@ -124,6 +136,7 @@ void DkPageSegmentation::findRectangles(const cv::Mat& img, std::vector<DkPolyRe
124136
//std::cout << "thresh step: " << threshStep << std::endl;
125137

126138
cv::Mat gray;
139+
std::vector<DkPolyRect> rectsL;
127140

128141
// try several threshold levels
129142
for (int thr = 0; thr < 255; thr += threshStep) {
@@ -166,7 +179,7 @@ void DkPageSegmentation::findRectangles(const cv::Mat& img, std::vector<DkPolyRe
166179
//cv::Mat pImg = imgL.clone();
167180
//cv::cvtColor(pImg, pImg, CV_GRAY2BGR);
168181
// DEBUG ------------------------
169-
182+
170183
// test each contour
171184
for (size_t i = 0; i < contours.size(); i++) {
172185
// approxicv::Mate contour with accuracy proportional
@@ -200,7 +213,7 @@ void DkPageSegmentation::findRectangles(const cv::Mat& img, std::vector<DkPolyRe
200213
(!maxSide || cr.maxSide() < maxSide*scale) &&
201214
cr.getMaxCosine() < 0.3 ) {
202215

203-
rects.push_back(cr);
216+
rectsL.push_back(cr);
204217
}
205218
}
206219
}
@@ -210,25 +223,23 @@ void DkPageSegmentation::findRectangles(const cv::Mat& img, std::vector<DkPolyRe
210223
// DEBUG ------------------------
211224
}
212225

213-
for (size_t idx = 0; idx < rects.size(); idx++)
214-
rects[idx].scale(1.0f/scale);
226+
for (size_t idx = 0; idx < rectsL.size(); idx++)
227+
rectsL[idx].scale(1.0f/scale);
215228

216229

217230
// filter rectangles which are found because of the image border
218-
std::vector<DkPolyRect> noLargeRects;
219-
for (const DkPolyRect& p : rects) {
231+
for (const DkPolyRect& p : rectsL) {
220232

221233
DkBox b = p.getBBox();
222234

223235
if (b.size().height < img.rows*maxSideFactor &&
224236
b.size().width < img.cols*maxSideFactor) {
225-
noLargeRects.push_back(p);
237+
rects.push_back(p);
226238
}
227239
}
228240

229241
//cv::normalize(dbgImg, dbgImg, 255, 0, cv::NORM_MINMAX);
230242

231-
rects = noLargeRects;
232243
}
233244

234245
//QImage DkPageSegmentation::cropToRect(const QImage & img, const nmc::DkRotatingRect & rect, const QColor & bgCol) const {

app/src/main/jni/PageSegmentation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class DllCoreExport DkPageSegmentation {
7777

7878
std::vector<DkPolyRect> mRects;
7979

80+
virtual void findRectanglesLab(const cv::Mat& img, std::vector<DkPolyRect>& squares) const;
8081
virtual void findRectangles(const cv::Mat& img, std::vector<DkPolyRect>& squares) const;
8182
//QImage cropToRect(const QImage& mImg, const nmc::DkRotatingRect& rect, const QColor& bgCol = QColor(0,0,0)) const;
8283
//void drawRects(QPainter* p, const std::vector<DkPolyRect>& mRects, const QColor& col = QColor(100, 100, 100)) const;

0 commit comments

Comments
 (0)