Skip to content

Commit

Permalink
Update LineSegmentaion.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir55 committed Dec 2, 2017
1 parent 32ffa1c commit f4119d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/LineSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ LineSegmentation::show_lines(string path) {
}

void
LineSegmentation::update_regions() {
LineSegmentation::generate_regions() {
this->line_regions = vector<Region>();

for (auto line : this->initial_lines) {
Expand Down Expand Up @@ -330,16 +330,16 @@ LineSegmentation::repair_lines() {
}

vector<cv::Mat>
LineSegmentation::get_lines() {
LineSegmentation::segment() {
this->pre_process_image();
this->find_contours();
this->generate_chunks();
this->get_initial_lines();
this->generate_initial_points();
this->show_lines("Initial_Lines.jpg");
this->update_regions();
this->generate_regions();
this->repair_lines();
this->update_regions();
this->generate_regions();
this->show_lines("Final_Lines.jpg");
return this->get_regions();
}
Expand Down Expand Up @@ -413,7 +413,7 @@ Chunk::calculate_histogram() {
}

int
Chunk::find_peaks_valleys() {
Chunk::find_peaks_valleys(map<int, Valley *>& map_valley) {
this->calculate_histogram();

// Detect Peaks.
Expand Down
28 changes: 23 additions & 5 deletions src/LineSegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Chunk
/// \param map_valley to fill it
/// \return int the average line height in this chunk.
int
find_peaks_valleys(map<int, Valley *>& map_valley);
find_peaks_valleys(map<int, Valley *> &map_valley);

private:
int index;
Expand Down Expand Up @@ -216,12 +216,14 @@ class LineSegmentation
public:
LineSegmentation(string path_of_image);

/// Generate the lines found in the saved image/
/// Generate the lines found in the saved image.
/// \return vector<cv::Mat> a vector containing each line as a 2D mat.
vector<cv::Mat>
get_lines();
segment();

private:
string image_path;
///< Path of the image.
cv::Mat color_img;
///< Used for debugging only.
cv::Mat grey_img;
Expand All @@ -230,6 +232,10 @@ class LineSegmentation
///< The preprocessed image.
vector<Chunk> chunks;
///< The image chunks.
map<int, Chunk *> chunk_map;
///< Map the Chunk id and its corresponding Chunk pointer
map<int, Valley *> map_valley;
///< Map the Valley id and its corresponding Valley pointer.
vector<Line> initial_lines;
///< The initial lines.
vector<Region> line_regions;
Expand All @@ -238,6 +244,13 @@ class LineSegmentation
/// The handwritten components found in the binary image.
int avg_line_height;
///< The average height of lines in the image.
int avg_space_height;
///< The average height of white spaces in the image.
// ToDo @Samir55 add CHUNKS_TO_BE_PROCESSED and chunk_width when needed.

/// Read the image file into CV matrix
void
read_image();

/// Apply OTSU threshold and Binarization to the grey image.
void
Expand All @@ -259,17 +272,22 @@ class LineSegmentation
void
generate_initial_points();

/// Update the lines regions (A 2D mat describing each line in the image).
/// Generate the lines regions (A 2D mat describing each line in the image).
void
update_regions();
generate_regions();

/// ToDo @Samir55.
vector<cv::Mat>
get_regions();

/// Use statistical approach to repair the initial lines (refer to the paper).
void
repair_lines();

/// Check if the component belongs to the above region
bool
component_belongs_to_above_region(Line &, Rect &);

/// Draw the lines on the original color image for debugging.
/// \param path string the path of the output image.
void
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
int main() {
string img_path = "../img/A.jpg";
LineSegmentation line_segmentation(img_path);
vector<cv::Mat> lines = line_segmentation.get_lines();
vector<cv::Mat> lines = line_segmentation.segment();
return 0;
}

0 comments on commit f4119d6

Please sign in to comment.