All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Classes | Public Member Functions | Private Member Functions | Private Attributes
portrait_painter::GetLines Class Reference

This class is used to convert a picture (especially contours) into a sequence of lines. More...

#include <getLines.h>

List of all members.

Classes

struct  getLinesParams
 Struct to store internal parameter. More...
struct  Lines
 Struct which is used in connectLines, to identify a line at its start and and point. More...

Public Member Functions

void drawLines ()
 Draws the computed lines. This method is especially for testing.
void drawPR2 (float percentualHeightOfImage)
 Feature - Draws the signing PR2 on the right bottom of the picture.
 GetLines ()
 Constructor.
vector< pair< CvPoint2D32f,
vector< CvPoint2D32f > > > 
getLines (string &image)
 Computes and minimizes the lines of a given image and stores them into a vector.
vector< pair< CvPoint2D32f,
vector< CvPoint2D32f > > > 
scaleTo (size_t size, bool preserveRatio)
 Scales the given vector of lines to a specific quadratic image size.

Private Member Functions

vector< LinesconnectLines (size_t maxDistance, vector< pair< CvPoint2D32f, vector< CvPoint2D32f > > > &linesToConnect)
 Connects lines, which are near to each other.
void eraseDoubleLines (size_t maxDistance)
 Erases double lines.
void eraseNearestNeighbours (size_t maxDistance, size_t distance, vector< CvPoint2D32f > &absolutePoints)
 Submethod for erasing double lines.
void minimize ()
 Minimizes the vector of lines.
void minimizeLines (size_t maxDistance, size_t threshold)
 Minimizes the vector of lines, by replacing a sequence of lines by one line.
void readInFile (string &image, vector< string > *output)
 Uses potrace for getting the .plt of an image and reads the plt into a vector if strings.
void setConnectingParams (size_t maxDistanceBetweenLines)
 Setmethod for connecting lines. Do this before getLines(string&).
void setErasingParams (size_t maxDistanceBetweenPoints, size_t minDistanceWithinVector, float splitFactor, size_t minLineSize)
 Setmethod for erasing double lines. Do this before getLines(string&).
void setMinimizeLinesParams (size_t maxDistance, size_t threshold)
void setPotraceParams (size_t turdSize, bool invert)
 Setmethod for potrace. Do this before getLines(string&).

Private Attributes

int _size
 Size of the picture (set in scaleTo, else _size = -1).
string image_name
 Path and name of the image for saving it later at the same place.
vector< pair< CvPoint2D32f,
vector< CvPoint2D32f > > > 
lines
 Vector in which all lines are stored as vector<pair<[absolute point], vector<[relative point]> > >.
getLinesParams params
 Stores parameters.
Mat src
 Source image.

Detailed Description

This class is used to convert a picture (especially contours) into a sequence of lines.

For using this class OpenCV should be installed, which is already a dependency of this package. Moreover potrace is necessary, which is included in this package.

GetLines is, like already written, for extracting a sequence of lines out of an image. Therefore first potrace is used, a program which creates a hpgl-plotfile, in which each line is represented by an absolute point and the following relative points. Following this file is read out into a vector of strings to edit/minimize the lines later. These two steps are done in readInFile(string&, vector<string>*). The next step, which should be done is to interpret the vector of strings (absolute point, relative points, end/start of a line), which is done in getLines(string&) after reading in the file. Following the lines are minimized in minimize(). In this method the first thing to do is to erase double lines. Potrace itself returns a polygon for each line, you can see it as a contour of each line. Since our aim is to draw the contours, it is necessary to erase these double lines, which is done in eraseDoubleLines(size_t). After doing so, we can now connect lines, which are near to each other in connectLines(size_t, vector<pair<CvPoint2D32f, vector<CvPoint2D32f> > >&). To minimize the number of points which has to be drawn and to erase small artefacts, we can now minimize our lines in minimizeLines(size_t, size_t).

Depending of the implementation of the Painter it might be necessary to scale the image onto a quadratic szene. This is done in scaleTo(size_t, bool). As a small feature it is possible to sign the image with "PR2" in drawPR2(float).

For testing it is possible to draw the lines of the vector we have read in and edited in drawLines().

Definition at line 33 of file getLines.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 19 of file getLines.cpp.


Member Function Documentation

