aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/CardProcessor.h
blob: 2eda83a1ed9b7e4e84a145cb4ca3610b04ea78d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <opencv2/opencv.hpp>
#include <opencv2/aruco.hpp>
#include <iostream>
#include <cmath> 

using namespace cv;
using namespace std;

#pragma once
class CardProcessor
{
	const int CV_QR_NORTH = 0;
	const int CV_QR_EAST = 1;
	const int CV_QR_SOUTH = 2;
	const int CV_QR_WEST = 3;

private:
	bool isInitialized;
	Mat gray;
	Mat edges;
	Mat traces;
	Mat qr, qr_raw, qr_gray, qr_thres;

	vector<vector<Point> > contours;
	vector<Vec4i> hierarchy;
	vector<Point> pointsseq;    //used to save the approximated sides of each contour

	int mark, A, B, C, D, F, top, right, bottom, median1, median2, outlier;
	float AB, BC, CA, dist, slope, areat, arear, areab, large, padding;

	int align, orientation;
private:
	void Initialize(Mat image);
	float cv_distance(Point2f P, Point2f Q);					// Get Distance between two points
	float cv_lineEquation(Point2f L, Point2f M, Point2f J);		// Perpendicular Distance of a Point J from line formed by Points L and M; Solution to equation of the line Val = ax+by+c 
	float cv_lineSlope(Point2f L, Point2f M, int& alignement);	// Slope of a line by two Points L and M on it; Slope of line, S = (x1 -x2) / (y1- y2)
	void cv_getVertices(vector<vector<Point> > contours, int c_id, float slope, vector<Point2f>& X);
	void cv_updateCorner(Point2f P, Point2f ref, float& baseline, Point2f& corner);
	void cv_updateCornerOr(int orientation, vector<Point2f> IN, vector<Point2f> &OUT);
	bool getIntersectionPoint(Point2f a1, Point2f a2, Point2f b1, Point2f b2, Point2f& intersection);
	float cross(Point2f v1, Point2f v2);
public:
	CardProcessor();
	~CardProcessor();
	vector<Point> GetQRVertices(Mat image);
	vector<Point> GetQRVertices4(Mat image);
	vector<Point> GetArcusVertices(Mat image);
	Mat ApplyHomography(Mat image,vector<Point> vertices, Size destination_size);
	Rect CropRect(Rect rect, Size size);
	Point GetRectCenter(Rect rect);
	Scalar GetRectMeanColor(Mat image, Rect rect);
	Mat GetImageRect(Mat image, Rect rect);
	Mat Diff(Mat image, int k);
	void DrawImage(Mat image,Mat draw, Rect rect);
	void DrawHistogram(Mat image);
};