|
|
|
@ -20,7 +20,6 @@
|
|
|
|
|
#include <pybind11/stl_bind.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <queue>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
@ -28,12 +27,14 @@
|
|
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using cv::vector;
|
|
|
|
|
using std::queue;
|
|
|
|
|
using cv::Mat;
|
|
|
|
|
using cv::Point;
|
|
|
|
|
|
|
|
|
|
namespace py = pybind11;
|
|
|
|
|
|
|
|
|
|
namespace pse_adaptor {
|
|
|
|
|
void get_kernals(const int *data, vector<int> data_shape, const vector<Mat> &kernals) {
|
|
|
|
|
void get_kernals(const int *data, vector<int64> data_shape, vector<Mat> *kernals) {
|
|
|
|
|
for (int i = 0; i < data_shape[0]; ++i) {
|
|
|
|
|
Mat kernal = Mat::zeros(data_shape[1], data_shape[2], CV_8UC1);
|
|
|
|
|
for (int x = 0; x < kernal.rows; ++x) {
|
|
|
|
@ -41,15 +42,14 @@ namespace pse_adaptor {
|
|
|
|
|
kernal.at<char>(x, y) = data[i * data_shape[1] * data_shape[2] + x * data_shape[2] + y];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
kernals.emplace_back(kernal);
|
|
|
|
|
kernals->emplace_back(kernal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void growing_text_line(const vector, const vector<vector<>> &text_line, float min_area) {
|
|
|
|
|
void growing_text_line(const vector<Mat> &kernals, vector<vector<int>> *text_line, float min_area) {
|
|
|
|
|
Mat label_mat;
|
|
|
|
|
int label_num = connectedComponents(kernals[kernals.size() - 1], label_mat, 4);
|
|
|
|
|
vector<int> area(label_num + 1, 0)
|
|
|
|
|
memset_s(area, 0, sizeof(area));
|
|
|
|
|
vector<int> area(label_num + 1, 0);
|
|
|
|
|
for (int x = 0; x < label_mat.rows; ++x) {
|
|
|
|
|
for (int y = 0; y < label_mat.cols; ++y) {
|
|
|
|
|
int label = label_mat.at<int>(x, y);
|
|
|
|
@ -69,7 +69,7 @@ namespace pse_adaptor {
|
|
|
|
|
queue.push(point);
|
|
|
|
|
row[y] = label;
|
|
|
|
|
}
|
|
|
|
|
text_line.emplace_back(row);
|
|
|
|
|
text_line->emplace_back(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dx[] = {-1, 1, 0, 0};
|
|
|
|
@ -81,20 +81,20 @@ namespace pse_adaptor {
|
|
|
|
|
queue.pop();
|
|
|
|
|
int x = point.x;
|
|
|
|
|
int y = point.y;
|
|
|
|
|
int label = text_line[x][y];
|
|
|
|
|
int label = text_line->at(x)[y];
|
|
|
|
|
bool is_edge = true;
|
|
|
|
|
for (int d = 0; d < 4; ++d) {
|
|
|
|
|
int tmp_x = x + dx[d];
|
|
|
|
|
int tmp_y = y + dy[d];
|
|
|
|
|
|
|
|
|
|
if (tmp_x < 0 || tmp_x >= (static_cast)<int>text_line.size()) continue;
|
|
|
|
|
if (tmp_y < 0 || tmp_y >= (static_cast)<int>text_line[1].size()) continue;
|
|
|
|
|
if (tmp_x < 0 || tmp_x >= static_cast<int>(text_line->size())) continue;
|
|
|
|
|
if (tmp_y < 0 || tmp_y >= static_cast<int>(text_line->at(1).size())) continue;
|
|
|
|
|
if (kernals[kernal_id].at<char>(tmp_x, tmp_y) == 0) continue;
|
|
|
|
|
if (text_line[tmp_x][tmp_y] > 0) continue;
|
|
|
|
|
if (text_line->at(tmp_x)[tmp_y] > 0) continue;
|
|
|
|
|
|
|
|
|
|
Point point_tmp(tmp_x, tmp_y);
|
|
|
|
|
queue.push(point_tmp);
|
|
|
|
|
text_line[tmp_x][tmp_y] = label;
|
|
|
|
|
text_line->at(tmp_x)[tmp_y] = label;
|
|
|
|
|
is_edge = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -110,9 +110,9 @@ namespace pse_adaptor {
|
|
|
|
|
auto buf = quad_n9.request();
|
|
|
|
|
auto data = static_cast<int *>(buf.ptr);
|
|
|
|
|
vector<Mat> kernals;
|
|
|
|
|
get_kernals(data, buf.shape, kernals);
|
|
|
|
|
get_kernals(data, buf.shape, &kernals);
|
|
|
|
|
vector<vector<int>> text_line;
|
|
|
|
|
growing_text_line(kernals, text_line, min_area);
|
|
|
|
|
growing_text_line(kernals, &text_line, min_area);
|
|
|
|
|
|
|
|
|
|
return text_line;
|
|
|
|
|
}
|
|
|
|
|