162class KilobotTracker :
public QObject
167 explicit KilobotTracker(QPoint smallImageSize = QPoint(300,300), QObject *parent = 0);
172 int dummyVar2000 = 1000;
183 int cannyThresh = 90;
185 int kbLEDMinSize = kbMinSize/7;
186 int kbLEDMaxSize = kbMinSize*10/7;
187 int LEDhoughAcc = houghAcc;
188 int LEDcannyThresh = cannyThresh;
190 int maxIDtoCheck = 100;
193 int height_x_adj = 10;
194 int height_y_adj = 10;
197 float redLThreshold = 0.75;
198 float redHThreshold = 0.0;
199 float greenLThreshold = 0.56;
200 float greenHThreshold = 0.75;
201 float blueLThreshold = 0.65;
202 float blueHThreshold = 0.0;
204 QList<Vec3f> detectedCircles;
206 bool debugBool =
false;
215 void setStitchedImage(QPixmap);
217 void capturedImage(cv::Mat);
219 void identifyKilo(uint8_t);
223 void clearMsgQueue();
225 void startExperiment(
bool);
227 void stopExperiment();
229 void toggleExpButton(
int);
231 void activateExpButtons(
int);
233 void setRuntimeIdentificationLock(
bool);
235 void kiloList(QVector<Kilobot *>);
237 void circlesToDrawSig(QVector < drawnCircle >);
279 void updateCropPoints(QRect cropRect);
281 QSize getImageSize();
290 void drawCircle(QPointF pos,
float r, QColor col,
int thickness = 2, std::string text =
"",
bool transparent =
false) {
292 this->circsToDraw.push_back(
drawnCircle {
Point(pos.x(),pos.y()), r_int, col, thickness, text, transparent});
295 void drawLine(std::vector<cv::Point> pos, QColor col,
int thickness = 2, std::string text =
"",
bool transparent =
false) {
296 this->linesToDraw.push_back(drawnLine {pos, col, thickness, text, transparent});
299 void clearDrawings() {
300 this->circsToDraw.clear();
301 this->linesToDraw.clear();
304 void drawCircleOnRecordedImage(QPointF pos,
float r, QColor col,
int thickness = 2, std::string text =
"") {
306 this->circsToDrawFinal.push_back(drawnCircle {Point(pos.x(),pos.y()), r_int, col, thickness, text});
309 void clearDrawingsOnRecordedImage() {
310 this->circsToDrawFinal.clear();
313 void saveImage(QString file) {
314 if (!finalImageCol.empty()) {
316 for (
int i = 0; i < this->circsToDrawFinal.size(); ++i) {
317 cv::circle(finalImageCol,this->circsToDrawFinal[i].pos, this->circsToDrawFinal[i].r,
318 Scalar(this->circsToDrawFinal[i].col.blue(),this->circsToDrawFinal[i].col.green(),this->circsToDrawFinal[i].col.red(),0.5),
319 this->circsToDrawFinal[i].thickness);
321 cv::imwrite(file.toStdString(),finalImageCol);
325 void saveVideoFrames(QString file,
unsigned int numofframes) {
326 savecamerasframes =
true;
327 savecamerasframesdir=file;
328 numberofframes=numofframes;
332 void setSourceType(
bool val) {
if (val) this->srcType = CAMERA;
else this->srcType = VIDEO;}
334 void setKbMin(
int val){this->kbMinSize = val;}
335 void setKbMax(
int val) {this->kbMaxSize = val;}
336 void setCannyThresh(
int val) {this->cannyThresh = val;}
337 void setHoughAcc(
int val) {this->houghAcc = val;}
339 void setKbLMin(
int val){this->kbLEDMinSize = val;}
340 void setKbLMax(
int val) {this->kbLEDMaxSize = val;}
341 void setLEDCannyThresh(
int val) {this->LEDcannyThresh = val;}
342 void setLEDHoughAcc(
int val) {this->LEDhoughAcc = val;}
345 void setLowRLED(
int val){this->redLThreshold = (double) val/100.0;}
346 void setLowGLED(
int val) {this->greenLThreshold = (double) val/100.0;}
347 void setLowBLED(
int val) {this->blueLThreshold = (double) val/100.0;}
348 void setHiRLED(
int val){this->redHThreshold = (double) val/100.0;}
349 void setHiGLED(
int val) {this->greenHThreshold = (double) val/100.0;}
350 void setHiBLED(
int val) {this->blueHThreshold = (double) val/100.0;}
353 void setHeightXSlider(
int val) {this->height_x_adj = val;}
354 void setHeightYSlider(
int val) {this->height_y_adj = val;}
356 void manuallyassignID(QPoint position);
365 void updateKilobotStates();
367 void getInitialKilobotStates();
369 void setTrackingType(
int t_type) {this->t_type = t_type;}
370 void updateExperimentBroadcastingState(
bool BroadcastingState)
372 experimentIsBroadcasting=BroadcastingState;
381 void showIds(
bool toggle) {this->showIDs = toggle;}
382 void detectred(
bool toggle) {this->m_detectred = toggle;}
383 void detectgreen(
bool toggle) {this->m_detectgreen = toggle;}
384 void detectblue(
bool toggle) {this->m_detectblue = toggle;}
385 void manualIDassignment(
bool toggle) {this->m_assignIDmanually = toggle;}
386 void enableRuntimeIdentification(
bool toggle) {this->m_runtimeIDenabled = toggle;}
389 void maxIDtoTry(QString maxIdStr) {this->maxIDtoCheck = maxIdStr.toInt();}
390 void setManualID(QString manID) {this->manualID = manID.toUInt();}
391 void setFlipangle(
double angle);
408 void trackKilobots();
414 void SETUPstitcher();
431 kiloLight getKiloBotLight(cuda::GpuMat channels[3], Point centreOfBox,
int index);
432 kiloLight getKiloBotLightAdaptive(cuda::GpuMat channels[3], Point centreOfBox,
int index);
433 void getKiloBotLights(Mat &display);
435 kiloLight getKiloBotLight(Mat channels[3], Point centreOfBox,
int index);
436 kiloLight getKiloBotLightAdaptive(Mat channels[3], Point centreOfBox,
int index);
447 Rect getKiloBotBoundingBox(
int index,
float scale);
453 void THREADSlaunch();
457 void identifyKilobot(
int);
458 void identifyKilobot(
int,
bool);
460 void runtimeIdentify();
462 void drawOverlay(Mat &);
464 void getDetectedCircles();
469 int t_type = POS | ADAPTIVE_LED | ROT;
471 bool experimentIsBroadcasting=
false;
476 cuda::GpuMat finalImageB;
477 cuda::GpuMat finalImageG;
478 cuda::GpuMat finalImageR;
479 cuda::GpuMat fullImages[3];
480 cuda::GpuMat grayImage;
488 MAT_TYPE warpedImages;
489 MAT_TYPE warpedMasks;
495 Point2f arenaCorners[4];
496 bool haveCalibration =
false;
499 acquireThread * threads = NULL;
506 QPoint smallImageSize;
508 Ptr<detail::ExposureCompensator> compensator;
509 Ptr<detail::Blender> blender;
513 bool loadFirstIm =
false;
515 srcDataType srcType = CAMERA;
518 trackerType trackType = CIRCLES_NAIVE;
520 QVector < Kilobot * > kilos;
522 QVector < float > kiloHeadings;
524 QVector < QPointF > kiloOldPos;
526 QVector < QVector < int > > exclusionTestsIndices;
528 float last_time = 0.0f;
534 uint found = IDENTIFY_TIMEOUT;
535 QVector < uint > foundIDs;
536 QVector < int > assignedCircles;
538 experimentType expType = USER_EXP;
542 QVector < drawnCircle > circsToDraw;
543 QVector < drawnLine > linesToDraw;
544 QVector < drawnCircle > circsToDrawFinal;
549 Ptr<cuda::HoughCirclesDetector> hough;
551 Ptr<cuda::HoughCirclesDetector> hough2;
554 Ptr<cuda::CLAHE> clahe;
555 Mat element = cv::getStructuringElement(MORPH_ELLIPSE,Size(7,7));
556 Ptr<cuda::Filter> dilateFilter;
561 bool m_detectred=
true;
562 bool m_detectgreen=
true;
563 bool m_detectblue=
true;
564 bool m_assignIDmanually=
false;
565 bool m_runtimeIDenabled=
true;
567 QVector <int> lost_count;
569 int m_runtimeIdentificationTimer = 0;
570 bool m_ongoingRuntimeIdentification =
false;
571 QVector <int> pendingRuntimeIdentification;
572 QElapsedTimer runtimeIDtimer;
575 bool savecamerasframes=
false;
576 unsigned int numberofframes;
577 QString savecamerasframesdir;