mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
EAST: An Efficient and Accurate Scene Text Detector (https://arxiv.org/abs/1704.03155v2)
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include "precomp.hpp"
|
||||
#include "nms.inl.hpp"
|
||||
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace dnn
|
||||
@@ -28,6 +30,28 @@ void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores,
|
||||
NMSFast_(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rectOverlap);
|
||||
}
|
||||
|
||||
static inline float rotatedRectIOU(const RotatedRect& a, const RotatedRect& b)
|
||||
{
|
||||
std::vector<Point2f> inter, hull;
|
||||
int res = rotatedRectangleIntersection(a, b, inter);
|
||||
if (inter.empty() || res == INTERSECT_NONE)
|
||||
return 0.0f;
|
||||
if (res == INTERSECT_FULL)
|
||||
return 1.0f;
|
||||
convexHull(inter, hull);
|
||||
float interArea = contourArea(hull);
|
||||
return interArea / (a.size.area() + b.size.area() - interArea);
|
||||
}
|
||||
|
||||
void NMSBoxes(const std::vector<RotatedRect>& bboxes, const std::vector<float>& scores,
|
||||
const float score_threshold, const float nms_threshold,
|
||||
std::vector<int>& indices, const float eta, const int top_k)
|
||||
{
|
||||
CV_Assert(bboxes.size() == scores.size(), score_threshold >= 0,
|
||||
nms_threshold >= 0, eta > 0);
|
||||
NMSFast_(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rotatedRectIOU);
|
||||
}
|
||||
|
||||
CV__DNN_EXPERIMENTAL_NS_END
|
||||
}// dnn
|
||||
}// cv
|
||||
|
||||
@@ -538,6 +538,37 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// In case of resizing by factor.
|
||||
class ResizeBilinearSubgraph : public Subgraph
|
||||
{
|
||||
public:
|
||||
ResizeBilinearSubgraph()
|
||||
{
|
||||
int input = addNodeToMatch("");
|
||||
|
||||
int shape = addNodeToMatch("Shape", input);
|
||||
int stack = addNodeToMatch("Const");
|
||||
int stack_1 = addNodeToMatch("Const");
|
||||
int stack_2 = addNodeToMatch("Const");
|
||||
int strided_slice = addNodeToMatch("StridedSlice", shape, stack, stack_1, stack_2);
|
||||
int factorY = addNodeToMatch("Const");
|
||||
int mul = addNodeToMatch("Mul", strided_slice, factorY);
|
||||
|
||||
shape = addNodeToMatch("Shape", input);
|
||||
stack = addNodeToMatch("Const");
|
||||
stack_1 = addNodeToMatch("Const");
|
||||
stack_2 = addNodeToMatch("Const");
|
||||
strided_slice = addNodeToMatch("StridedSlice", shape, stack, stack_1, stack_2);
|
||||
int factorX = addNodeToMatch("Const");
|
||||
int mul_1 = addNodeToMatch("Mul", strided_slice, factorX);
|
||||
|
||||
int pack = addNodeToMatch("Pack", mul, mul_1);
|
||||
|
||||
addNodeToMatch("ResizeBilinear", input, pack);
|
||||
setFusedNode("ResizeBilinear", input, factorY, factorX);
|
||||
}
|
||||
};
|
||||
|
||||
void simplifySubgraphs(tensorflow::GraphDef& net)
|
||||
{
|
||||
std::vector<Ptr<Subgraph> > subgraphs;
|
||||
@@ -551,6 +582,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net)
|
||||
subgraphs.push_back(Ptr<Subgraph>(new L2NormalizeSubgraph()));
|
||||
subgraphs.push_back(Ptr<Subgraph>(new DeconvolutionValidKerasSubgraph()));
|
||||
subgraphs.push_back(Ptr<Subgraph>(new DeconvolutionSameKerasSubgraph()));
|
||||
subgraphs.push_back(Ptr<Subgraph>(new ResizeBilinearSubgraph()));
|
||||
|
||||
int numNodes = net.node_size();
|
||||
std::vector<int> matchedNodesIds;
|
||||
|
||||
@@ -767,6 +767,26 @@ void TFImporter::populateNet(Net dstNet)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == "Sub")
|
||||
{
|
||||
bool haveConst = false;
|
||||
for(int ii = 0; !haveConst && ii < layer.input_size(); ++ii)
|
||||
{
|
||||
Pin input = parsePin(layer.input(ii));
|
||||
haveConst = value_id.find(input.name) != value_id.end();
|
||||
}
|
||||
CV_Assert(haveConst);
|
||||
|
||||
layerParams.blobs.resize(1);
|
||||
blobFromTensor(getConstBlob(layer, value_id), layerParams.blobs[0]);
|
||||
layerParams.blobs[0] *= -1;
|
||||
|
||||
int id = dstNet.addLayer(name, "Shift", layerParams);
|
||||
layer_id[name] = id;
|
||||
|
||||
// one input only
|
||||
connect(layer_id, dstNet, parsePin(layer.input(0)), id, 0);
|
||||
}
|
||||
else if (type == "MatMul")
|
||||
{
|
||||
CV_Assert(layer.input_size() == 2);
|
||||
|
||||
Reference in New Issue
Block a user