Commit 0c92ba08 authored by NicolaiO's avatar NicolaiO 🐼

introduced some changes in data format

parent 440d9ecf
Pipeline #19 skipped
......@@ -51,21 +51,27 @@ AiDataLoaderFile::AiDataLoaderFile(string folder, int fps)
for (vec::const_iterator it(v.begin()); it != v.end(); ++it)
{
string fileName((*it).filename().string());
long timestamp = atol(fileName.substr(6, 13).c_str());
if(firstTimestamp == -1)
{
firstTimestamp = timestamp;
}
if(spf * frameId <= timestamp - firstTimestamp)
tigers::AugmWrapperContainer container;
loadAiDataFromFile(it->string(), &container);
for(int i=0;i<container.wrapper_size();i++)
{
tigers::AugmWrapper wrapper;
loadAiDataFromFile(it->string(), &wrapper);
frames.push_back(wrapper);
frameId++;
long timestamp = atol(fileName.substr(6, 13).c_str());
if(firstTimestamp == -1)
{
firstTimestamp = timestamp;
}
if(spf * frameId <= timestamp - firstTimestamp)
{
frames.push_back(container.wrapper(i));
frameId++;
goto hacky_goto_ref_toberemoved; // FIXME
}
lastTimestamp = timestamp;
numFiles++;
}
lastTimestamp = timestamp;
numFiles++;
}
hacky_goto_ref_toberemoved:
cout << "Loaded " << frames.size() << "/" << numFiles
<< " frames for " << fps << "fps, lasting "
<< ((float) frames.size() / fps) << "s" << endl;
......@@ -132,7 +138,7 @@ tigers::AugmWrapper AiDataLoaderFile::getCurrent()
}
int AiDataLoaderFile::loadAiDataFromFile(string fileName,
tigers::AugmWrapper * wrapper)
tigers::AugmWrapperContainer * container)
{
fstream input(fileName, ios::in | ios::binary);
if (!input)
......@@ -140,7 +146,7 @@ int AiDataLoaderFile::loadAiDataFromFile(string fileName,
cout << fileName << ": File not found." << endl;
return -2;
}
else if (!(*wrapper).ParseFromIstream(&input))
else if (!(*container).ParseFromIstream(&input))
{
cerr << "Failed to parse." << endl;
return -1;
......
......@@ -9,6 +9,7 @@
#define AIDATALOADER_H_
#include "augm_wrapper.pb.h"
#include "augm_wrapper_container.pb.h"
#include <string>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
......@@ -36,7 +37,7 @@ public:
tigers::AugmWrapper getCurrent();
static int loadAiDataFromFile(std::string fileName,
tigers::AugmWrapper * wrapper);
tigers::AugmWrapperContainer * wrapper);
int fps = 0;
private:
......
......@@ -105,10 +105,14 @@ void AugmSSL::drawReferee(AugmWrapper aiDataWrapper, Mat& drawing, Mat H) {
void AugmSSL::drawAiData(AugmWrapper aiDataWrapper, Mat& drawing,
Transformer& transformer) {
// drawAllBots(aiDataWrapper, drawing, H);
circleRenderer.render(&aiDataWrapper, drawing, transformer);
lineRenderer.render(&aiDataWrapper, drawing, transformer);
pointRenderer.render(&aiDataWrapper, drawing, transformer);
textRenderer.render(&aiDataWrapper, drawing, transformer);
for(int i=0;i<aiDataWrapper.shapecollections_size();i++)
{
ShapeCollection shapeColl = aiDataWrapper.shapecollections(i);
circleRenderer.render(&shapeColl, drawing, transformer);
lineRenderer.render(&shapeColl, drawing, transformer);
pointRenderer.render(&shapeColl, drawing, transformer);
textRenderer.render(&shapeColl, drawing, transformer);
}
drawReferee(aiDataWrapper, drawing, transformer.H);
}
......@@ -186,6 +190,9 @@ AugmSSL::AugmSSL(AugmSSL_params params) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
this->params = params;
visibleShapeContainers.push_back("PATHS");
visibleShapeContainers.push_back("ROLE_NAMES");
}
AugmSSL::AugmSSL() {
......@@ -263,6 +270,8 @@ void AugmSSL::run() {
if (!init) {
stop();
} else {
initH = H.clone();
cout << "Change initH to " << initH << endl;
// std::cout << "H_after=" << std::endl << H << std::endl;
if (params.continuousTracking)
hDetector = lineSampler;
......@@ -288,7 +297,7 @@ void AugmSSL::run() {
int tWait = (int) ((1000 / (params.fps)) - (time * 1000));
if (tWait < 1)
tWait = 1;
int key = waitKey(tWait);
char key = waitKey(tWait);
if (key == 27) //wait for 'esc' key press 27
stop();
if (params.inputType != INPUT_TYPE_CAM
......
......@@ -84,6 +84,8 @@ private:
cv::Point2f rndTrans = cv::Point2f(0, 0);
std::vector<std::string> visibleShapeContainers;
void drawAiData(AugmWrapper aiDataWrapper, cv::Mat &drawing,
Transformer &transformer);
void drawReferee(AugmWrapper aiDataWrapper, cv::Mat &drawing, cv::Mat H);
......@@ -102,7 +104,9 @@ public:
void stop();
void processFrame();
cv::Mat H = cv::Mat(cv::Size(3, 3), CV_64F);bool active = true;
cv::Mat H = cv::Mat(cv::Size(3, 3), CV_64F);
cv::Mat initH = cv::Mat(cv::Size(3, 3), CV_64F);
bool active = true;
int frameNumber = 0;
cv::VideoCapture* cap = NULL;
};
......
......@@ -30,7 +30,7 @@ include(FindProtobuf)
find_package( Protobuf REQUIRED )
include_directories(${PROTOBUF_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS augm_wrapper.proto)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS augm_wrapper.proto augm_wrapper_container.proto)
add_executable( augmSSL MainWindow.cpp ${augmSSL_SOURCES} ${augmSSL_HEADERS_MOC} ${PROTO_SRCS} ${PROTO_HDRS} )
target_link_libraries( augmSSL ${OpenCV_LIBS} ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${QT_LIBRARIES} )
......
......@@ -17,30 +17,30 @@ CircleRenderer::CircleRenderer() {
CircleRenderer::~CircleRenderer() {
}
void CircleRenderer::render(AugmWrapper* aiDataWrapper, cv::Mat& drawing,
void CircleRenderer::render(ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer) {
std::vector<Point2f> vCirclePosReal;
std::vector<float> vRadius;
std::vector<float> vThickness;
std::vector<cv::Scalar> vColors;
for (int i = 0; i < aiDataWrapper->circles_size(); i++) {
Point2f circlePosField(aiDataWrapper->circles(i).vcenter().x(),
aiDataWrapper->circles(i).vcenter().y());
for (int i = 0; i < shapeCollection->circles_size(); i++) {
Point2f circlePosField(shapeCollection->circles(i).vcenter().x(),
shapeCollection->circles(i).vcenter().y());
float radius = aiDataWrapper->circles(i).radius();
float radius = shapeCollection->circles(i).radius();
radius = radius > .05 ? radius : .05;
float thickness = aiDataWrapper->circles(i).linewidth();
float thickness = shapeCollection->circles(i).linewidth();
for (int j = 0; j < 5; j++) {
vCirclePosReal.push_back(
(vSupportPoints.at(j) * radius) + circlePosField);
}
cv::Scalar color(aiDataWrapper->circles(i).color().b(),
aiDataWrapper->circles(i).color().g(),
aiDataWrapper->circles(i).color().r());
cv::Scalar color(shapeCollection->circles(i).color().b(),
shapeCollection->circles(i).color().g(),
shapeCollection->circles(i).color().r());
vRadius.push_back(radius);
vThickness.push_back(thickness);
vColors.push_back(color);
......
......@@ -15,7 +15,7 @@ private:
public:
CircleRenderer();
virtual ~CircleRenderer();
virtual void render(tigers::AugmWrapper* aiDataWrapper, cv::Mat& drawing, Transformer& transformer);
virtual void render(tigers::ShapeCollection* shapeCollection, cv::Mat& drawing, Transformer& transformer);
};
} /* namespace tigers */
......
......@@ -152,18 +152,18 @@ bool FieldInit::initializeField(cv::Mat& H, cv::Mat imgDst)
isInitialized = true;
setMouseCallback("init_Window", pullCorner, this);
// initCorners(imgDst.cols, imgDst.rows);
initCornersH(H);
initCorners(imgDst.cols, imgDst.rows);
// initCornersH(H);
drawRawField();
while (true)
{
int key = waitKey(100);
char key = waitKey(100);
void* wh = cvGetWindowHandle("init_Window");
if (!active || key == 27 || wh == NULL) //wait for 'esc' key press
{
isInitialized = false;
break;
} else if((key == 32 || key == 10) // space or enter
} else if((key == ' ' || key == 10) // space or enter
&& (std::count(vValidCorners.begin(), vValidCorners.end(), true) >= 4))
{
break;
......
......@@ -12,7 +12,7 @@ class IRenderer {
public:
virtual ~IRenderer() {
}
virtual void render(tigers::AugmWrapper* aiDataWrapper, cv::Mat& drawing,
virtual void render(tigers::ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer) = 0;
};
......
......@@ -50,12 +50,12 @@ LineRenderer::LineRenderer() {
LineRenderer::~LineRenderer() {
}
void LineRenderer::render(AugmWrapper* aiDataWrapper, cv::Mat& drawing,
void LineRenderer::render(ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer) {
std::vector<Point3f> vVectorTips; // index%2==0: start; index%2==1: end
std::vector<cv::Scalar> vColors;
for (int i = 0; i < aiDataWrapper->lines_size(); i++) {
tigers::Line l = aiDataWrapper->lines(i);
for (int i = 0; i < shapeCollection->lines_size(); i++) {
tigers::Line l = shapeCollection->lines(i);
Point3f pointFieldStart(l.vstart().x(), l.vstart().y(), l.vstart().z());
Point3f pointFieldEnd(l.vend().x(), l.vend().y(), l.vend().z());
cv::Scalar color(l.color().b(), l.color().g(), l.color().r());
......
......@@ -12,7 +12,7 @@ class LineRenderer: public IRenderer
public:
LineRenderer();
virtual ~LineRenderer();
virtual void render(tigers::AugmWrapper* aiDataWrapper, cv::Mat& drawing,
virtual void render(tigers::ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer);
};
......
......@@ -34,6 +34,7 @@ MainWindow::MainWindow() {
setWindowTitle(tr("Augmented SSL"));
readSettings();
memcpy(augm.initH.data, defH, 9 * sizeof(double));
inputChanged();
......@@ -181,7 +182,7 @@ void MainWindow::inputChanged() {
void MainWindow::stopPlayback() {
startstop->setText(tr("&Start"));
memcpy(defH, augm.H.data, 9 * sizeof(double));
memcpy(defH, augm.initH.data, 9 * sizeof(double));
augm.stop();
}
......
......@@ -17,14 +17,14 @@ PointRenderer::PointRenderer() {
PointRenderer::~PointRenderer() {
}
void PointRenderer::render(AugmWrapper* aiDataWrapper, cv::Mat& drawing,
void PointRenderer::render(ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer) {
std::vector<Point2f> vCirclePosReal;
std::vector<cv::Scalar> vColors;
std::vector<float> vThickness;
for (int i = 0; i < aiDataWrapper->points_size(); i++) {
tigers::Point c = aiDataWrapper->points(i);
for (int i = 0; i < shapeCollection->points_size(); i++) {
tigers::Point c = shapeCollection->points(i);
Point2f circlePosField(c.vpoint().x(), c.vpoint().y());
......
......@@ -15,7 +15,7 @@ private:
public:
PointRenderer();
virtual ~PointRenderer();
virtual void render(tigers::AugmWrapper* aiDataWrapper, cv::Mat& drawing, Transformer& transformer);
virtual void render(tigers::ShapeCollection* shapeCollection, cv::Mat& drawing, Transformer& transformer);
};
} /* namespace tigers */
......
......@@ -8,14 +8,14 @@ namespace tigers {
TextRenderer::TextRenderer() {
}
void TextRenderer::render(AugmWrapper* aiDataWrapper, cv::Mat& drawing,
void TextRenderer::render(ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer) {
std::vector < Point3f > vRatingPosReal;
std::vector < cv::Scalar > vColors;
std::vector < std::string > vStrings;
for (int i = 0; i < aiDataWrapper->texts_size(); i++) {
tigers::Text txt = aiDataWrapper->texts(i);
for (int i = 0; i < shapeCollection->texts_size(); i++) {
tigers::Text txt = shapeCollection->texts(i);
Point3f ratingPosField(txt.vpoint().x(), txt.vpoint().y(), 0);
......
......@@ -13,7 +13,7 @@ public:
TextRenderer();
virtual ~TextRenderer() {
}
virtual void render(tigers::AugmWrapper* aiDataWrapper, cv::Mat& drawing,
virtual void render(tigers::ShapeCollection* shapeCollection, cv::Mat& drawing,
Transformer& transformer);
};
......
......@@ -4,13 +4,19 @@ option java_package = "edu.dhbw.mannheim.tigers.sumatra.proto";
option java_outer_classname = "AugmWrapperProtos";
message AugmWrapper {
required Field field = 1;
repeated TrackedBot bots = 2;
repeated Line lines = 3;
repeated Circle circles = 4;
repeated Point points = 5;
optional Referee referee = 6;
repeated Text texts = 7;
required uint64 timestamp = 1;
required Field field = 2;
repeated TrackedBot bots = 3;
repeated ShapeCollection shapeCollections = 4;
optional Referee referee = 5;
}
message ShapeCollection {
required string identifier = 1;
repeated Line lines = 2;
repeated Circle circles = 3;
repeated Point points = 4;
repeated Text texts = 5;
}
message Field {
......
package tigers;
option java_package = "edu.dhbw.mannheim.tigers.sumatra.proto";
option java_outer_classname = "AugmWrapperContainerProtos";
import "augm_wrapper.proto";
message AugmWrapperContainer {
repeated AugmWrapper wrapper = 1;
}
\ No newline at end of file
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