vector< GetLines::Lines > GetLines::connectLines ( size_t  maxDistance,
vector< pair< CvPoint2D32f, vector< CvPoint2D32f > > > &  linesToConnect 
) [private]

Connects lines, which are near to each other.

Parameters:
maxDistanceSpecifies the maximal euclidean distance between two lines to connect them.
linesToConnectSpecifies a vector containing the lines, which should be tested for connection.

In this method the struct Lines is used. To connect the lines it's important to distinguish those and to know start and end point. After getting these values we just have to look for each two lines if end-end, start-start or end-start points are near to each other. If this is the case we just connect these two lines.

Definition at line 376 of file getLines.cpp.

Draws the computed lines. This method is especially for testing.

This method draws the lines stored in the vector using OpenCV. Therefore it shouldn't be scaled before. OpenCV uses integers for drawing points and lines, following: the smaller the image, the more imprecise the output image.

Definition at line 578 of file getLines.cpp.

void GetLines::drawPR2 ( float  percentualHeightOfImage)

Feature - Draws the signing PR2 on the right bottom of the picture.

Parameters:
percentualHeightOfImageSpecifies the size of the signing as percentual height of the image.

This is just a feature and not necessary for real. In this method you can find the hard coded letters PR2, so the robot can sign his own image. The distance from bottom is given by a fourth of the specified size.

Definition at line 629 of file getLines.cpp.

void GetLines::eraseDoubleLines ( size_t  maxDistance) [private]

Erases double lines.

Parameters:
maxDistanceSee eraseNearestNeighbours(size_t, size_t, vector<CvPoint2D32f>&).

Every line in the image is kind of double. This happens, since potrace does return the contours of the lines and not the lines themself. In this method it's the aim to erase those double lines. Therefore we first try to delete the corresponding points on the "other side" of each line by computing the absolute points of each line and using the method eraseNearestNeighbours(size_t, size_t, vector<CvPoint2D32f>&). Doing this it's very probably that some artifacts are generated, like very long lines, which don't make sense. Do avoid this we erase lines which are just too long. Now it's quite possible that some lines are missing. I couldn't avoid this and in my opinion it's the lesser evil. It's for sure something which should be improved.

Definition at line 277 of file getLines.cpp.

void GetLines::eraseNearestNeighbours ( size_t  maxDistance,
size_t  distance,
vector< CvPoint2D32f > &  absolutePoints 
) [private]

Submethod for erasing double lines.

Parameters:
maxDistanceFor each point all points with a distance smaller than maxDistance are erased.
distanceJust those points are regarded, which have a specified distance from the point within the vector.
absolutePointsVector of absolute points in which near neighbours should be erased.

Definition at line 209 of file getLines.cpp.

vector< pair< CvPoint2D32f, vector< CvPoint2D32f > > > GetLines::getLines ( string &  image)

Computes and minimizes the lines of a given image and stores them into a vector.

Parameters:
imageThe path to the contour image, which should be stored as .bmp. If it isn't a bmp it's going to converted, but therefore ImageMagick should be installed.
Returns:
Returns the minimized vector of lines, given as a vector of pairs with absolute point and vector of relative points.

You can stucture this method as followed:

  • readInFile(string&, vector<string>*)
  • Interpret the vector<string>* returned by readInFile(string&, vector<string>*). The vector of strings contains different hpgl-commands, like PA (absolute point), PR (relative point), PD (Pen down), PU (Pen up) and so on. Depending on the previous command the points are read out and stored as absolute point or relative point. Whenever a PU or an end of a line is detected, the pair of detected absolute point and relative points is pushed back into the vector lines.
  • minimize()

Definition at line 32 of file getLines.cpp.

void GetLines::minimize ( ) [private]

Minimizes the vector of lines.

Minimizing is done by doing the following steps:

Definition at line 141 of file getLines.cpp.

void GetLines::minimizeLines ( size_t  maxDistance,
size_t  threshold 
) [private]

Minimizes the vector of lines, by replacing a sequence of lines by one line.

Parameters:
maxDistanceIf there are two points A and B within a line and their distance is smaller than maxDistance, all points between them are erased.
thresholdNumber of points of a line divided by threshold is the maximal number of points which are allowed to erase in one step.

