Update with starting server

parent bb7fe1f7
......@@ -5,7 +5,7 @@
#-------------------------------------------------
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = VSSS
......@@ -29,14 +29,16 @@ SOURCES += \
main.cpp \
mainwindow.cpp \
backend.cpp \
global.cpp
global.cpp \
localserver.cpp
LIBS += -lstdc++fs
HEADERS += \
mainwindow.h \
global.h \
backend.h
backend.h \
localserver.h
FORMS += \
mainwindow.ui
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.1, 2019-10-12T14:24:16. -->
<!-- Written by QtCreator 4.8.1, 2019-10-27T01:09:54. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
This diff is collapsed.
......@@ -3,7 +3,8 @@
#include <chrono>
#include <opencv2/opencv.hpp>
#include <QTimer>
#include <QThread>
#include "global.h"
extern std::chrono::high_resolution_clock::time_point lastFrame;
extern QTimer timer;
extern double counter;
......@@ -13,9 +14,19 @@ void startCapture();
void calibration();
void gerenciador();
void getFrame();
void frameMod();
void findBall();
void detectAlly();
void findEnemies();
void frameMod(Global::ThreadVariables* var);
void findBall(Global::ThreadVariables* var);
void detectAlly(Global::ThreadVariables* var);
void findEnemies(Global::ThreadVariables* var);
void estrategia();
class Threader : public QThread{
public:
Threader();
void run();
};
extern std::vector<Threader*> threads;
#endif // BACKEND_HPP
#include <opencv2/opencv.hpp>
#include "global.h"
#include <mutex>
#include <QDebug>
using namespace std;
using namespace cv;
namespace Global {
int defaultImageHeight;
vector<vector<Point2d>> lastTriangles;
vector<vector<Point2d>> lastAllyFormats;
bool showAllyThreshold = true;
bool showAllyFThreshold = true;
Mutex mtx;
int cameraStatus = 0;
VideoCapture cap;
bool capActive = false;
Mat frame;
Mat correctedFrame;
Mat frameHSV;
Mat thresholdAllyF;
Mat thresholdAllyC;
Mat thresholdBall;
Mat thresholdEnemy;
int frames = 0;
int fps = 0;
bool frameModReady = true;
bool enemyDetectionReady = true;
bool ballDetectionReady = true;
bool allyDetectionReady = true;
bool strategyCompilerReady = true;
ThreadVariables::~ThreadVariables(){
Global::frame = frame;
Global::frameHSV = frameHSV;
Global::correctedFrame = correctedFrame;
Global::thresholdBall = thresholdBall;
Global::thresholdAllyF = thresholdAllyF;
Global::thresholdAllyC = thresholdAllyC;
Global::thresholdEnemy = thresholdEnemy;
Global::posRobots = posRobots;
Global::frenteRobots = frenteRobots;
Global::contornosRobots = contornosRobots;
Global::enemies = enemies;
Global::ballPosition = ballPosition;
}
ThreadVariables::ThreadVariables(){
posRobots = vector<Point2d>(3);
frenteRobots = vector<Point2d>(3);
contornosRobots = vector<vector<Point2d>>(3);
};
int defaultImageHeight;
vector<vector<Point2d>> lastTriangles;
vector<vector<Point2d>> lastAllyFormats;
bool showAllyThreshold = true;
bool showAllyFThreshold = true;
Mutex mtx;
int cameraStatus = 0;
VideoCapture cap;
bool capActive = false;
Mat frame;
Mat correctedFrame;
Mat frameHSV;
Mat thresholdAllyF;
Mat thresholdAllyC;
Mat thresholdBall;
Mat thresholdEnemy;
int frames = 0;
int fps = 0;
bool frameModReady = true;
bool enemyDetectionReady = true;
bool ballDetectionReady = true;
bool allyDetectionReady = true;
bool strategyCompilerReady = true;
int actualTab;
const double proporcao = 7.5;
const int comprimento = 150;
const int altura = 130;
const cv::Point2d marcas[] = {
cv::Point2d(25, 37.5),
cv::Point2d(65, 37.5),
cv::Point2d(105, 37.5),
cv::Point2d(25, 112.5),
cv::Point2d(65, 112.5),
cv::Point2d(105, 112.5)
};
const int alturaGol = 40;
const int alturaAG = 70;
const int larguraAG = 15;
int ballUH = 20;
int ballLH = 9;
int ballUS = 255;
int ballLS = 120;
int ballUV = 255;
int ballLV = 120;
cv::Point2d ballPosition(0, 0);
int actualTab; ///< Index atual do tab widget
/**
* @defgroup Global
* @brief Constantes e variáveis globais do software
* @addtogroup Global
* @{
* @defgroup Constantes
* @brief Constantes do software
* @addtogroup Constantes
* @{
*/
const double proporcao = 7.5; ///< Proporção do tamanho do campo para píxels, equivale a 1 cm
const int comprimento = 150; ///< Largura do campo em cm
const int altura = 130; ///< Altura do campo em cm
const cv::Point2d marcas[] = {
cv::Point2d(25, 37.5),
cv::Point2d(65, 37.5),
cv::Point2d(105, 37.5),
cv::Point2d(25, 112.5),
cv::Point2d(65, 112.5),
cv::Point2d(105, 112.5)
}; ///< Posição das marcações do campo
const int alturaGol = 40; ///< Altura do gol
const int alturaAG = 70; ///< Altura da área do gol
const int larguraAG = 15; ///< Largura da área do gol
/**
*@}
* @defgroup Bola
* @brief Variáveis utilizadas no reconhecimento da bola
* @addtogroup Bola
* @{
*/
int ballUH = 20; ///< Hue máximo
int ballLH = 9; ///< Hue mínimo
int ballUS = 255; ///< Saturation máximo
int ballLS = 120; ///< Saturation mínimo
int ballUV = 255; ///< Value máximo
int ballLV = 120; ///< Value mínimo
cv::Point2d ballPosition(0, 0);
///@}
int enemyUH = 60;
int enemyLH = 25;
int enemyUS = 255;
int enemyLS = 120;
int enemyUV = 255;
int enemyLV = 120;
double distanceTolerance = 15;
vector<cv::Point2d> enemies;
/**
* @defgroup Oponentes
* @brief Variáveis usadas no reconhecimento dos oponentes
* @addtogroup Oponentes
* @{
*/
int enemyUH = 60; ///< Hue máximo
int enemyLH = 25; ///< Hue mínimo
int enemyUS = 255; ///< Saturation máximo
int enemyLS = 120; ///< Saturation mínimo
int enemyUV = 255; ///< Value máximo
int enemyLV = 120; ///< Value mínimo
double distanceTolerance = 15; ///< Tolerância de distancia entre pontos para considerar como um robô
vector<cv::Point2d> enemies;
///@}
vector<Point2d> posRobots(3);
vector<Point2d> frenteRobots(3);
vector<vector<Point2d>> contornosRobots(3);
/**
* @defgroup Aliados
* @brief Vaiáveis de localização dos nossos robôs
* @addtogroup Aliados
* @{
*/
vector<Point2d> posRobots(3);
vector<Point2d> frenteRobots(3);
vector<vector<Point2d>> contornosRobots(3);
int allyUH = 150;
int allyLH = 100;
int allyUS = 255;
int allyLS = 120;
int allyUV = 255;
int allyLV = 120;
int allyUH = 150; ///< Hue máximo
int allyLH = 100; ///< Hue mínimo
int allyUS = 255; ///< Saturation máximo
int allyLS = 120; ///< Saturation mínimo
int allyUV = 255; ///< Value máximo
int allyLV = 120; ///< Value mínimo
int allyFUH = 180;
int allyFLH = 146;
int allyFUS = 255;
int allyFLS = 120;
int allyFUV = 255;
int allyFLV = 120;
int DISTANCE = 15;
int allyFUH = 180; ///< Hue máximo
int allyFLH = 146; ///< Hue mínimo
int allyFUS = 255; ///< Saturation máximo
int allyFLS = 120; ///< Saturation mínimo
int allyFUV = 255; ///< Value máximo
int allyFLV = 120; ///< Value mínimo
int DISTANCE = 15;
/**
* @}
* @defgroup Calibração
* @brief Variáveis usadas na calibração da câmera
* @addtogroup Calibração
* @{
*/
std::vector<cv::Point2d> corners(4); ///< Cantos do campo
cv::Point2d midLeft; ///< Centro esquerdo do campo
cv::Point2d midRight; ///< Centro direito do campo
double rotation = 0; ///< Angulo de rotação do campo
int confStatus = 0; ///< Estado atual da configuração
bool confConcluded = false; ///< Diz se a configuração foi terminada ou não
cv::Mat homography; ///< Homografia para correção de perspectiva
std::string calibrationFramesPath = "/home/kramer/frames"; ///< Caminho para os frames de calibração
std::vector<std::vector<cv::Point3f>> object_points; ///<Variável utilizada pela função de calibração
std::vector<std::vector<cv::Point2f>> image_points; ///<Variável utilizada pela função de calibração
std::vector<cv::Point2d> corners(4);
cv::Point2d midLeft;
cv::Point2d midRight;
double rotation = 0;
int confStatus = 0;
bool confConcluded = false;
cv::Mat homography;
std::string calibrationFramesPath = "/home/kramer/frames";
std::vector<std::vector<cv::Point3f>> object_points;
std::vector<std::vector<cv::Point2f>> image_points;
cv:: Mat intrinsic = cv::Mat(3, 3, CV_32FC1); ///<Variável utilizada pela função de calibração
cv::Mat distCoeffs; ///<Variável utilizada pela função de calibração
std::vector<cv::Mat> rvecs; ///<Variável utilizada pela função de calibração
std::vector<cv::Mat> tvecs; ///<Variável utilizada pela função de calibração
///@}
///@}
cv:: Mat intrinsic = cv::Mat(3, 3, CV_32FC1);
cv::Mat distCoeffs;
std::vector<cv::Mat> rvecs;
std::vector<cv::Mat> tvecs;
}
......@@ -2,10 +2,29 @@
#define GLOBAL_H
#include <opencv2/opencv.hpp>
#include <mutex>
#include <chrono>
using namespace std;
using namespace cv;
using namespace std::chrono;
namespace Global {
class ThreadVariables{
public:
ThreadVariables();
~ThreadVariables();
Mat frame;
Mat correctedFrame;
Mat frameHSV;
Mat thresholdBall;
Mat thresholdAllyF;
Mat thresholdAllyC;
Mat thresholdEnemy;
vector<Point2d> posRobots;
vector<Point2d> frenteRobots;
vector<vector<Point2d>> contornosRobots;
vector<Point2d> enemies;
Point2d ballPosition;
};
extern int defaultImageHeight;
extern vector<vector<Point2d>> lastTriangles;
extern vector<vector<Point2d>> lastAllyFormats;
......
#include "localserver.h"
#include <QTcpSocket>
#include <QDataStream>
#include <QJsonObject>
#include <chrono>
#include <QJsonDocument>
#include <QJsonArray>
#include <opencv2/opencv.hpp>
#include "global.h"
using namespace std::chrono;
using namespace std;
using namespace cv;
using namespace Global;
LocalServer::LocalServer(QObject *parent) : QTcpServer(parent)
{
mSocket = nullptr;
connect(this, &LocalServer::newConnection, [&](){
mSocket = nextPendingConnection();
});
}
void LocalServer::send()
{
if(mSocket)
{
high_resolution_clock::time_point p = high_resolution_clock::now();
milliseconds ms = duration_cast<milliseconds>(p.time_since_epoch());
seconds s = duration_cast<seconds>(ms);
std::time_t t = s.count();
std::size_t fractional_seconds = ms.count() % 1000;
QJsonObject j;
j["time"] = static_cast<int>(fractional_seconds);
QJsonArray arr;
for(size_t i = 0; i < 3; i++){
QJsonObject posRobot;
posRobot.insert("x", posRobots[i].x);
posRobot.insert("y", posRobots[i].y);
arr.insert(static_cast<int>(i), posRobot);
}
j.insert("posRobots", arr);
arr = QJsonArray();
for(size_t i = 0; i < 3; i++){
QJsonObject frenteRobot;
frenteRobot.insert("x", frenteRobots[i].x);
frenteRobot.insert("y", frenteRobots[i].y);
arr.insert(static_cast<int>(i), frenteRobot);
}
j.insert("frenteRobots", arr);
arr = QJsonArray();
for(size_t i = 0; i < 3; i++){
QJsonArray contornosRobot;
for(size_t j = 0; j < contornosRobots[i].size(); j++){
QJsonObject contorno;
contorno.insert("x", contornosRobots[i][j].x);
contorno.insert("y", contornosRobots[i][j].y);
contornosRobot.insert(static_cast<int>(j), contorno);
}
arr.insert(static_cast<int>(i), contornosRobot);
}
j.insert("contornosRobots", arr);
arr = QJsonArray();
for(size_t i = 0; i < 3; i++){
QJsonObject enemy;
enemy.insert("x", enemies[i].x);
enemy.insert("y", enemies[i].y);
arr.insert(static_cast<int>(i), enemy);
}
j.insert("enemies", arr);
QJsonObject ball;
ball.insert("x", ballPosition.x);
ball.insert("y", ballPosition.y);
j.insert("ballPosition", ball);
QTextStream D(mSocket);
QJsonDocument doc(j);
D << doc.toJson();
mSocket->flush();
}
}
#ifndef LOCALSERVER_H
#define LOCALSERVER_H
#include <QTcpServer>
class QTcpSocket;
class LocalServer : public QTcpServer
{
Q_OBJECT
public:
explicit LocalServer(QObject * parent = nullptr);
void send();
QTcpSocket *mSocket;
};
#endif // LOCALSERVER_H
This diff is collapsed.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "localserver.h"
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
......@@ -27,6 +27,7 @@ private slots:
private:
Ui::MainWindow *ui;
LocalServer *mLocalServer;
protected:
void closeEvent(QCloseEvent *event) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment