2018-12-14 17:04:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 dimercur
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IMG_H__
|
|
|
|
#define __IMG_H__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <list>
|
2018-12-19 09:15:42 +01:00
|
|
|
#include <string>
|
2018-12-14 17:04:42 +01:00
|
|
|
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
|
|
#include <opencv2/core.hpp>
|
|
|
|
|
|
|
|
#ifdef __WITH_ARUCO__
|
|
|
|
#include <opencv2/aruco/dictionary.hpp>
|
|
|
|
#include <opencv2/aruco/charuco.hpp>
|
2019-01-09 16:32:16 +01:00
|
|
|
//#include <opencv2/aruco.hpp>
|
2018-12-14 17:04:42 +01:00
|
|
|
#include <opencv2/core/mat.hpp>
|
2019-01-09 16:32:16 +01:00
|
|
|
|
2018-12-14 17:04:42 +01:00
|
|
|
#endif // __WITH_ARUCO__
|
|
|
|
|
|
|
|
#define ARENA_NOT_DETECTED -1
|
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
using namespace std;
|
|
|
|
|
2018-12-14 17:04:42 +01:00
|
|
|
typedef cv::Mat ImageMat;
|
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
typedef vector<unsigned char> Jpg;
|
2018-12-14 17:04:42 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
typedef struct {
|
2018-12-14 17:04:42 +01:00
|
|
|
cv::Point2f center;
|
|
|
|
cv::Point2f direction;
|
|
|
|
float angle;
|
|
|
|
int robotId;
|
2018-12-19 09:15:42 +01:00
|
|
|
} Position;
|
2018-12-14 17:04:42 +01:00
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
class Arena {
|
2018-12-14 17:04:42 +01:00
|
|
|
public:
|
2019-01-04 16:55:48 +01:00
|
|
|
Arena() {}
|
2018-12-14 17:04:42 +01:00
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
cv::Rect arena;
|
|
|
|
bool IsEmpty();
|
2018-12-14 17:04:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Img {
|
|
|
|
public:
|
2019-01-09 16:32:16 +01:00
|
|
|
ImageMat img;
|
|
|
|
|
2018-12-14 17:04:42 +01:00
|
|
|
Img(ImageMat imgMatrice);
|
2018-12-19 09:15:42 +01:00
|
|
|
|
|
|
|
string ToString();
|
|
|
|
Img* Copy();
|
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
Jpg ToJpg();
|
|
|
|
Arena SearchArena();
|
2018-12-14 17:04:42 +01:00
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
int DrawRobot(Position robot);
|
|
|
|
int DrawAllRobots(std::list<Position> robots);
|
2019-01-09 16:32:16 +01:00
|
|
|
int DrawArena(Arena arenaToDraw);
|
|
|
|
std::list<Position> SearchRobot(Arena arena);
|
|
|
|
|
2018-12-14 17:04:42 +01:00
|
|
|
#ifdef __WITH_ARUCO__
|
2019-01-09 16:32:16 +01:00
|
|
|
list<Position> SearchAruco(Arena arena);
|
|
|
|
cv::Ptr<cv::aruco::Dictionary> dictionary;
|
2018-12-14 17:04:42 +01:00
|
|
|
#endif // __WITH_ARUCO__
|
|
|
|
private:
|
|
|
|
#ifdef __WITH_ARUCO__
|
2019-01-09 16:32:16 +01:00
|
|
|
cv::Point2f FindArucoCenter(std::vector<cv::Point2f> aruco);
|
|
|
|
cv::Point2f FindArucoDirection(std::vector<cv::Point2f> aruco);
|
2018-12-14 17:04:42 +01:00
|
|
|
#endif // __WITH_ARUCO__
|
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
float CalculAngle(Position robots);
|
|
|
|
float CalculAngle2(cv::Point2f pt1, cv::Point2f pt2);
|
|
|
|
float EuclideanDistance(cv::Point2f p, cv::Point2f q);
|
2019-01-09 16:32:16 +01:00
|
|
|
ImageMat CropArena(Arena arena);
|
2018-12-14 17:04:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //__IMG_H__
|