-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathimagestreamwindow.cpp
778 lines (660 loc) · 35.6 KB
/
imagestreamwindow.cpp
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
#include "imagestreamwindow.h"
#include "imageacquisition.h"
#include <QMessageBox>
#include "homescreen.h"
#include <QHBoxLayout>
#include <QCheckBox>
#include <QStatusBar>
#include <QMenuBar>
#include<QToolBar>
#include<QDateTime>
#include<QDir>
#include <QtGui>
#include "usoundutils.h"
#include <queuewriter.h>
#include<defaults.h>
#include<QDir>
#include "spinboxcontainer.h"
#include "doublespinboxcontainer.h"
#include <typeinfo>
#include "checkboxcontainer.h"
#include <QScrollBar>
#include <defaultcameraparameternames.h>
#include <settingsstore.h>
#include <customscene.h>
#include <QSplitter>
ImageStreamWindow::ImageStreamWindow(ImageAcquisition* imageAcquisitionThread, QWidget *parent) : QMainWindow(parent)
{
this->imageAcquisitionThread = imageAcquisitionThread;
DefaultCameraParameterNames* cameraSettings = DefaultCameraParameterNames::getInstance();
cameraParameters = cameraSettings->defaultCameraParameterNames.value(this->imageAcquisitionThread->getDeviceMake());
}
CameraParameters ImageStreamWindow::getCameraParameters() const
{
return cameraParameters;
}
void ImageStreamWindow::setCameraParameters(const CameraParameters &value)
{
cameraParameters = value;
}
void ImageStreamWindow::restoreDeviceSpecificSettings(){
qDebug() << "Restoring device specific settings . . .";
try {
imageAcquisitionThread->imageRotation = SettingsStore::getDeviceSpecificSettings(imageAcquisitionThread->getDeviceName(),
"rotation", QString("0.0")).toDouble();
imageAcquisitionThread->mirrorImageHorizontal = SettingsStore::getDeviceSpecificSettings(imageAcquisitionThread->getDeviceName(),
"mirrorH", QString("%1").arg(false)).toBool();
imageAcquisitionThread->mirrorImageVertical = SettingsStore::getDeviceSpecificSettings(imageAcquisitionThread->getDeviceName(),
"mirrorV", QString("%1").arg(false)).toBool();
} catch (std::exception &e) {
qDebug() << e.what();
}
}
void ImageStreamWindow::setupCameraWindow()
{
// Add new ToolBar
toolBar = new QToolBar;
addToolBar(Qt::TopToolBarArea, toolBar);
imageSaveButton = toolBar->addAction(tr("ImageSaveButton"));
imageSaveButton->setIcon(QIcon(":icons/icon-single-shot.png"));
imageSaveButton->setToolTip("Save frame");
connect(imageSaveButton, SIGNAL(triggered()), this, SLOT(saveImage()));
recordButton = toolBar->addAction(tr("RecordButton"));
recordButton->setIcon(QIcon(":icons/icon-media-record.png"));
recordButton->setToolTip("Start recording frames");
connect(recordButton, SIGNAL(triggered()), this, SLOT(startVideoRecord()));
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(writeQueue()));
timer->start(1000);
// recordPauseButton = this->menuBar()->addAction(tr("RecordPauseButton"));
// recordPauseButton->setIcon(QIcon(":icons/icon-media-playback-pause.png"));
// recordPauseButton->setDisabled(true);
// connect(recordPauseButton, SIGNAL(triggered()), this, SLOT(pauseVideoRecord()));
recordStopButton = toolBar->addAction(tr("RecordStopButton"));
recordStopButton->setIcon(QIcon(":icons/icon-media-playback-stop.png"));
recordStopButton->setDisabled(true);
recordStopButton->setToolTip("Stop recording frames");
connect(recordStopButton, SIGNAL(triggered()), this, SLOT(stopVideoRecord()));
// fixedAspectRatioButton = this->menuBar()->addAction(tr("FixedAspectRatioButton"));
// fixedAspectRatioButton->setIcon(QIcon(":icons/icon-fullscreen.png"));
// fixedAspectRatioButton->setCheckable(true);
// connect(fixedAspectRatioButton, SIGNAL(triggered()), this, SLOT(setFixedAspectRatio()));
// Histogram
grayHistogramButton = toolBar->addAction(tr("GrayHistogramButton"));
grayHistogramButton->setIcon(QIcon(":icons/icon-histogram.png"));
grayHistogramButton->setToolTip("Open Histogram");
connect(grayHistogramButton, SIGNAL(triggered()), this, SLOT(createHistogramWindow()));
rotateClockwise90Button = toolBar->addAction(tr("Rotate90Button"));
rotateClockwise90Button->setIcon(QIcon(":icons/rotate.png"));
rotateClockwise90Button->setToolTip("Rotate anticlockwise by 90");
connect(rotateClockwise90Button, SIGNAL(triggered()), this, SLOT(rotateAntiClockwise90Deg()));
mirrorImageHorizontalButton = toolBar->addAction(tr("MirrorImageHorizontalButton"));
mirrorImageHorizontalButton->setIcon(QIcon(":icons/flip-horizontal.png"));
mirrorImageHorizontalButton->setToolTip("Flip horizontal");
mirrorImageHorizontalButton->setCheckable(true);
connect(mirrorImageHorizontalButton, SIGNAL(triggered()), this, SLOT(mirrorImageHorizontalSlot()));
mirrorImageVerticalButton = toolBar->addAction(tr("MirrorImageVerticalButton"));
mirrorImageVerticalButton->setIcon(QIcon(":icons/flip-vertical.png"));
mirrorImageVerticalButton->setToolTip("Flip Vertical");
mirrorImageVerticalButton->setCheckable(true);
connect(mirrorImageVerticalButton, SIGNAL(triggered()), this, SLOT(mirrorImageVerticalSlot()));
gridButton = toolBar->addAction(tr("GridImageButton"));
gridButton->setIcon(QIcon(":icons/icon-grid.png"));
gridButton->setToolTip("Enable Grid Lines");
gridButton->setCheckable(true);
connect(gridButton, SIGNAL(triggered()), this, SLOT(gridSlot()));
resetImageButton = toolBar->addAction(tr("ResetImageButton"));
resetImageButton->setIcon(QIcon(":icons/reset.png"));
resetImageButton->setToolTip("Reset");
connect(resetImageButton, SIGNAL(triggered()), this, SLOT(resetImageSlot()));
selectButton =toolBar->addAction(tr("SelectButton"));
selectButton->setIcon(QIcon(":icons/select.png"));
selectButton->setToolTip("Select Lines");
selectButton->setCheckable(true);
selectButton->setData(int(CustomScene::SelectObject));
// connect(selectButton, SIGNAL(triggered()), this, SLOT(selectSlot()));
lineButton = toolBar->addAction(tr("LineButton"));
lineButton->setIcon(QIcon(":icons/line.png"));
lineButton->setToolTip("Draw Lines");
lineButton->setCheckable(true);
lineButton->setData(int(CustomScene::DrawLine));
// connect(lineButton, SIGNAL(triggered()), this, SLOT(lineSlot()));
actionGroup = new QActionGroup(this);
actionGroup->setExclusive(true);
actionGroup->addAction(lineButton);
actionGroup->addAction(selectButton);
connect(actionGroup, SIGNAL(triggered(QAction*)),
this, SLOT(actionGroupClicked(QAction*)));
// Setting up graphics view
graphicsView = new QGraphicsView();
graphicsScene = new CustomScene(this);
QSplitter *splitter = new QSplitter(Qt::Horizontal);
this->setCentralWidget(splitter);
graphicsView->setScene(graphicsScene);
graphicsView->setRenderHints(QPainter::Antialiasing);
graphicsPixmapItem = new QGraphicsPixmapItem();
graphicsView->scene()->addItem(graphicsPixmapItem);
QTreeWidget *ccTreeWidget = new QTreeWidget;
ccTreeWidget->setColumnCount(2);
ccTreeWidget->setHeaderLabels(QStringList() <<"Feature"<<"Value");
// Set column width for ccTree (Dynamic resize only for image)
ccTreeWidget->setFixedWidth(350);
ccTreeWidget->setColumnWidth(0, 250);
// Set the two UI elements on the camera acquisition screen
splitter->addWidget(ccTreeWidget);
splitter->addWidget(graphicsView);
QList<QTreeWidgetItem *> topLevelItems;
// exposure controls
// parent
exposureControls = new QTreeWidgetItem();
exposureControls->setText(0, "Exposure Controls");
topLevelItems.append(exposureControls);
// child
// EXPOSURE
QHBoxLayout * exposureLayout = new QHBoxLayout(splitter);
QWidget *exposureWidget = new QWidget;
exposureWidget->setLayout(exposureLayout);
exposureLayout->setSpacing(0);
exposureLayout->setMargin(0);
SpinboxContainer *exposureContainer = new SpinboxContainer(3000,cameraParameters.EXPOSURETIME,cameraParameters.EXPOSURETIME,0,1000000,50,imageAcquisitionThread);
addToContainer(exposureContainer,exposureContainer->getUiElement()->isEnabled());
exposureLayout->addWidget(exposureContainer->getUiElement());
exposureLayout->addWidget(exposureContainer->getIntSlider());
exposureControls->addChild(exposureContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(exposureContainer->getQTreeWidgetItem(), 1, exposureWidget);
// ANALOG GAIN
QHBoxLayout * gainLayout = new QHBoxLayout(splitter);
QWidget *gainWidget = new QWidget;
gainWidget->setLayout(gainLayout);
DoubleSpinboxContainer *analogGainContainer = new DoubleSpinboxContainer(5,cameraParameters.GAIN,cameraParameters.GAIN,0,36,0.1,10,imageAcquisitionThread);
addToContainer(analogGainContainer,analogGainContainer->getUiElement()->isEnabled());
gainLayout->addWidget(analogGainContainer->getUiElement());
gainLayout->addWidget(analogGainContainer->getDoubleSlider());
exposureControls->addChild(analogGainContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(analogGainContainer->getQTreeWidgetItem(), 1, gainWidget);
// AUTO GAIN
QHBoxLayout * autoGainLayout = new QHBoxLayout(splitter);
QWidget *autoGainWidget = new QWidget;
autoGainWidget->setLayout(autoGainLayout);
CheckboxContainer *autoGainContainer = new CheckboxContainer(false,cameraParameters.AUTOGAIN,cameraParameters.AUTOGAIN,"Once","Off",imageAcquisitionThread);
addToContainer(autoGainContainer,autoGainContainer->getUiElement()->isEnabled());
autoGainLayout->addWidget(autoGainContainer->getUiElement());
exposureControls->addChild(autoGainContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(autoGainContainer->getQTreeWidgetItem(), 1, autoGainWidget);
// AUTO EXPOSURE
QHBoxLayout * autoExposureLayout = new QHBoxLayout(splitter);
QWidget *autoExposureWidget = new QWidget;
autoExposureWidget->setLayout(autoExposureLayout);
CheckboxContainer *autoExposureContainer = new CheckboxContainer(false,cameraParameters.AUTOEXPOSURE,cameraParameters.AUTOEXPOSURE,"Once","Off",imageAcquisitionThread);
addToContainer(autoExposureContainer,autoExposureContainer->getUiElement()->isEnabled());
autoExposureLayout->addWidget(autoExposureContainer->getUiElement());
exposureControls->addChild(autoExposureContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(autoExposureContainer->getQTreeWidgetItem(), 1, autoExposureWidget);
// color appearance parameters
// parent
colorAppearance = new QTreeWidgetItem();
colorAppearance->setExpanded(true);
colorAppearance->setText(0, "Color and Appearance");
topLevelItems.append(colorAppearance);
// child
// HUE
QHBoxLayout * hueLayout = new QHBoxLayout(splitter);
QWidget *hueWidget = new QWidget;
hueWidget->setLayout(hueLayout);
SpinboxContainer *hueContainer = new SpinboxContainer(0,cameraParameters.HUE, cameraParameters.HUE,-40,40,1, imageAcquisitionThread);
addToContainer(hueContainer,hueContainer->getUiElement()->isEnabled());
hueLayout->addWidget(hueContainer->getUiElement());
hueLayout->addWidget(hueContainer->getIntSlider());
colorAppearance->addChild(hueContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(hueContainer->getQTreeWidgetItem(), 1, hueWidget);
// SATURATION
QHBoxLayout * saturationLayout = new QHBoxLayout(splitter);
QWidget *saturationWidget = new QWidget;
saturationWidget->setLayout(saturationLayout);
DoubleSpinboxContainer *saturationContainer = new DoubleSpinboxContainer(0,cameraParameters.SATURATION,cameraParameters.SATURATION,0,2,1, 10, imageAcquisitionThread);
addToContainer(saturationContainer,saturationContainer->getUiElement()->isEnabled());
saturationLayout->addWidget(saturationContainer->getUiElement());
saturationLayout->addWidget(saturationContainer->getDoubleSlider());
colorAppearance->addChild(saturationContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(saturationContainer->getQTreeWidgetItem(), 1, saturationWidget);
// BRIGHTNESS
QHBoxLayout * brightnessLayout = new QHBoxLayout(splitter);
QWidget *brightnessWidget = new QWidget;
brightnessWidget->setLayout(brightnessLayout);
SpinboxContainer *brightnessContainer = new SpinboxContainer(0,cameraParameters.BRIGHTNESS, cameraParameters.BRIGHTNESS,0,100,1, imageAcquisitionThread);
addToContainer(brightnessContainer,brightnessContainer->getUiElement()->isEnabled());
brightnessLayout->addWidget(brightnessContainer->getUiElement());
brightnessLayout->addWidget(brightnessContainer->getIntSlider());
colorAppearance->addChild(brightnessContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(brightnessContainer->getQTreeWidgetItem(), 1, brightnessWidget);
// CONTRAST
QHBoxLayout * contrastLayout = new QHBoxLayout(splitter);
QWidget *contrastWidget = new QWidget;
contrastWidget->setLayout(contrastLayout);
SpinboxContainer *contrastContainer = new SpinboxContainer(0,cameraParameters.CONTRAST,cameraParameters.CONTRAST,0,100,1, imageAcquisitionThread);
addToContainer(contrastContainer,contrastContainer->getUiElement()->isEnabled());
contrastLayout->addWidget(contrastContainer->getUiElement());
contrastLayout->addWidget(contrastContainer->getIntSlider());
colorAppearance->addChild(contrastContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(contrastContainer->getQTreeWidgetItem(), 1, contrastWidget);
// GAMMA
QHBoxLayout * gammaLayout = new QHBoxLayout(splitter);
QWidget *gammaWidget = new QWidget;
gammaWidget->setLayout(gammaLayout);
DoubleSpinboxContainer *gammaContainer = new DoubleSpinboxContainer(0,cameraParameters.GAMMA,cameraParameters.GAMMA,0,4,0.1,10,imageAcquisitionThread);
addToContainer(gammaContainer,gammaContainer->getUiElement()->isEnabled());
gammaLayout->addWidget(gammaContainer->getUiElement());
gammaLayout->addWidget(gammaContainer->getDoubleSlider());
colorAppearance->addChild(gammaContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(gammaContainer->getQTreeWidgetItem(), 1, gammaWidget);
// ACQUISITION FRAME RATE ENABLER
QHBoxLayout * acquisitionFrameRateEnableLayout = new QHBoxLayout(splitter);
QWidget *acquisitionFrameRateEnableWidget = new QWidget;
acquisitionFrameRateEnableWidget->setLayout(acquisitionFrameRateEnableLayout);
CheckboxContainer *acquisitionFrameRateEnableContainer = new CheckboxContainer(false,cameraParameters.ACQUISITIONFRAMERATEENABLE,
cameraParameters.ACQUISITIONFRAMERATEENABLE,"","",imageAcquisitionThread);
addToContainer(acquisitionFrameRateEnableContainer,acquisitionFrameRateEnableContainer->getUiElement()->isEnabled());
acquisitionFrameRateEnableLayout->addWidget(acquisitionFrameRateEnableContainer->getUiElement());
colorAppearance->addChild(acquisitionFrameRateEnableContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(acquisitionFrameRateEnableContainer->getQTreeWidgetItem(), 1, acquisitionFrameRateEnableWidget);
// ACQUISITION FRAME RATE
QHBoxLayout * acquisitionFrameRateLayout = new QHBoxLayout(splitter);
QWidget *acquisitionFrameRateWidget = new QWidget;
acquisitionFrameRateWidget->setLayout(acquisitionFrameRateLayout);
SpinboxContainer *acquisitionFrameRateContainer = new SpinboxContainer(10,cameraParameters.ACQUISITIONFRAMERATE,cameraParameters.ACQUISITIONFRAMERATE,1,120,1, imageAcquisitionThread);
addToContainer(acquisitionFrameRateContainer,acquisitionFrameRateContainer->getUiElement()->isEnabled());
acquisitionFrameRateLayout->addWidget(acquisitionFrameRateContainer->getUiElement());
acquisitionFrameRateLayout->addWidget(acquisitionFrameRateContainer->getIntSlider());
colorAppearance->addChild(acquisitionFrameRateContainer->getQTreeWidgetItem());
ccTreeWidget->setItemWidget(acquisitionFrameRateContainer->getQTreeWidgetItem(), 1, acquisitionFrameRateWidget);
// // MONOCHROME
// CheckboxContainer *monochromeContainer = new CheckboxContainer(false,cameraParameters.MONOCHROME,
// cameraParameters.MONOCHROME,"","",imageAcquisitionThread);
// addToContainer(monochromeContainer,monochromeContainer->getUiElement()->isEnabled());
// colorAppearance->addChild(monochromeContainer->getQTreeWidgetItem());
// ccTreeWidget->setItemWidget(monochromeContainer->getQTreeWidgetItem(), 1, monochromeContainer->getUiElement());
// // RGB
// CheckboxContainer *rgbContainer = new CheckboxContainer(false,cameraParameters.RGB,
// cameraParameters.RGB,"","",imageAcquisitionThread);
// addToContainer(rgbContainer,rgbContainer->getUiElement()->isEnabled());
// colorAppearance->addChild(rgbContainer->getQTreeWidgetItem());
// ccTreeWidget->setItemWidget(rgbContainer->getQTreeWidgetItem(), 1, rgbContainer->getUiElement());
ccTreeWidget->addTopLevelItems(topLevelItems);
exposureControls->setExpanded(true);
colorAppearance->setExpanded(true);
emit updateStatusBar("Frame Rate: "+ QString::number(this->getImageAcquisitionThread()->getValueForParam(cameraParameters.RESULTINGFRAMERATE).D()));
// resulting frame rate in status bar
// TODO: THis is a temp fix. The below line of code currently has to be written for every parameter addition. Going forward find a level of abstraction for it.
connect(exposureContainer->getUiElement(), SIGNAL(valueChanged(int)),this,SLOT(updateAllParameters()));
connect(analogGainContainer->getUiElement(), SIGNAL(valueChanged(double)),this,SLOT(updateAllParameters()));
connect(autoGainContainer->getUiElement(), SIGNAL(clicked(bool)),this,SLOT(updateAllParameters()));
connect(autoExposureContainer->getUiElement(), SIGNAL(clicked(bool)),this,SLOT(updateAllParameters()));
connect(saturationContainer->getUiElement(), SIGNAL(valueChanged(int)),this,SLOT(updateAllParameters()));
connect(hueContainer->getUiElement(), SIGNAL(valueChanged(int)),this,SLOT(updateAllParameters()));
connect(brightnessContainer->getUiElement(), SIGNAL(valueChanged(int)),this,SLOT(updateAllParameters()));
connect(contrastContainer->getUiElement(), SIGNAL(valueChanged(int)),this,SLOT(updateAllParameters()));
connect(acquisitionFrameRateEnableContainer->getUiElement(), SIGNAL(clicked(bool)),this,SLOT(updateAllParameters()));
connect(gammaContainer->getUiElement(), SIGNAL(valueChanged(double)),this,SLOT(updateAllParameters()));
connect(acquisitionFrameRateContainer->getUiElement(), SIGNAL(valueChanged(int)),this,SLOT(updateAllParameters()));
// connect(monochromeContainer->getUiElement(), SIGNAL(clicked(bool)),this,SLOT(updateAllParameters()));
// connect(rgbContainer->getUiElement(), SIGNAL(clicked(bool)),this,SLOT(updateAllParameters()));
connect(imageAcquisitionThread, SIGNAL(renderHistogramSignal(QList<QLineSeries*>, int)), this, SLOT(renderHistogramSlot(QList<QLineSeries*>, int)));
connect(imageAcquisitionThread, SIGNAL(renderHistogramSignalForLine(QList<QLineSeries*>, int)), this, SLOT(renderHistogramSlotForLine(QList<QLineSeries*>, int)));
restoreDeviceSpecificSettings();
// createToolBar();
}
void ImageStreamWindow::createToolBar(){
toolBar = new QToolBar;
addToolBar(Qt::TopToolBarArea, toolBar);
toolBar->addAction(imageSaveButton);
toolBar->addAction(recordButton);
toolBar->addAction(recordStopButton);
toolBar->addAction(grayHistogramButton);
toolBar->addAction(rotateClockwise90Button);
toolBar->addAction(mirrorImageVerticalButton);
toolBar->addAction(mirrorImageHorizontalButton);
toolBar->addAction(gridButton);
toolBar->addAction(selectButton);
toolBar->addAction(lineButton);
// toolBar->addAction(lineAction);
}
void ImageStreamWindow::addToContainer(ParameterContainer *container, bool exists)
{
if(exists)
containers.append(container);
}
void ImageStreamWindow::closeEvent(QCloseEvent *event)
{
qDebug() << "Checking for pending images in buffer";
if(!recordButton->isEnabled()){
QMessageBox::critical(this, "Close Camera","Image recording in progress",QMessageBox::Ok);
}
else if (!imageAcquisitionThread->imageBuffer.isEmpty()){
QMessageBox::critical(this, "Close Camera","Image save in progress",QMessageBox::Ok);
}
else{
ImageAcquisition *imageAcquisitionThread = this->imageAcquisitionThread;
imageAcquisitionThread->setStopAcquisition(true);
try {
qDebug() << "Closing device " + imageAcquisitionThread->getDeviceName()<< ". . . ";
imageAcquisitionThread->getImageAcquisitionHandle().CloseFramegrabber();
} catch (HalconCpp::HException &) {
//todo: add dialog box here
qDebug() << "Error: Could not close message box";
QMessageBox::critical(this, "Close Camera","Error. Could not close camera",QMessageBox::Ok);
}
imageAcquisitionThread->exit();
qDebug() << "Counter value: "<<imageAcquisitionThread->getCounter();
}
}
void ImageStreamWindow::renderImage(QImage qImage)
{
// QLABEL WAY OF STREAMING
// windowWidget = newCameraConnectionWindows.at(widgetIndex);
// if(!windowWidget->imageAcquisitionThread->stop)
// {
//// qDebug() << "qimage size "<<qImage.width()<<qImage.height();
// imageLabel = newCameraConnectionLabels.at(widgetIndex);
// int height=windowWidget->height(); int width = windowWidget->width();
// imageLabel->setPixmap(QPixmap::fromImage(qImage));
// imageLabel->setScaledContents(true);
// imageLabel->resize(width, height);
// windowWidget->show();
// }
// QGRAPHICSVIEW WAY OF STREAMING
if(!imageAcquisitionThread->getStopAcquisition())
{
imageAcquisitionThread->dynamicWidth = graphicsView->width();
imageAcquisitionThread->dynamicHeight = graphicsView->height();
// qImage = qImage.scaled(graphicsView->width(), graphicsView->height(), fixedAspectRatio);
graphicsPixmapItem->setPixmap(QPixmap::fromImage(qImage));
this->show();
}
}
void ImageStreamWindow::saveImage()
/*
Save Image
*/
{
try {
auto dir = getImageSavePathForDevice(imageAcquisitionThread->getDeviceName());
if (!qDir.exists(dir)) {
qDebug() << "Creating Application directory at "+dir;
qDir.mkpath(dir);
}
QString filename=dir+"/"+QString(generateTimeStamp().c_str())+"."+IMAGE_CONFIGURATION::IMAGE_FORMAT;
qInfo() << "Saving image at "+filename;
imageAcquisitionThread->getImageAcquisitionHandle().GrabImageAsync(0).WriteImage(IMAGE_CONFIGURATION::IMAGE_FORMAT.toStdString().c_str(), 1, filename.toStdString().c_str());
} catch (HalconCpp::HException he) {
qCritical() << he.ErrorMessage().Text();
}
catch(std::exception &e)
{
qCritical() << e.what();
}
}
void ImageStreamWindow::startVideoRecord(){
try {
QDir dir;
qDebug() << "Starting video record";
imageAcquisitionThread->currentBufferImageCounter=0;
imageAcquisitionThread->currentRecordSaveDir = getVideoSavePathForDevice(imageAcquisitionThread->getDeviceName())
+ "/" + QString(generateTimeStamp().c_str()) + "/";
dir.mkpath(imageAcquisitionThread->currentRecordSaveDir);
// Disable Record button and enable pause and stop button
imageAcquisitionThread->setRecording(true);
this->recordButton->setDisabled(true);
// this->recordPauseButton->setEnabled(true);
this->recordStopButton->setEnabled(true);
} catch (std::exception &e) {
qCritical() << e.what();
}
}
void ImageStreamWindow::stopVideoRecord(){
try {
qDebug() << "Stopping video record";
// Disable Record button and enable pause and stop button
imageAcquisitionThread->setRecording(false);
this->recordButton->setEnabled(true);
// this->recordPauseButton->setDisabled(true);
this->recordStopButton->setDisabled(true);
qDebug() << "Launching thread to record images . . .";
} catch (std::exception &e) {
qDebug() << e.what();
}
}
void ImageStreamWindow::pauseVideoRecord(){
try {
qDebug() << "Pausing video record";
//todo: Prathyush SP - Implement pause functionality
} catch (std::exception &e) {
qDebug() << e.what();
}
}
void ImageStreamWindow::updateStatusBar(QString statusMsg){
try {
this->statusBar()->showMessage(statusMsg);
} catch (std::exception &e) {
qDebug() << e.what();
}
}
void ImageStreamWindow::writeQueue(){
try {
if (!imageAcquisitionThread->imageBuffer.isEmpty() && !imageAcquisitionThread->writeInProgress){
QueueWriter *thread = new QueueWriter(imageAcquisitionThread);
thread->start();
}
} catch (std::exception &e) {
qDebug() << e.what();
}
}
void ImageStreamWindow::setFixedAspectRatio()
{
if (fixedAspectRatio == Qt::KeepAspectRatio){
fixedAspectRatio = Qt::IgnoreAspectRatio;
fixedAspectRatioButton->setIcon(QIcon(":icons/icon-fullscreen-disabled.png"));
qDebug() << "Image aspect ratio set to ignore";
}
else{
fixedAspectRatio = Qt::KeepAspectRatio;
fixedAspectRatioButton->setIcon(QIcon(":icons/icon-fullscreen.png"));
qDebug() << "Image aspect ratio set to fixed";
}
}
void ImageStreamWindow::rotateAntiClockwise90Deg()
{
if (imageAcquisitionThread->imageRotation+90.0 >= 360){
imageAcquisitionThread->imageRotation = 0;
qDebug() << "Rotation Clockwise: "+ QString::number(imageAcquisitionThread->imageRotation);
}
else{
imageAcquisitionThread->imageRotation += 90;
qDebug() << "Rotation Clockwise: "+ QString::number(imageAcquisitionThread->imageRotation);
}
SettingsStore::addDeviceSpecificSetting(imageAcquisitionThread->getDeviceName(), "rotation", QString::number(imageAcquisitionThread->imageRotation));
}
void ImageStreamWindow::mirrorImageHorizontalSlot()
{
imageAcquisitionThread->mirrorImageHorizontal = !imageAcquisitionThread->mirrorImageHorizontal;
qDebug() << "Mirror Image: "+QString("%1").arg(imageAcquisitionThread->mirrorImageHorizontal);
SettingsStore::addDeviceSpecificSetting(imageAcquisitionThread->getDeviceName(), "mirrorH", QString("%1").arg(imageAcquisitionThread->mirrorImageHorizontal));
}
void ImageStreamWindow::mirrorImageVerticalSlot()
{
imageAcquisitionThread->mirrorImageVertical = !imageAcquisitionThread->mirrorImageVertical;
qDebug() << "Mirror Image: "+QString("%1").arg(imageAcquisitionThread->mirrorImageVertical);
SettingsStore::addDeviceSpecificSetting(imageAcquisitionThread->getDeviceName(), "mirrorV", QString("%1").arg(imageAcquisitionThread->mirrorImageVertical));
}
void ImageStreamWindow::gridSlot()
{
imageAcquisitionThread->enableGrid = !imageAcquisitionThread->enableGrid;
qDebug() << "Grid: "+QString("%1").arg(imageAcquisitionThread->enableGrid);
}
void ImageStreamWindow::resetImageSlot()
{
qDebug() << "Reset called on device: " + imageAcquisitionThread->getDeviceName();
imageAcquisitionThread->mirrorImageHorizontal = false;
SettingsStore::addDeviceSpecificSetting(imageAcquisitionThread->getDeviceName(), "mirrorH", QString("%1").arg(imageAcquisitionThread->mirrorImageHorizontal));
qDebug() << "Reset Horizontal Mirror Image: "+QString("%1").arg(imageAcquisitionThread->mirrorImageHorizontal);
imageAcquisitionThread->mirrorImageVertical = false;
SettingsStore::addDeviceSpecificSetting(imageAcquisitionThread->getDeviceName(), "mirrorV", QString("%1").arg(imageAcquisitionThread->mirrorImageVertical));
qDebug() << "Reset Vertical Mirror Image: "+QString("%1").arg(imageAcquisitionThread->mirrorImageVertical);
imageAcquisitionThread->imageRotation = 0.0;
SettingsStore::addDeviceSpecificSetting(imageAcquisitionThread->getDeviceName(), "rotation", QString::number(imageAcquisitionThread->imageRotation));
qDebug() << "Reset Image Rotation: "+QString("%1").arg(imageAcquisitionThread->imageRotation);
imageAcquisitionThread->enableGrid = false;
qDebug() << "Reset Grid: "+QString("%1").arg(imageAcquisitionThread->enableGrid);
}
void ImageStreamWindow::selectSlot(){
qDebug() << "Select Clicked";
}
void ImageStreamWindow::lineSlot(){
qDebug() << "Line Clicked";
}
void ImageStreamWindow::actionGroupClicked(QAction *action){
graphicsScene->setMode(CustomScene::Mode(action->data().toInt()));
}
void ImageStreamWindow::updateAllParameters()
{
// query for all the parameters from hardware
// display all the updated parameters to UI
for(int i=0;i<containers.size();i++)
{
containers.at(i)->updateParamValue();
containers.at(i)->displayParamValue();
}
emit updateStatusBar("Frame Rate: "+ QString::number(this->getImageAcquisitionThread()->getValueForParam(cameraParameters.RESULTINGFRAMERATE).D()));
}
void ImageStreamWindow::createHistogramWindow()
{
histogramWindow = new HistogramWindow(grayHistogramButton, this);
histogramWindow->setImageAcquisitionThread(imageAcquisitionThread);
QChart *chart = new QChart();
QtCharts::QLineSeries *series = new QtCharts::QLineSeries();
chart->addSeries(series);
chart->setTitle("Histogram");
chart->createDefaultAxes();
chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
histogramWindow->setCentralWidget(chartView);
histogramWindow->resize(500, 400);
histogramWindow->setWindowTitle(this->imageAcquisitionThread->getDeviceName());
if(graphicsScene->getLines().size()==0) // Requesting Histogram for whole image
{
this->imageAcquisitionThread->setSupplyHistogramData(true);
}
else{ // Requesting Histogram for the line drawn on image
QLine *line = graphicsScene->getLines().last();
this->imageAcquisitionThread->x1=line->x1();
this->imageAcquisitionThread->x2=line->x2();
this->imageAcquisitionThread->y1=line->y1();
this->imageAcquisitionThread->y2=line->y2();
QList<QPair<int,int>> coordinates;
if(line->x2()-line->x1()==0) // Vertical Line
{
for(int y=line->y1();y<line->y2();y++)
{
coordinates.append(qMakePair(line->x1(),y));
}
this->imageAcquisitionThread->setCoordinates(coordinates);
}
else if(line->y2()-line->y1()==0) // Horizontal Line
{
for(int x=line->x1();x<line->x2();x++)
{
coordinates.append(qMakePair(x,line->y1()));
}
this->imageAcquisitionThread->setCoordinates(coordinates);
}
// 1. First decide axis (Whether its a horizontal line or vertical line.
// If horizontal then iterate over x1 till x2. If vertical then iterate over y1 till y2
// 2. Then check if there is a need to flip x1y1 with x2y2.
// Reason for this is, since we iterate from x1 till x2 or from y1 to y2,
// we want to be sure that x1 and y1 is always lesser than x2 and y2
// 3. Then check if x2-x1>y2-y2, this condition is satisfied if the line looks horizontal.
// In this case, iterate over x axis and find y cordinates, else iterate over y axis and find x coordinates
else{ // Rectangle
double lineSlope = (line->y2()-line->y1())/(double)(line->x2()-line->x1());
double intercept = line->y2() - (lineSlope*line->x2()); // Find y-intercept 'c' using y=mx+c formula
int newX1,newX2,newY1,newY2;
if(abs(line->x2() - line->x1()) > abs(line->y2()-line->y1())) // Line looks like horizontal. Therefore iterate over x1 and x2
{
// Meaning, the drawn line ends before the start point i.e start point > end point(wrt x coordinate, since line looks like horizontal).
// This condition makes sure x1y1 is always lesser than x2y2, by comparing the points x1 and x2
// THis is necessary because we iterate from x1 towards x2 so we want x1 to be lesser than x2
if(line->x1()>line->x2()){
newX1 = line->x2(); newY1 = line->y2();
newX2 = line->x1(); newY2 = line->y1();
}
else{ // Else, the drawn line ends after the start point
newX1 = line->x1(); newY1 = line->y1();
newX2 = line->x2(); newY2 = line->y2();
}
// Now iterate over the new x1 till x2, find y for every x and append them to coordinates list.
// These are the points lying on the diagonal
for(int x=newX1;x<newX2;x++)
{
int y = (lineSlope * x) + intercept; // y=mc+c. If required, use ciel and floor values to round it off to nearest interest.
coordinates.append(qMakePair(x,y));
}
}
else{ // Line looks vertical, therefore iterate over y1 and y2
// Meaning, the drawn line ends below the start point i.e start point > end point
// This condition makes sure x1y1 is always lesser than x2y2, by comparing the points y1 and y2
// THis is necessary becuase we iterate from y1 towards y2 so we want y1 to be lesser than y2
if(line->y1()>line->y2()){
newX1 = line->x2(); newY1 = line->y2();
newX2 = line->x1(); newY2 = line->y1();
}
else{ // Else, the line drawn ends above the start point
newX1 = line->x1(); newY1 = line->y1();
newX2 = line->x2(); newY2 = line->y2();
}
// Now iterate over the new y1 till y2, find x for every y and append them to coordinates list.
// These are the points lying on the diagonal
for(int y=newY1;y<newY2;y++)
{
int x = (y-intercept)/lineSlope;
coordinates.append(qMakePair(x,y));
}
}
}
this->imageAcquisitionThread->setCoordinates(coordinates);
this->imageAcquisitionThread->setSupplyHistogramDataForLine(true);
}
}
void ImageStreamWindow::renderHistogramSlot(QList<QLineSeries*> frequencies, int max)
{
chartView->chart()->axes(Qt::Horizontal).first()->setRange(0, 255);
chartView->chart()->removeAllSeries();
for(int i=0;i<frequencies.size();i++)
{
chartView->chart()->addSeries(frequencies.at(i));
}
chartView->chart()->axes(Qt::Vertical).first()->setRange(0, QVariant(max));
// chartView->chart()->legend()->markers(series)[0]->setVisible(false);
grayHistogramButton->setDisabled(true);
histogramWindow->show();
}
void ImageStreamWindow::renderHistogramSlotForLine(QList<QLineSeries *> intensities, int totalPoints)
{
chartView->chart()->axes(Qt::Horizontal).first()->setRange(0, totalPoints);
chartView->chart()->removeAllSeries();
for(int i=0;i<intensities.size();i++)
{
chartView->chart()->addSeries(intensities.at(i));
}
chartView->chart()->axes(Qt::Vertical).first()->setRange(0, 255);
// chartView->chart()->legend()->markers(series)[0]->setVisible(false);
grayHistogramButton->setDisabled(true);
histogramWindow->show();
}
// Setters and Getters
ImageAcquisition *ImageStreamWindow::getImageAcquisitionThread() const
{
return imageAcquisitionThread;
}
void ImageStreamWindow::setImageAcquisitionThread(ImageAcquisition *value)
{
imageAcquisitionThread = value;
}