This method does nothing else than erasing points, which are not necessary. So if there is a line from A to B and in the mid there is C with a minimal deviation, C is deleted. This is done as long as the distance from A to B is smaller than maxDistance and the number of points between A and B is smaller or equal than the size of the line divided through threshold (all points between A and B are deleted). The threshold is especially set, since point clouds, like eyes or noses can be a problem. Restricting the number of points which are allowed to erase, minimizes the problem of deleting necessary points.

Definition at line 166 of file getLines.cpp.

void GetLines::readInFile ( string &  image,
vector< string > *  output 
) [private]

Uses potrace for getting the .plt of an image and reads the plt into a vector if strings.

Parameters:
imagePath to the image, which should be a bmp in the best case. Else ImageMagick is needed to convert it to bmp.
outputThe content of the plt, which is created by potrace, splitted at every semicolon (= end of each command).

This method first tries to convert the image, if it has the wrong file format, since potrace can't handle images like pngs or jpegs. Following it creates the .plt using potrace and reads the file out.

Definition at line 483 of file getLines.cpp.

vector< pair< CvPoint2D32f, vector< CvPoint2D32f > > > GetLines::scaleTo ( size_t  size,
bool  preserveRatio 
)

Scales the given vector of lines to a specific quadratic image size.

Parameters:
sizeSpecifies the target size of the image in x and y-direction.
preserveRatioSpecifies if the ratio should preserved. If preserveRatio is true, an offset is created to preserve the relations, else the image is going to be distorted, if the original one wasn't quadratic.
Returns:
Returns the minimized and scaled vector of lines, given as a vector of pairs with absolute point and vector of relative points.

Definition at line 533 of file getLines.cpp.

void GetLines::setConnectingParams ( size_t  maxDistanceBetweenLines) [private]

Setmethod for connecting lines. Do this before getLines(string&).

Parameters:
maxDistanceBetweenLinesLines with a distance up to this size are going to be connected. (default: ImageHeight / 70)

Definition at line 728 of file getLines.cpp.

void GetLines::setErasingParams ( size_t  maxDistanceBetweenPoints,
size_t  minDistanceWithinVector,
float  splitFactor,
size_t  minLineSize 
) [private]

Setmethod for erasing double lines. Do this before getLines(string&).

Parameters:
maxDistanceBetweenPointsPoints with a distance up to this size are going to be erased. (default: 3)
minDistanceWithinVectorThese points need to have a distance of at least the size within the vector. (default: 2)
splitFactorAfter erasing there are some lines generated, which are too long. Sublines bigger than (linelength * splitFactor) / linesize are going to be erased. (default: 7)
minLineSizeBecause of the splitting there are some lines, which are too small, erase them, when they have a size smaller or equal minLineSize. (default: 1)
Warning:
Do not use minLineSize to erase small lines it won't work well. Use the turdSize parameter in setPotraceParams(size_t, bool) to do this.

Definition at line 720 of file getLines.cpp.

void GetLines::setMinimizeLinesParams ( size_t  maxDistance,
size_t  threshold 
) [private]

Setmethod for minimizeLines. Do this before getLines(string&).

Parameters:
maxDistanceIf there are two points A and B within a line and their distance is smaller than maxDistance, all points between them are erased (ImageHeight / 200).
thresholdNumber of points of a line divided by threshold is the maximal number of points which are allowed to erase in one step (default: 5).

Definition at line 732 of file getLines.cpp.

void GetLines::setPotraceParams ( size_t  turdSize,
bool  invert 
) [private]

Setmethod for potrace. Do this before getLines(string&).

Parameters:
turdSizeSuppress speckles of up to this size (default: 2).
invertInvert image before processing. Potrace expects a white background, so if it's black, you need to invert it. (default: true)

Definition at line 715 of file getLines.cpp.


Member Data Documentation

Size of the picture (set in scaleTo, else _size = -1).

Definition at line 190 of file getLines.h.

Path and name of the image for saving it later at the same place.

Definition at line 196 of file getLines.h.

vector<pair<CvPoint2D32f, vector<CvPoint2D32f> > > portrait_painter::GetLines::lines [private]

Vector in which all lines are stored as vector<pair<[absolute point], vector<[relative point]> > >.

Definition at line 187 of file getLines.h.

Stores parameters.

Definition at line 212 of file getLines.h.

Source image.

Definition at line 193 of file getLines.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


portrait_painter
Author(s): Niklas Meinzer, Ina Baumgarten
autogenerated on Wed Dec 26 2012 16:00:43