/*
 * mycv.h
 *
 *  Created on: 3. 5. 2015
 *      Author: Jirka
 */

#ifndef MYCV_H_
#define MYCV_H_

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"

#include "mycvdigitssegm.h"

#define ROW_FRES_MIN_ONES 10

#define GLOBAL_WIDTH 150

// processImage modes
#define M_ALL_IMAGE_PROC    0
#define M_FRAME_PROC        1

// VerHor direction
#define PROJ_VERTICAL       0
#define PROJ_HRIZONTAL      1

using namespace std;
using namespace cv;

struct sPoints4
{
//  Rectangle points
//    cornerLU____
//           |    |
//            ----cornerPD
    Point cornerLU;
    Point cornerPD;
};

class mycv
{
public:
	// Constructor
    mycv();
    // Destructor
    ~mycv();


    void detectFrame(const Mat &aSrc, Mat &aDst, vector<Rect> &aRects);
    void adjustFrame(const Mat &aSrc, Mat &aDst, vector<Rect> &aRects);

    void segmentDigits(const Mat &aSrc, Mat &aDst, vector<Mat> &aDigits, Mat &aPatt);



    void mycvRemoveHighLowObjects(const Mat &aSrc, Mat &aDst, uint aMaxVol,\
    							uint maxX, uint maxY, uint minX = 0,\
    							uint minY = 0, uint aMinVol = 0);

    int blockSize(int aNum, int aDiv);
    void mycvFindRed(const Mat &aSrc, Mat &aDst);
    void mycvRowClusters(const Mat &aImgThresh, Mat &aDst, vector<sPoints4> &aTxtBlocks);
    void mycvRowFreks(const Mat &aImage, vector<int> &avFreks);
    void mycvAdjustFrame(sPoints4 &aTextBlock, const Mat &aImgBlackMask);
    void mycvRemoveFalseFrames(vector<sPoints4> &aTextBlocks, Mat &aImgBlackMask, const Mat &aImgRedMask);
    Mat mycvRotateAcDominantLines(const Mat &aSrc1Gray, float &aAngle);
    void mycvReduseLines(vector<Vec4i> &aLinesCartesian, vector<Vec4i> &aLinesCartesianRed, float &aAngle);

    void mycvCheckDigit(const Mat &aSrc, vector<Rect> &aRects);
    int mycvVerHorProjection(const Mat &aSrc, Mat &aDst, const int aDir, vector<Point> &aSepar);
    Point mycvCheckHorizBorders(const Mat &aSrc, vector<Point> &aHorProj);
};
#endif /* MYCV_H_ */
