17#include <opencv2/highgui.hpp>
18#include <opencv2/video.hpp>
19#include <opencv2/imgproc.hpp>
20#include <opencv2/videostab.hpp>
21#include <opencv2/features2d.hpp>
23#include <opencv2/opencv.hpp>
24#include <opencv2/core/core.hpp>
25#include <opencv2/imgcodecs.hpp>
26#include <opencv2/videoio.hpp>
27#include <opencv2/core/ocl.hpp>
28#include <opencv2/cudaarithm.hpp>
29#include <opencv2/cudaimgproc.hpp>
30#include <opencv2/cudafilters.hpp>
31#include <opencv2/cudafeatures2d.hpp>
32#include <opencv2/cudawarping.hpp>
35#define MAT_TYPE cuda::GpuMat
36#define CV_NS cv::cuda::
53#include <QElapsedTimer>
58#include "Kilobot/kilobot.h"
62 MAT_TYPE full_warped_image;
71#define IDENTIFY_TIMEOUT 1
83 MY_HAPPY_OTHER_TRACKER,
117 std::vector<Point> pos;
138 explicit KilobotTracker(QPoint smallImageSize = QPoint(300,300), QObject *parent = 0);
144 int dummyVar2000 = 2000;
164 int cannyThresh = 129;
172 int kbLEDMinSize = kbMinSize/7;
173 int kbLEDMaxSize = kbMinSize*10/7;
174 int LEDhoughAcc = houghAcc;
175 int LEDcannyThresh = cannyThresh;
195 int cannyThresh = 115;
200 int kbLEDMinSize = kbMinSize;
201 int kbLEDMaxSize = kbMaxSize;
202 int LEDhoughAcc = houghAcc;
203 int LEDcannyThresh = cannyThresh;
207 int maxIDtoCheck = 100;
211 float morfiTrack_maxDisplacement = 12.0;
213 float smooth_fact = 0.5;
216 int height_x_adj = 10;
217 int height_y_adj = 10;
220 float redLThreshold = 1.0;
221 float redHThreshold = 0.0;
222 float greenLThreshold = 1.0;
223 float greenHThreshold = 0.0;
224 float blueLThreshold = 0.65;
225 float blueHThreshold = 0.0;
227 QList<Vec3f> detectedCircles;
229 bool debugBool =
false;
230 bool drawDebugBool =
false;
240 void setStitchedImage(QPixmap);
242 void capturedImage(cv::Mat);
244 void identifyKilo(uint8_t);
248 void clearMsgQueue();
250 void startExperiment(
bool);
252 void stopExperiment();
254 void toggleExpButton(
int);
256 void activateExpButtons(
int);
258 void setRuntimeIdentificationLock(
bool);
260 void kiloList(QVector<Kilobot *>);
262 void circlesToDrawSig(QVector < drawnCircle >);
304 void updateCropPoints(QRect cropRect);
306 QSize getImageSize();
315 void drawCircle(QPointF pos,
float r, QColor col,
int thickness = 2, std::string text =
"",
bool transparent =
false) {
317 this->circsToDraw.push_back(
drawnCircle {
Point(pos.x(),pos.y()), r_int, col, thickness, text, transparent});
320 void drawLine(std::vector<cv::Point> pos, QColor col,
int thickness = 2, std::string text =
"",
bool transparent =
false) {
321 this->linesToDraw.push_back(drawnLine {pos, col, thickness, text, transparent});
324 void clearDrawings() {
325 this->circsToDraw.clear();
326 this->linesToDraw.clear();
329 void drawCircleOnRecordedImage(QPointF pos,
float r, QColor col,
int thickness = 2, std::string text =
"") {
331 this->circsToDrawFinal.push_back(drawnCircle {Point(pos.x(),pos.y()), r_int, col, thickness, text});
334 void clearDrawingsOnRecordedImage() {
335 this->circsToDrawFinal.clear();
338 void saveImage(QString file) {
339 if (!finalImageCol.empty()) {
341 for (
int i = 0; i < this->circsToDrawFinal.size(); ++i) {
342 cv::circle(finalImageCol,this->circsToDrawFinal[i].pos, this->circsToDrawFinal[i].r,
343 Scalar(this->circsToDrawFinal[i].col.blue(),this->circsToDrawFinal[i].col.green(),this->circsToDrawFinal[i].col.red(),0.5),
344 this->circsToDrawFinal[i].thickness);
346 cv::imwrite(file.toStdString(),finalImageCol);
350 void saveVideoFrames(QString file,
unsigned int numofframes) {
351 savecamerasframes =
true;
352 savecamerasframesdir=file;
353 numberofframes=numofframes;
357 void setSourceType(
bool val) {
if (val) this->srcType = CAMERA;
else this->srcType = VIDEO;}
359 void setKbMin(
int val){this->kbMinSize = val;}
360 void setKbMax(
int val) {this->kbMaxSize = val;}
365 void setCannyThresh(
int val) {this->cannyThresh = val;}
366 void setHoughAcc(
int val) {this->houghAcc = val;}
368 void setKbLMin(
int val){this->kbLEDMinSize = val;}
369 void setKbLMax(
int val) {this->kbLEDMaxSize = val;}
370 void setLEDCannyThresh(
int val) {this->LEDcannyThresh = val;}
371 void setLEDHoughAcc(
int val) {this->LEDhoughAcc = val;}
374 void setLowRLED(
int val){this->redLThreshold = (double) val/100.0;}
375 void setLowGLED(
int val) {this->greenLThreshold = (double) val/100.0;}
376 void setLowBLED(
int val) {this->blueLThreshold = (double) val/100.0;}
377 void setHiRLED(
int val){this->redHThreshold = (double) val/100.0;}
378 void setHiGLED(
int val) {this->greenHThreshold = (double) val/100.0;}
379 void setHiBLED(
int val) {this->blueHThreshold = (double) val/100.0;}
382 void setHeightXSlider(
int val) {this->height_x_adj = val;}
383 void setHeightYSlider(
int val) {this->height_y_adj = val;}
385 void manuallyassignID(QPoint position);
394 void updateKilobotStates();
396 void getInitialKilobotStates();
398 void setTrackingType(
int t_type) {this->t_type = t_type;}
399 void updateExperimentBroadcastingState(
bool BroadcastingState)
401 experimentIsBroadcasting=BroadcastingState;
410 void showIds(
bool toggle) {this->showIDs = toggle;}
411 void detectred(
bool toggle) {this->m_detectred = toggle;}
412 void detectgreen(
bool toggle) {this->m_detectgreen = toggle;}
413 void detectblue(
bool toggle) {this->m_detectblue = toggle;}
414 void manualIDassignment(
bool toggle) {this->m_assignIDmanually = toggle;}
415 void enableRuntimeIdentification(
bool toggle) {this->m_runtimeIDenabled = toggle;}
418 void maxIDtoTry(QString maxIdStr) {this->maxIDtoCheck = maxIdStr.toInt();}
419 void setManualID(QString manID) {this->manualID = manID.toUInt();}
420 void setFlipangle(
double angle);
437 void trackKilobots();
443 void SETUPstitcher();
460 kiloLight getKiloBotLight(cuda::GpuMat channels[3],
Point centreOfBox,
int index);
461 kiloLight getKiloBotLightAdaptive(cuda::GpuMat channels[3],
Point centreOfBox,
int index);
462 void getKiloBotLights(Mat &display);
464 kiloLight getKiloBotLight(Mat channels[3],
Point centreOfBox,
int index);
465 kiloLight getKiloBotLightAdaptive(Mat channels[3],
Point centreOfBox,
int index);
476 Rect getKiloBotBoundingBox(
int index,
float scale);
482 void THREADSlaunch();
486 void identifyKilobot(
int);
487 void identifyKilobot(
int,
bool);
489 void runtimeIdentify();
491 void drawOverlay(Mat &);
493 void getDetectedCircles();
498 int t_type = POS | LED | ROT;
500 bool experimentIsBroadcasting=
false;
505 cuda::GpuMat finalImageB;
506 cuda::GpuMat finalImageG;
507 cuda::GpuMat finalImageR;
508 cuda::GpuMat fullImages[3];
511 cuda::GpuMat fullImagesHSV[3];
512 cuda::GpuMat grayImage, finalImageH, finalImageS, finalImageV;
521 MAT_TYPE warpedImages;
522 MAT_TYPE warpedMasks;
528 Point2f arenaCorners[4];
529 bool haveCalibration =
false;
539 QPoint smallImageSize;
546 bool loadFirstIm =
false;
548 srcDataType srcType = CAMERA;
551 trackerType trackType = MORFI_TRACKER;
553 QVector < Kilobot * > kilos;
555 QVector < float > kiloHeadings;
557 QVector < QPointF > kiloOldPos;
559 QVector < QVector < int > > exclusionTestsIndices;
561 float last_time = 0.0f;
567 uint found = IDENTIFY_TIMEOUT;
568 QVector < uint > foundIDs;
569 QVector < int > assignedCircles;
571 experimentType expType = VRK_EXP;
575 QVector < drawnCircle > circsToDraw;
576 QVector < drawnLine > linesToDraw;
577 QVector < drawnCircle > circsToDrawFinal;
582 Ptr<cuda::HoughCirclesDetector> hough;
583 bool detectHeter =
true;
584 Ptr<cuda::HoughCirclesDetector> houghLarger;
586 Ptr<cuda::HoughCirclesDetector> hough2;
589 Ptr<cuda::CLAHE> clahe;
590 Mat element = cv::getStructuringElement(MORPH_ELLIPSE,Size(7,7));
591 Ptr<cuda::Filter> dilateFilter;
596 bool m_detectred=
true;
597 bool m_detectgreen=
true;
598 bool m_detectblue=
true;
599 bool m_assignIDmanually=
false;
600 bool m_runtimeIDenabled=
true;
602 QVector <int> lost_count;
604 int m_runtimeIdentificationTimer = 0;
605 bool m_ongoingRuntimeIdentification =
false;
606 QVector <int> pendingRuntimeIdentification;
607 QElapsedTimer runtimeIDtimer;
610 bool savecamerasframes=
false;
611 unsigned int numberofframes;
612 QString savecamerasframesdir;
The KilobotTracker class.
Definition kilobottracker_copy.h:163
void SETUPloadCalibration()
loadCalibration Load the calibration matrices from an OpenCV FileStorage format
void showIds(bool toggle)
showIds
Definition robottracker.h:410
void errorMessage(QString)
errorMessage Qt signal to update the UI message QLabel
void LOOPiterate()
iterateTracker Use the existing feature matches to stitch the images and track the kilobots
void LOOPstartstop(int stage)
startLoop This slot is the target of the timeout on the QTimer tick, and fetches warped images from t...
void RefreshDisplayedImage()
RefreshDisplayedImage Refresh the displayed image on the GUI.
void setVideoDir(QString dir)
setVideoDir
Definition robottracker.h:392
void identifyKilobots()
identifyKilobots Find out what IDs the Kilobots have
void SETUPfindKilobots()
findKilobots Find the locations of Kilobots in the stitched image
The acquireThread class This thread acquires input data from a source, applies the local warps to the...
Definition kilobottracker_copy.cpp:42
Definition voronoii.cpp:9
Definition kilobottracker_copy.h:136
Definition kilobottracker_copy.h:145
Definition kilobottracker_copy.h:114
Definition kilobottracker_copy.h:119
Definition kilobottracker_copy.h:89