-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
680 lines (595 loc) · 22.3 KB
/
mainwindow.cpp
File metadata and controls
680 lines (595 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
blur(3),
threshold(200)
{
int stateSize = 6;
int measSize = 4;
int contrSize = 0;
unsigned int type = CV_32F;
cv::KalmanFilter kf(stateSize, measSize, contrSize, type);
/// Set up Qt toolbar window
ui->setupUi(this);
ui->contourTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
ui->contourTable->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->contourPanel->hide();
ui->frameSlider->setEnabled(false);
ui->frameSpinBox->setEnabled(false);
/// Set window icon
QPixmap logo = QPixmap(":/Logo/northern-red.png");
QPixmap icon = QPixmap(":/Logo/northern-red-icon.png");
setWindowIcon(QIcon(icon));
/// Set up scene
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
ui->graphicsView->setBackgroundBrush(QBrush(Qt::black, Qt::SolidPattern));
ui->insetView->setScene(scene);
ui->insetView->setBackgroundBrush(QBrush(Qt::black, Qt::SolidPattern));
/// Set up frame
image_item = new ImageItem();
image_item->setPixmap(logo);
scene->addItem(image_item);
/// Set up blur, threshold spinboxes
ui->blurSpinBox->setValue(blur);
ui->thresholdSpinBox->setValue(threshold);
//// Set up chart
//chart = new Chart;
//chart->setTitle("Dynamic spline chart");
//chart->legend()->hide();
//chart->setAnimationOptions(QChart::AllAnimations);
//chart_view = new QChartView(chart);
//chart_view->setRenderHint(QPainter::Antialiasing);
//chart_view->setFixedSize(300,400);
//ui->chartLayout->addWidget(chart_view);
/// Connect signals
connect(image_item, SIGNAL(currentPositionRgbChanged(QPointF&)), this, SLOT(showMousePosition(QPointF&)));
//connect(image_item, SIGNAL(pixelClicked(QPointF&)), this, SLOT(showClosestContour(QPointF&)));
connect(image_item, SIGNAL(pixelClicked(QPointF&)), this, SLOT(updateInset(QPointF&)));
//connect(ui->graphicsView, SIGNAL(pixelUpdate(QPointF&)), this, SLOT(showClosestContour(QPointF&)));
connect(ui->graphicsView, SIGNAL(selectionUpdate(QRect&)), this, SLOT(showSelectedContours(QRect&)));
connect(ui->graphicsView, SIGNAL(doubleClick()), this, SLOT(deselectAll()));
show();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::showMousePosition(QPointF &pos)
{
if (!current_frame.empty())
{
cv::Size mat_size = current_frame.size();
int x = static_cast<int>(pos.x());
int y = static_cast<int>(pos.y());
if (x >= 0 && y >= 0 && x <= mat_size.width && y <= mat_size.height)
{
ui->mousePositionLabel->setText("x: " + QString::number(x) + ", y: " + QString::number(y));
}
}
}
//void MainWindow::showClosestContour(QPointF &pos)
//{
// if (ui->mainTabs->currentIndex()==0 && ui->contoursCheckBox->isChecked() && frame_centroids.size()>0)
// {
// std::vector<int> selected;
// cv::Point mouse;
// mouse.x = pos.x();
// mouse.y = pos.y();
// int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
// ContourList contours = frame_contours.at(frame_index);
// for (int i=0; i<contours.size(); i++)
// {
// Contour contour = contours.at(i);
// double result = cv::pointPolygonTest(contour, mouse, false);
// if (result > -1)
// {
// if (std::find(active_contours.begin(), active_contours.end(), i) == active_contours.end())
// {
// active_contours.clear();
// active_contours.push_back(i);
// drawAllContours(frame_index);
// }
// break;
// }
// }
// }
//}
void MainWindow::updateInset(QPointF &pos)
{
if (!current_frame.empty())
{
cv::Size mat_size = current_frame.size();
int x = static_cast<int>(pos.x());
int y = static_cast<int>(pos.y());
if (x >= 0 && y >= 0 && x <= mat_size.width && y <= mat_size.height)
{
/// Update inset
ui->insetView->centerOn(x,y);
}
}
}
void MainWindow::showSelectedContours(QRect &selection)
{
if (ui->mainTabs->currentIndex()==0 && ui->contoursCheckBox->isChecked() && frame_centroids.size()>0)
{
std::vector<int> selected;
cv::Point mouse;
mouse.x = selection.bottomLeft().x();
mouse.y = selection.bottomLeft().y();
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
std::vector<cv::Point> centroids = frame_centroids.at(frame_index);
for (int i=0; i<centroids.size(); i++)
{
cv::Point centroid = centroids.at(i);
if (selection.contains((int)centroid.x, (int)centroid.y))
{
selected.push_back(i);
}
}
active_contours = selected;
drawAllContours(frame_index);
}
}
void MainWindow::deselectAll()
{
/// Deselect all the active contours
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
active_contours.clear();
drawAllContours(frame_index);
}
void MainWindow::removeAllSceneEllipses()
{
foreach (QGraphicsItem *item, scene->items())
{
QGraphicsEllipseItem *ellipse = qgraphicsitem_cast<QGraphicsEllipseItem *>(item);
if (ellipse)
{
scene->removeItem(ellipse);
}
}
}
void MainWindow::removeAllSceneLines()
{
foreach (QGraphicsItem *item, scene->items())
{
QGraphicsLineItem *line = qgraphicsitem_cast<QGraphicsLineItem *>(item);
if (line)
{
scene->removeItem(line);
}
}
}
void MainWindow::drawCrosshair(int x, int y, QColor color)
{
QPen pen = QPen(color, 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
scene->addEllipse( x-5, y-5, 10, 10, pen);
scene->addLine(x-4, y, x+4, y, pen);
scene->addLine(x, y-4, x, y-1, pen);
scene->addLine(x, y+1, x, y+4, pen);
}
void MainWindow::savePointsToCSV(QString filename)
{
QString text_data;
text_data += QString("Centroid points,\nFrame,Contour,X,Y,\n");
qDebug() << "frame centroids size: " << frame_centroids.size();
for (int frame=0; frame<frame_centroids.size(); frame++)
{
/// Populate the CSV
std::vector<cv::Point> centroids = frame_centroids.at(frame);
for(std::vector<int>::size_type i = 0; i != active_contours.size(); i++)
{
/* std::cout << someVector[i]; ... */
cv::Point centroid = centroids.at(active_contours.at(i));
text_data += QString("%1,%2,%3,%4,\n").arg(frame+1).arg(i+1).arg(centroid.x).arg(centroid.y);
}
// for (int contour=0; contour<centroids.size(); contour++)
// {
// cv::Point centroid = centroids.at(contour);
// text_data += QString("%1,%2,%3,%4,\n").arg(frame+1).arg(contour+1).arg(centroid.x).arg(centroid.y);
// //qDebug() << QString("%1,%2,%3,%4,\n").arg(frame+1).arg(contour+1).arg(centroid.x).arg(centroid.y);
// }
}
QFile csv_file(filename);
if(csv_file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
QTextStream out(&csv_file);
out << text_data;
csv_file.close();
}
qDebug() << "saved all points: " << filename;
}
void MainWindow::drawAllContours(int frame_index)
{
if (frame_contours.size()>0)
{
/// Remove the previous crosshairs
removeAllSceneEllipses();
removeAllSceneLines();
/// Set the frame
cap.set(CV_CAP_PROP_POS_FRAMES, frame_index);
cap.read(current_frame);
/// Access the contour centroid values
std::vector<cv::Point> centroids = frame_centroids.at(frame_index);
/// Draw contours
if (ui->contoursCheckBox->isChecked())
{
//cv::RNG rng(12345);
ContourList contours = frame_contours.at(frame_index);
Hierarchy hierarchy = frame_hierarchies.at(frame_index);
/// Clear the table
ui->contourTable->setRowCount(0);
/// Iterate through contours
for (int i=0; i<contour_colors.size(); i++)
{
cv::Scalar color = contour_colors.at(i);
if (std::find(active_contours.begin(), active_contours.end(), i) != active_contours.end())
{
/// Draw the active contours
cv::drawContours(current_frame, contours, i, color, 2, 8, hierarchy, 0, cv::Point());
/// Update the table
cv::Point centroid = centroids.at(i);
QString text = QString("%1, %2").arg(centroid.x).arg(centroid.y);
int count = ui->contourTable->rowCount();
ui->contourTable->insertRow(count);
ui->contourTable->setItem(count, 0, new QTableWidgetItem());
ui->contourTable->setItem(count, 1, new QTableWidgetItem(text));
ui->contourTable->setItem(count, 2, new QTableWidgetItem());
ui->contourTable->item(count, 0)->setBackgroundColor(QColor(color.val[0], color.val[1], color.val[2], 255));
//ui->contourTable->item(count, 2)->setCheckState(Qt::Checked);
} else {
// cv::drawContours(current_frame, contours, i, color, 1, 8, hierarchy, 0, cv::Point());
cv::drawContours(current_frame, contours, i, color, 1, 8, hierarchy, 0, cv::Point());
}
}
}
/// Draw centroids
if (ui->centroidsCheckBox->isChecked())
{
std::vector<cv::Point> centroids = frame_centroids.at(frame_index);
for (int i=0; i<centroids.size(); i++)
{
cv::Point centroid = centroids.at(i);
cv::Scalar color = contour_colors.at(i);
drawCrosshair(centroid.x, centroid.y, QColor(color.val[0], color.val[1], color.val[2], 150));
}
}
/// Show in a window
img = QImage((uchar*) current_frame.data, current_frame.cols, current_frame.rows, current_frame.step, QImage::Format_RGB888);
QPixmap pixmap;
pixmap = QPixmap::fromImage(img);
/// Show in view, scaled to view bounds & keeping aspect ratio
image_item->setPixmap(pixmap);
}
}
void MainWindow::showCannyFrame(int frame_index)
{
if (cap.isOpened())
{
/// Clear all the crosshairs
removeAllSceneEllipses();
removeAllSceneLines();
/// Set the frame
cap.set(CV_CAP_PROP_POS_FRAMES, frame_index);
cap.read(current_frame);
try
{
/// Convert image to gray and blur it
int blur = ui->blurSpinBox->value();
int threshold = ui->thresholdSpinBox->value();
cv::RNG rng(12345);
cv::Mat src_gray;
cv::Mat canny_output;
cv::cvtColor(current_frame, src_gray, CV_BGR2GRAY);
cv::blur(src_gray, src_gray, cv::Size(blur,blur));
/// Detect edges using canny
cv::Canny(src_gray, canny_output, threshold/2, threshold, 3);
/// Show in a window
img = QImage((uchar*) canny_output.data, canny_output.cols, canny_output.rows, canny_output.step, QImage::Format_Grayscale8);
QPixmap pixmap;
pixmap = QPixmap::fromImage(img);
/// Show in view, scaled to view bounds & keeping aspect ratio
image_item->setPixmap(pixmap);
}
catch (const std::runtime_error& error)
{
qDebug() << "blur, threshold combination failed!";
}
}
}
cv::Point MainWindow::getMeanPoint(const Contour contour)
{
cv::Point zero(0.0f, 0.0f);
cv::Point sum = std::accumulate(contour.begin(), contour.end(), zero);
cv::Point mean_point = (sum * (1.0f / contour.size()));
return mean_point;
}
cv::Point MainWindow::getCenterOfMass(const Contour contour)
{
cv::Moments mu = cv::moments(contour);
cv::Point centroid = cv::Point(mu.m10/mu.m00 , mu.m01/mu.m00);
if (centroid.x < 0 || centroid.y < 0)
{
return getMeanPoint(contour);
} else {
return centroid;
}
}
void MainWindow::updateAllContours()
{
/// Contour-oriented tracking:
/// 1) Find contours
/// 2) Binarize the image, making contours = 1 & background = 0
/// 3) Create tags for each countour (ID from 0-N in each frame)
/// 4) Make a matrix of 1's and 0's for each frame,
/// Clear current contours
frame_centroids.clear();
frame_contours.clear();
frame_hierarchies.clear();
contour_colors.clear();
/// Find contours
int frame_count = cap.get(CV_CAP_PROP_FRAME_COUNT);
frame_centroids.resize(frame_count);
frame_contours.resize(frame_count);
frame_hierarchies.resize(frame_count);
int blur = ui->blurSpinBox->value();
int threshold = ui->thresholdSpinBox->value();
cv::RNG rng(12345);
cv::Mat src_gray;
cv::Mat canny_output;
ContourListSet initial_contours;
HierarchyListSet initial_hierarchies;
std::vector<std::vector<cv::Point>> initial_centroids(frame_count);
for (int i=0; i<frame_count; i++)
{
cap.set(CV_CAP_PROP_POS_FRAMES, i);
cap.read(current_frame);
/// Convert image to gray and blur it
cv::cvtColor(current_frame, src_gray, CV_BGR2GRAY);
cv::blur(src_gray, src_gray, cv::Size(blur,blur));
/// Detect edges using canny
cv::Canny(src_gray, canny_output, threshold/2, threshold, 3);
/// Find contours
std::vector<cv::Vec4i> hierarchy;
ContourList contours;
cv::findContours(canny_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
initial_contours.push_back(contours);
initial_hierarchies.push_back(hierarchy);
/// Find centroid (mean) of each contour
for(int j=0; j<(int)contours.size(); j++)
{
Contour contour = contours.at(j);
initial_centroids[i].push_back(getMeanPoint(contour));
}
}
contour_colors.resize(initial_contours.at(0).size());
qDebug() << "Completed finding contours";
for (int c=0; c<(int)contour_colors.size(); c++)
{
/// Match first contour
frame_contours.at(0).push_back(initial_contours.at(0).at(c));
frame_hierarchies.at(0).push_back(initial_hierarchies.at(0).at(c));
frame_centroids.at(0).push_back(initial_centroids.at(0).at(c));
std::vector<cv::Point> first_set = initial_centroids.at(0);
cv::Point first_point = first_set.at(c);
for (int i=1; i<(int)frame_count; i++)
{
std::vector<cv::Point> point_set = initial_centroids.at(i);
int best_distance = current_frame.cols;
int index = -1;
for (int k=0; k<(int)point_set.size(); k++)
{
cv::Point point = point_set.at(k);
double dist = cv::norm(first_point-point);
if (dist < best_distance)
{
best_distance = dist;
index = k;
}
}
first_point = point_set.at(index);
frame_contours.at(i).push_back(initial_contours.at(i).at(index));
frame_hierarchies.at(i).push_back(initial_hierarchies.at(i).at(index));
frame_centroids.at(i).push_back(initial_centroids.at(i).at(index));
}
/// Set the color for the contour
cv::Scalar color = cv::Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
contour_colors[c] = (color);
}
qDebug() << "Found" << contour_colors.size() << "contours";
}
void MainWindow::on_frameSpinBox_valueChanged(int arg1)
{
int frame_index = arg1-1;
int tab = ui->mainTabs->currentIndex();
if (tab == 0)
{
drawAllContours(frame_index);
}
else if (tab == 1)
{
showCannyFrame(frame_index);
}
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
if (!current_frame.empty())
{
QRectF bounds = scene->itemsBoundingRect();
ui->graphicsView->fitInView(bounds, Qt::KeepAspectRatio);
ui->graphicsView->centerOn(0,0);
}
}
void MainWindow::on_action_Open_triggered()
{
/// Load a video
QString result = QFileDialog::getOpenFileName(this, tr("Select a Video File"), "/home", tr("Video Files (*.avi *.mp4 *.m4v)"));
video_filepath = result.toUtf8().constData();
QString video_filename = QString::fromStdString(video_filepath.substr(video_filepath.find_last_of("/\\") + 1));
if (!video_filename.isEmpty())
{
/// Clear current contours
frame_centroids.clear();
frame_contours.clear();
frame_hierarchies.clear();
contour_colors.clear();
/// Remove the previous crosshairs
removeAllSceneEllipses();
removeAllSceneLines();
cap = cv::VideoCapture(video_filepath);
qDebug() << "opened video: " << video_filename;
/// Enable video control elements, update elements with video information.
int frame_count = cap.get(CV_CAP_PROP_FRAME_COUNT);
ui->contourPanel->show();
ui->videoComboBox->addItem(video_filename);
/// Get contours
updateAllContours();
/// show frame zero
cap.set(CV_CAP_PROP_POS_FRAMES, 0);
cap.read(current_frame);
img = QImage((uchar*) current_frame.data, current_frame.cols, current_frame.rows, current_frame.step, QImage::Format_RGB888);
QPixmap pixmap = QPixmap::fromImage(img);
/// Show in view, scaled to view bounds & keeping aspect ratio
image_item->setPixmap(pixmap);
QRectF bounds = scene->itemsBoundingRect();
ui->graphicsView->fitInView(bounds, Qt::KeepAspectRatio);
ui->graphicsView->centerOn(0,0);
/// 5X scale in inset view
ui->insetView->scale(5,5);
ui->insetView->centerOn(bounds.center());
ui->insetView->setFixedHeight(250);
///// Set up chart
//chart->axisX()->setRange(1, frame_count);
/// Enable frame sliders
ui->frameSlider->setEnabled(true);
ui->frameSlider->setRange(1, frame_count);
ui->frameSlider->setValue(1);
ui->frameSpinBox->setEnabled(true);
ui->frameSpinBox->setRange(1, frame_count);
ui->frameSpinBox->setValue(1);
}
}
void MainWindow::on_contourTable_itemSelectionChanged()
{
//QItemSelectionModel *selection = ui->contourTable->selectionModel();
//ui->deleteContourButton->setEnabled(selection->hasSelection());
qDebug() << "table selection changed";
}
void MainWindow::on_contourTable_currentCellChanged(int row, int column, int previous_row, int previous_column)
{
/// Outline the contour selected in the table
//int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
//drawAllContours(frame_index);
qDebug() << "cell changed";
}
void MainWindow::on_deleteContourButton_clicked()
{
qDebug() << "delete button was pressed.";
QItemSelectionModel *selection = ui->contourTable->selectionModel();
int row;
int shift = 0;
foreach (QModelIndex index, selection->selectedRows())
{
row = index.row() - shift;
ui->contourTable->removeRow(row);
/// Erase the contour in each frame
for (int i=0; i<frame_contours.size(); i++)
{
frame_contours[i].erase(frame_contours[i].begin() + row);
frame_hierarchies[i].erase(frame_hierarchies[i].begin() + row);
}
contour_colors.erase(contour_colors.begin() + row);
shift++;
}
on_frameSpinBox_valueChanged(ui->frameSpinBox->value());
}
void MainWindow::on_findContoursButton_clicked()
{
/// TODO: Check if contours have been updated (deleted) before doing this.
updateAllContours();
on_frameSpinBox_valueChanged(ui->frameSpinBox->value());
}
void MainWindow::on_contoursCheckBox_stateChanged(int arg1)
{
/// Outline the contour selected in the table
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
drawAllContours(frame_index);
}
void MainWindow::on_centroidsCheckBox_stateChanged(int arg1)
{
/// Outline the contour selected in the table
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
drawAllContours(frame_index);
}
void MainWindow::on_actionSave_to_CSV_triggered()
{
QString filename = QFileDialog::getSaveFileName(this,
tr("Save all contour centroids to CSV"), "",
tr("CSV (*.csv);;All Files (*)"));
if (!filename.trimmed().isEmpty())
{
savePointsToCSV(filename);
}
}
void MainWindow::on_mainTabs_currentChanged(int index)
{
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
if (index==0)
{
drawAllContours(frame_index);
}
else if (index==1)
{
showCannyFrame(frame_index);
}
}
void MainWindow::on_trackingApplyButton_clicked()
{
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
updateAllContours();
showCannyFrame(frame_index);
}
void MainWindow::on_blurSpinBox_valueChanged(int arg1)
{
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
// showCannyFrame(frame_index);
}
void MainWindow::on_thresholdSpinBox_valueChanged(int arg1)
{
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
// showCannyFrame(frame_index);
}
void MainWindow::on_trackBlurSpinBox_valueChanged(int arg1)
{
if (cap.isOpened())
{
/// Clear all the crosshairs
removeAllSceneEllipses();
removeAllSceneLines();
/// Set the frame
int frame_index = cap.get(CV_CAP_PROP_POS_FRAMES)-1;
cap.set(CV_CAP_PROP_POS_FRAMES, frame_index);
cap.read(current_frame);
try
{
/// Convert image to gray and blur it
int blur = ui->trackBlurSpinBox->value();
cv::Mat src_gray;
cv::cvtColor(current_frame, src_gray, CV_BGR2GRAY);
// cv::medianBlur(src_gray, src_gray, blur);
cv::blur(src_gray, src_gray, cv::Size(blur,blur));
/// Show in a window
img = QImage((uchar*) src_gray.data, src_gray.cols, src_gray.rows, src_gray.step, QImage::Format_Grayscale8);
QPixmap pixmap;
pixmap = QPixmap::fromImage(img);
/// Show in view, scaled to view bounds & keeping aspect ratio
image_item->setPixmap(pixmap);
}
catch (const std::runtime_error& error)
{
qDebug() << "blur failed!";
}
}
}