/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/ml.hpp"
#include <limits>
#include <fstream>
#include <queue>
#if defined _MSC_VER && _MSC_VER == 1500
typedef int int_fast32_t;
#else
#ifndef INT32_MAX
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#endif
#endif
namespace cv
{
namespace text
{
using namespace cv::ml;
using namespace std;
using namespace cv::ml;
// Deletes a tree of ERStat regions starting at root. Used only
// internally to this implementation.
static void deleteERStatTree(ERStat* root) {
queue<ERStat*> to_delete;
to_delete.push(root);
while (!to_delete.empty()) {
ERStat* n = to_delete.front();
to_delete.pop();
ERStat* c = n->child;
if (c != NULL) {
to_delete.push(c);
ERStat* sibling = c->next;
while (sibling != NULL) {
to_delete.push(sibling);
sibling = sibling->next;
}
}
delete n;
}
}
ERStat::ERStat(int init_level, int init_pixel, int init_x, int init_y) : pixel(init_pixel),
level(init_level), area(0), perimeter(0), euler(0), probability(1.0),
parent(0), child(0), next(0), prev(0), local_maxima(0),
max_probability_ancestor(0), min_probability_ancestor(0)
{
rect = Rect(init_x,init_y,1,1);
raw_moments[0] = 0.0;
raw_moments[1] = 0.0;
central_moments[0] = 0.0;
central_moments[1] = 0.0;
central_moments[2] = 0.0;
crossings = new deque<int>();
crossings->push_back(0);
}
// derivative classes
// the class implementing the interface for the 1st and 2nd stages of Neumann and Matas algorithm
class CV_EXPORTS ERFilterNM : public ERFilter
{
public:
//Constructor
ERFilterNM();
//Destructor
~ERFilterNM() {}
float minProbability;
bool nonMaxSuppression;
float minProbabilityDiff;
// the key method. Takes image on input, vector of ERStat is output for the first stage,
// input/output - for the second one.
void run( InputArray image, vector<ERStat>& regions );
protected:
int thresholdDelta;
float maxArea;
float minArea;
Ptr<ERFilter::Callback> classifier;
// count of the rejected/accepted regions
int num_rejected_regions;
int num_accepted_regions;
public:
// set/get methods to set the algorithm properties,
void setCallback(const Ptr<ERFilter::Callback>& cb);
void setThresholdDelta(int thresholdDelta);
void setMinArea(float minArea);
void setMaxArea(float maxArea);
void setMinProbability(float minProbability);
void setMinProbabilityDiff(float minProbabilityDiff);
void setNonMaxSuppression(bool nonMaxSuppression);
int getNumRejected();
private:
// pointer to the input/output regions vector
vector<ERStat> *regions;
// image mask used for feature calculations
Mat region_mask;
// extract the component tree and store all the ER regions
void er_tree_extract( InputArray image );
// accumulate a pixel into an ER
void er_add_pixel( ERStat *parent, int x, int y, int non_boundary_neighbours,
int non_boundary_neighbours_horiz,
int d_C1, int d_C2, int d_C3 );
// merge an ER with its nested parent
void er_merge( ERStat *parent, ERStat *child );
// copy extracted regions into the output vector
ERStat* er_save( ERStat *er, ERStat *parent, ERStat *prev );
// recursively walk the tree and filter (remove) regions using the callback classifier
ERStat* er_tree_filter( InputArray image, ERStat *stat, ERStat *parent, ERStat *prev );
// recursively walk the tree selecting only regions with local maxima probability
ERStat* er_tree_nonmax_suppression( ERStat *er, ERStat *parent, ERStat *prev );
};
// default 1st stage classifier
class CV_EXPORTS ERClassifierNM1 : public ERFilter::Callback
{
public:
//Constructor
ERClassifierNM1(const string& filename);
// Destructor
~ERClassifierNM1() {}
// The classifier must return probability measure for the region.
double eval(const ERStat& stat);
private:
Ptr<Boost> boost;
};
// default 2nd stage classifier
class CV_EXPORTS ERClassifierNM2 : public ERFilter::Callback
{
public:
//constructor
ERClassifierNM2(const string& filename);
// Destructor
~ERClassifierNM2() {}
// The classifier must return probability measure for the region.
double eval(const ERStat& stat);
private:
Ptr<Boost> boost;
};
// default constructor
ERFilterNM::ERFilterNM()
{
thresholdDelta = 1;
minArea = 0.;
maxArea = 1.;
minProbability = 0.;
nonMaxSuppression = false;
minProbabilityDiff = 1.;
num_accepted_regions = 0;
num_rejected_regions = 0;
}
// the key method. Takes image on input, vector of ERStat is output for the first stage,
// input/output for the second one.
void ERFilterNM::run( InputArray image, vector<ERStat>& _regions )
{
// assert correct image type
CV_Assert( image.getMat().type() == CV_8UC1 );
regions = &_regions;
region_mask = Mat::zeros(image.getMat().rows+2, image.getMat().cols+2, CV_8UC1);
// if regions vector is empty we must extract the entire component tree
if ( regions->size() == 0 )
{
er_tree_extract( image );
if (nonMaxSuppression)
{
vector<ERStat> aux_regions;
regions->swap(aux_regions);
regions->reserve(aux_regions.size());
er_tree_nonmax_suppression( &aux_regions.front(), NULL, NULL );
aux_regions.clear();
}
}
else // if regions vector is already filled we'll just filter the current regions
{
// the tree root must have no parent
CV_Assert( regions->front().parent == NULL );
vector<E
没有合适的资源?快使用搜索试试~ 我知道了~
Extremal Region Text Detection-ERDetect-Demo
共14个文件
hpp:4个
xml:2个
cpp:2个
5星 · 超过95%的资源 需积分: 9 175 下载量 135 浏览量
2015-02-14
21:38:56
上传
评论 1
收藏 156KB ZIP 举报
温馨提示
Jiri Matas的方法:Real-Time Scene Text Localization and Recognition CVPR 2012 在OpenCV 3.0 contrib中的实现Demo,VC 2012+OpenCV3.0工程.论文和代码分析见博客:http://blog.csdn.net/hiterdu ERFilter源码地址:https://github.com/Itseez/opencv_contrib/tree/master/modules/text
资源推荐
资源详情
资源评论
收起资源包目录
ERDetect-Demo.zip (14个子文件)
ERDetect-Demo
ERDetect.sln 970B
ERDetect
precomp.hpp 2KB
trained_classifierNM1.xml 47KB
erfilter.cpp 149KB
text.hpp 5KB
erfilter.hpp 16KB
text_config.hpp 101B
scenetext01.jpg 95KB
trained_classifierNM2.xml 47KB
textdetection.cpp 5KB
ERDetect.vcxproj.filters 2KB
ERDetect.vcxproj 4KB
ERDetect.v12.suo 33KB
ERDetect.opensdf 16B
共 14 条
- 1
今哉
- 粉丝: 39
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页