~matthill/openalpr/master

« back to all changes in this revision

Viewing changes to src/openalpr/segmentation/charactersegmenter.h

  • Committer: Matt Hill
  • Date: 2016-07-02 14:27:26 UTC
  • Revision ID: git-v1:b6469b015e923bf7d15b5c823964d29c1b860f17
Moved segmentation code to inside OCR

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2015 OpenALPR Technology, Inc.
3
 
 * Open source Automated License Plate Recognition [http://www.openalpr.com]
4
 
 *
5
 
 * This file is part of OpenALPR.
6
 
 *
7
 
 * OpenALPR is free software: you can redistribute it and/or modify
8
 
 * it under the terms of the GNU Affero General Public License
9
 
 * version 3 as published by the Free Software Foundation
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU Affero General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Affero General Public License
17
 
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 
*/
19
 
 
20
 
#ifndef OPENALPR_CHARACTERSEGMENTER_H
21
 
#define OPENALPR_CHARACTERSEGMENTER_H
22
 
 
23
 
#include "opencv2/imgproc/imgproc.hpp"
24
 
#include "constants.h"
25
 
#include "binarize_wolf.h"
26
 
#include "utility.h"
27
 
#include "histogramvertical.h"
28
 
#include "config.h"
29
 
#include "textdetection/textcontours.h"
30
 
#include "pipeline_data.h"
31
 
 
32
 
namespace alpr
33
 
{
34
 
 
35
 
 
36
 
  const cv::Scalar COLOR_DEBUG_EDGE(0,0,255); // Red
37
 
  const cv::Scalar COLOR_DEBUG_SPECKLES(0,0,255); // Red
38
 
  const cv::Scalar COLOR_DEBUG_MIN_HEIGHT(255,0,0); // Blue
39
 
  const cv::Scalar COLOR_DEBUG_MIN_AREA(255,0,0); // Blue
40
 
  const cv::Scalar COLOR_DEBUG_FULLBOX(255,255,0); // Blue-green
41
 
  const cv::Scalar COLOR_DEBUG_COLORFILTER(255,0,255); // Magenta
42
 
  const cv::Scalar COLOR_DEBUG_EMPTYFILTER(0,255,255); // Yellow
43
 
 
44
 
  class CharacterSegmenter
45
 
  {
46
 
 
47
 
    public:
48
 
      CharacterSegmenter(PipelineData* pipeline_data);
49
 
      virtual ~CharacterSegmenter();
50
 
 
51
 
      int confidence;
52
 
 
53
 
 
54
 
    private:
55
 
      Config* config;
56
 
      PipelineData* pipeline_data;
57
 
 
58
 
 
59
 
      LineSegment top;
60
 
      LineSegment bottom;
61
 
 
62
 
      std::vector<cv::Mat> imgDbgGeneral;
63
 
      std::vector<cv::Mat> imgDbgCleanStages;
64
 
 
65
 
      cv::Mat getCharBoxMask(cv::Mat img_threshold, std::vector<cv::Rect> charBoxes);
66
 
 
67
 
      void removeSmallContours(std::vector<cv::Mat> thresholds, float avgCharHeight, TextLine textLine);
68
 
 
69
 
      std::vector<cv::Rect> getHistogramBoxes(HistogramVertical histogram, float avgCharWidth, float avgCharHeight, float* score);
70
 
      std::vector<cv::Rect> getBestCharBoxes(cv::Mat img, std::vector<cv::Rect> charBoxes, float avgCharWidth);
71
 
      
72
 
      int getCharGap(cv::Rect leftBox, cv::Rect rightBox);
73
 
      std::vector<cv::Rect> combineCloseBoxes( std::vector<cv::Rect> charBoxes);
74
 
 
75
 
      std::vector<cv::Rect> get1DHits(cv::Mat img, int yOffset);
76
 
 
77
 
      void cleanCharRegions(std::vector<cv::Mat> thresholds, std::vector<cv::Rect> charRegions);
78
 
      void cleanBasedOnColor(std::vector<cv::Mat> thresholds, cv::Mat colorMask, std::vector<cv::Rect> charRegions);
79
 
      std::vector<cv::Rect> filterMostlyEmptyBoxes(std::vector<cv::Mat> thresholds, const  std::vector<cv::Rect> charRegions);
80
 
      cv::Mat filterEdgeBoxes(std::vector<cv::Mat> thresholds, const std::vector<cv::Rect> charRegions, float avgCharWidth, float avgCharHeight);
81
 
 
82
 
      int getLongestBlobLengthBetweenLines(cv::Mat img, int col);
83
 
 
84
 
      int isSkinnyLineInsideBox(cv::Mat threshold, cv::Rect box, std::vector<std::vector<cv::Point> > contours, std::vector<cv::Vec4i> hierarchy, float avgCharWidth, float avgCharHeight);
85
 
 
86
 
      std::vector<cv::Rect> convert1DHitsToRect(std::vector<std::pair<int, int> >  hits, LineSegment top, LineSegment bottom);
87
 
  };
88
 
 
89
 
}
90
 
 
91
 
#endif // OPENALPR_CHARACTERSEGMENTER_H