Skip to content

Commit 0b1be72

Browse files
authored
Merge pull request #7 from electronicarts/dev-Ricardo/FixLineAproximationError
Fix line approximation runtime error
2 parents fed70cd + 033d7fa commit 0b1be72

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/Log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace tik
1414
m_CoreLogger = std::make_shared<spdlog::logger>("CoreLogger");
1515

1616
// Then the logging level can be set with the following function
17-
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_SILENT);
17+
1818

1919
//add sinks to logger
2020
if (console)

src/Textbox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ namespace tik
2020
int boxWidth = bottomRight.x - topLeft.x;
2121

2222
textBoxRect = cv::Rect(topLeft.x, topLeft.y, boxWidth, boxHeight);
23+
textRect = textBoxRect;
2324
textSubMat = frameImg(textBoxRect);
2425
}
2526

2627
TextBox::TextBox(cv::Rect rect, cv::Mat frameImg) : textBoxRect(rect)
2728
{
29+
textRect = textBoxRect;
2830
textSubMat = frameImg(textBoxRect);
2931
}
3032

src/TextboxDetectionDB.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,38 @@ namespace tik {
9999
if (boxes.empty()) return { mergedLines, boxes };
100100

101101
// Sort boxes by the top y-coordinate
102-
auto sortedBoxes = boxes;
102+
auto& sortedBoxes = boxes;
103103
for (auto& textBox : sortedBoxes)
104104
{
105105
textBox.calculateTextBoxLuminance(sRGB_LUT);
106106
}
107+
107108
for (auto& textBox : sortedBoxes)
108109
{
109110
textBox.calculateTextMask();
110111
auto boxRect = textBox.getTextBoxRect();
111112
auto textRect = textBox.getTextRect();
112113

113-
textBox = { cv::Rect{ boxRect.x + textRect.x - 1, boxRect.y + textRect.y - 1, textRect.width + 2, textRect.height + 2 },img };
114+
int x = std::max(boxRect.x + textRect.x, 0);
115+
int y = std::max(boxRect.y + textRect.y, 0);
116+
int w = std::min(boxRect.width, (img.cols - x));
117+
int h = std::min(boxRect.height, (img.rows - y));
118+
119+
auto tb = cv::Rect{ x , y, w, h };
120+
textBox = { tb,img };
114121
}
115122

116-
// boxRect.x + textRect.x - 1, boxRect.y + textRect.y - 1, textRect.width + 2, textRect.height + 2
123+
// Sort vertically
117124
std::sort(sortedBoxes.begin(), sortedBoxes.end(), [](const TextBox& a, const TextBox& b) {
118125
return a.getTextBoxRect().y < b.getTextBoxRect().y;
119-
});
126+
});
127+
// Sort horizontally after vertically
128+
std::sort(sortedBoxes.begin(), sortedBoxes.end(), [&](const TextBox& a, const TextBox& b) {
129+
if (std::abs(a.getTextBoxRect().y - b.getTextBoxRect().y) < MAX_Y_DIFF) {
130+
return a.getTextBoxRect().x < b.getTextBoxRect().x;
131+
}
132+
return a.getTextBoxRect().y < b.getTextBoxRect().y;
133+
});
120134

121135
TextBox currentLine = sortedBoxes[0];
122136

src/TextboxDetectionEAST.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace tik {
125125
if (boxes.empty()) return { mergedLines, boxes };
126126

127127
// Sort boxes by the top y-coordinate
128-
auto sortedBoxes = boxes;
128+
auto& sortedBoxes = boxes;
129129
for (auto& textBox : sortedBoxes)
130130
{
131131
textBox.calculateTextBoxLuminance(sRGB_LUT);
@@ -138,8 +138,8 @@ namespace tik {
138138

139139
int x = std::max(boxRect.x + textRect.x , 0);
140140
int y = std::max(boxRect.y + textRect.y , 0);
141-
int w = std::min(textRect.width , (img.cols - x));
142-
int h = std::min(textRect.height , (img.rows - y));
141+
int w = std::min(boxRect.width , (img.cols - x));
142+
int h = std::min(boxRect.height , (img.rows - y));
143143

144144
auto tb = cv::Rect{x , y, w, h };
145145
textBox = { tb,img };

vcpkg.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
"spscqueue",
99
"gtest",
1010
"spdlog",
11-
"benchmark"
11+
"benchmark",
12+
{
13+
"name": "ffmpeg",
14+
"features": [ "openh264", "openjpeg", "zlib" ]
15+
}
16+
1217
],
1318
"features": {
1419
"cuda-opencv": {

0 commit comments

Comments
 (0)