forked from romixlab/cnc-vision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
875 lines (776 loc) · 27.4 KB
/
main.qml
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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtMultimedia 5.9
import io.opencv 1.0
import tech.vhrd.vision 1.0
import tech.vhrd 1.0
import tech.vhrd.automator 1.0
import QtCharts 2.2
import QtQuick.Dialogs 1.2
Window {
id: root
visible: true
width: 1920
height: 1080
title: qsTr("Hello World")
color: "#161616"
// CaptureController {
// id: captureCtrl
// onStatusChanged: console.log(status)
// }
VideoOutput {
id: mainVideoOutput
anchors.right: parent.right
anchors.top: parent.top
width: parent.width / 2
height: parent.height / 2
source: CVMatSurfaceSource {
name: "main"
}
}
VideoOutput {
id: secondVideoOutput
anchors.right: parent.right
anchors.bottom: parent.bottom
width: parent.width / 2
height: parent.height / 2
source: CVMatSurfaceSource {
id: secondVideoSource
name: "second"
}
onWidthChanged: osdRescale(testRect, secondVideoSource, secondVideoOutput)
onHeightChanged: osdRescale(testRect, secondVideoSource, secondVideoOutput)
}
Item {
id: testRect
anchors.left: secondVideoOutput.left
anchors.top: secondVideoOutput.top
width: secondVideoOutput.width
height: secondVideoOutput.height
ColumnLayout {
id: settingsLayout
anchors.left: parent.left
anchors.leftMargin: 16
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width * 0.4
spacing: 8
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Hue range low:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
RangeSlider {
from: 0
to: 179
stepSize: 1
first.value: 0
second.value: 40
first.onMoved: lineDetector.hueLowRangeFrom = Math.floor(first.value)
second.onMoved: lineDetector.hueLowRangeTo = Math.floor(second.value)
Component.onCompleted: {
lineDetector.hueLowRangeFrom = Math.floor(first.value);
lineDetector.hueLowRangeTo = Math.floor(second.value);
}
}
}
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Hue range high:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
RangeSlider {
from: 0
to: 179
stepSize: 1
first.value: 140
second.value: 179
first.onMoved: lineDetector.hueHighRangeFrom = Math.floor(first.value)
second.onMoved: lineDetector.hueHighRangeTo = Math.floor(second.value)
Component.onCompleted: {
lineDetector.hueHighRangeFrom = Math.floor(first.value);
lineDetector.hueHighRangeTo = Math.floor(second.value);
}
}
}
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Saturation range:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
RangeSlider {
from: 0
to: 255
stepSize: 1
first.value: 0
second.value: 100
first.onMoved: lineDetector.saturationFrom = Math.floor(first.value)
second.onMoved: lineDetector.saturationTo = Math.floor(second.value)
Component.onCompleted: {
lineDetector.saturationFrom = Math.floor(first.value);
lineDetector.saturationTo = Math.floor(second.value);
}
}
}
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Value range:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
RangeSlider {
from: 0
to: 255
stepSize: 1
first.value: 185
second.value: 255
first.onMoved: lineDetector.valueFrom = Math.floor(first.value)
second.onMoved: lineDetector.valueTo = Math.floor(second.value)
Component.onCompleted: {
lineDetector.valueFrom = Math.floor(first.value);
lineDetector.valueTo = Math.floor(second.value);
}
}
}
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Integration range:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
RangeSlider {
from: 0
to: 1
stepSize: 0.01
first.value: 0.18
second.value: 0.28
first.onMoved: lineDetector.integrateFrom = first.value
second.onMoved: lineDetector.integrateTo = second.value
Component.onCompleted: {
lineDetector.integrateFrom = first.value;
lineDetector.integrateTo = second.value;
}
}
}
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Threshold:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
Slider {
id: thresholdSlider
from: 0
to: 1
stepSize: 0.01
value: 0.045
onValueChanged: lineDetector.threshold = value
Component.onCompleted: {
lineDetector.threshold = value
}
}
}
RowLayout {
Layout.maximumHeight: 24
Text {
text: "Fine rotation:"
color: "gray"
Layout.preferredWidth: settingsLayout.width * 0.4
}
Slider {
from: -15
to: 15
stepSize: 0.1
value: 0
onValueChanged: lineDetector.rotation = value
Component.onCompleted: {
lineDetector.rotation = value
}
}
}
Item {
Layout.fillHeight: true
}
}
ChartView {
height: parent.width * 0.3
width: parent.height + 112
rotation: -90
anchors.bottom: parent.top
anchors.bottomMargin: 47
anchors.right: parent.right
anchors.rightMargin: -54
transformOrigin: Item.BottomRight
animationOptions: ChartView.NoAnimation
backgroundColor: "transparent"
legend.visible: false
//antialiasing: true
ValueAxis {
id: axisX
min: 0
max: 1
gridVisible: false
lineVisible: false
labelsVisible: false
}
ValueAxis {
id: axisY
min: 0
max: 1
gridVisible: false
lineVisible: false
labelsVisible: false
}
LineSeries {
id: integratedPlotSeries
name: "test"
axisX: axisX
axisY: axisY
useOpenGL: true
width: 1.0
}
LineSeries {
id: thresholdPlotSeries
axisX: axisX
axisY: axisY
useOpenGL: true
width: 2.0
color: "red"
}
Component.onCompleted: {
lineDetectorDataSource.setIntegratedPlotSeries(integratedPlotSeries)
lineDetectorDataSource.setThresholdPlotSeries(thresholdPlotSeries)
}
}
Text {
id: stateLabel
text: "UNLOCKED"
color: "#f44336"
font.bold: true
font.pointSize: 18
anchors.top: parent.top
anchors.right: parent.right
anchors.topMargin: 32
anchors.rightMargin: 32
Connections {
target: lineDetector
onStateChanged: {
var lstate = lineDetector.state;
if (lstate === LineDetector.Locked) {
stateLabel.text = "LOCKED"
stateLabel.color = "#4caf50"
} else if (lstate === LineDetector.Hold) {
stateLabel.text = "HOLD"
stateLabel.color = "#cddc39"
} else {
stateLabel.text = "UNLOCKED"
stateLabel.color = "#f44336"
}
}
}
}
Text {
id: dzLabel
font.bold: true
font.pointSize: 18
anchors.top: stateLabel.top
anchors.right: stateLabel.left
anchors.rightMargin: 8
color: "gray"
text: lineDetector.dz.toFixed(3)
}
Button {
anchors.right: stateLabel.left
anchors.top: dzLabel.bottom
anchors.topMargin: 0
anchors.rightMargin: 8
text: "0"
height: 34
onClicked: lineDetector.zerodxs()
}
}
function osdRescale(item, videoSource, videoOutput) {
if (videoSource.width === 0)
return
var sourceAspectRatio = videoSource.width / videoSource.height
var sourceVisibleWidth = videoOutput.width
var sourceVisibleHeight = sourceVisibleWidth / sourceAspectRatio
if (sourceVisibleHeight > videoOutput.height) {
sourceVisibleHeight = videoOutput.height
sourceVisibleWidth = sourceVisibleHeight * sourceAspectRatio
item.anchors.leftMargin = (videoOutput.width - sourceVisibleWidth) / 2
item.anchors.topMargin = 0
} else {
item.anchors.topMargin = (videoOutput.height - sourceVisibleHeight) / 2
item.anchors.leftMargin = 0
}
item.width = sourceVisibleWidth
item.height = sourceVisibleHeight
}
Connections {
target: secondVideoSource
onDimensionsChanged: osdRescale(testRect, secondVideoSource, secondVideoOutput)
}
// GcodePlayer {
// id: player
// onCurrentLineChanged: commandsListView.positionViewAtIndex(currentLineNumber, ListView.Center)
// }
FileDialog {
id: playerFileDialog
title: "Choose gcode file"
folder: shortcuts.home
onAccepted: {
player.loadFile(fileUrl)
}
}
Item {
id: playerItem
anchors.left: parent.left
anchors.bottom: parent.bottom
width: parent.width / 2
height: parent.height / 2
RowLayout {
id: playerButtonsLayout
anchors.leftMargin: 16
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
height: 48
spacing: 16
Button {
text: "Load"
onClicked: playerFileDialog.visible = true
}
Button {
text: "Play"
onClicked: player.play();
}
Button {
text: "Pause"
onClicked: player.pause();
}
Button {
text: "Stop"
onClicked: player.stop();
}
Text {
id: connectionStatusLabel
font.bold: true
font.pointSize: 14
function checkState() {
var lstate = player.connectionState;
if (lstate === GcodePlayer.Connected) {
connectionStatusLabel.text = "MC:connected"
connectionStatusLabel.color = "#4caf50"
} else if (lstate === GcodePlayer.Connecting) {
connectionStatusLabel.text = "MC:connecting"
connectionStatusLabel.color = "#cddc39"
} else if (lstate === GcodePlayer.Disconnected) {
connectionStatusLabel.text = "MC:disconnected"
connectionStatusLabel.color = "#f44336"
}
}
Connections {
id: c1
target: player
onConnectionStateChanged: connectionStatusLabel.checkState()
}
Component.onCompleted: connectionStatusLabel.checkState()
MouseArea {
anchors.fill: parent
onClicked: player.connectToMC()
}
}
Text {
id: playerStatusLabel
text: "STOPPED"
color: "orange"
font.bold: true
font.pointSize: 14
Connections {
target: player
onStateChanged: {
var lstate = player.state;
if (lstate === GcodePlayer.Playing) {
playerStatusLabel.text = "PLAYING"
playerStatusLabel.color = "#4caf50"
} else if (lstate === GcodePlayer.Paused) {
playerStatusLabel.text = "PAUSED"
playerStatusLabel.color = "#cddc39"
} else if (lstate === GcodePlayer.PausedM25) {
playerStatusLabel.text = "PAUSEDM25"
playerStatusLabel.color = "#cddc39"
}else if (lstate === GcodePlayer.Stopped) {
playerStatusLabel.text = "STOPPED"
playerStatusLabel.color = "orange"
} else if (lstate === GcodePlayer.Error) {
playerStatusLabel.text = "ERROR"
playerStatusLabel.color = "#f44336"
}
}
}
}
Text {
font.bold: true
font.pointSize: 14
color: "#ccc"
text: player.currentLineNumber + " / " + player.linesCount + " (" + (player.currentLineNumber / player.linesCount).toFixed(1) + " %)"
}
Item {
Layout.fillWidth: true
}
}
ListView {
id: commandsListView
anchors.left: parent.left
anchors.top: playerButtonsLayout.bottom
anchors.right: parent.right
anchors.bottom: parent.bottom
clip: true
model: player.model
delegate: Rectangle {
height: 16
width: parent.width
color: model.lineNumber % 2 === 0 ? "#222" : "#333"
RowLayout {
anchors.fill: parent
spacing: 0
Item {
width: 6
}
Rectangle {
width: parent.height * 0.6
height: width
//radius: height
color: {
if (model.status === GcodePlayerItem.Pending) {
return "orange"
} else if (model.status === GcodePlayerItem.Ok) {
return "#4caf50"
} else if (model.status === GcodePlayerItem.Warning) {
return "red"
} else if (model.status === GcodePlayerItem.InternalCommand) {
return "blue"
}
return "gray"
}
}
Item {
width: 64
height: parent.height
//color: "#333"
Text {
anchors.fill: parent
text: String(model.lineNumber).padStart(6, '0')
color: "#666"
horizontalAlignment: Text.AlignHCenter
font.family: "Monaco"
}
}
Item {
height: parent.height
Layout.fillWidth: true
Text {
anchors.fill: parent
//anchors.leftMargin: 8
text: {
if (model.status === GcodePlayerItem.Warning) {
return model.code.trim() + " (" + model.response + ")"
} else {
return model.code
}
}
color: "#ccc"
horizontalAlignment: Text.AlignLeft
font.family: "Monaco"
}
}
}
}
ScrollBar.vertical: ScrollBar {
//minimumSize: 0.1
}
}
}
Item {
anchors.top: parent.top
anchors.left: buttonsLayout.right
anchors.bottom: playerItem.top
anchors.right: mainVideoOutput.left
anchors.margins: 20
ColumnLayout {
anchors.fill: parent
RowLayout {
Slider {
property real lastValue: 0.4
id: laserPowerSlider
from: 0.4
to: 5
stepSize: 0.01
onPressedChanged: {
if (value !== lastValue) {
lastValue = value
var normalized = value / 5.0
ray.setLaserPower(normalized)
}
}
}
Button {
text: "-0.01"
onClicked: {
laserPowerSlider.value -= 0.01
laserPowerSlider.onPressedChanged()
}
}
Button {
text: "+0.01"
onClicked: {
laserPowerSlider.value += 0.01
laserPowerSlider.onPressedChanged()
}
}
Text {
color: "#ccc"
font.bold: true
text: laserPowerSlider.value.toFixed(2)
}
}
RowLayout {
Button {
text: "TE"
onClicked: ray.setTopExhaust(true)
}
Button {
text: "TD"
onClicked: ray.setTopExhaust(false)
}
Button {
text: "BE"
onClicked: ray.setBottomExhaust(true)
}
Button {
text: "BD"
onClicked: ray.setBottomExhaust(false)
}
}
RowLayout {
Text {
color: "#ccc"
font.bold: true
text: "Ray:"
}
Text {
font.bold: true
text: ray.connected ? "connected" : "disconnected"
color: ray.connected ? "green" : "red"
}
}
RowLayout {
Text {
color: "#ccc"
font.bold: true
text: "Automator:"
}
Switch {
id: automatorEnableSwitch
onCheckedChanged: automator.enabled = checked
}
Button {
text: "Scan"
onClicked: {
var component = Qt.createComponent("scan.qml");
component.createObject(root);
}
}
Text {
id: automatorWorkingLabel
font.bold: true
text: "DISABLED"
color: "red"
Connections {
target: automator
onStateChanged: {
var astate = automator.state;
if (astate === Automator.Disabled) {
automatorWorkingLabel.text = "DISABLED"
automatorWorkingLabel.color = "#4caf50"
} else if (astate === Automator.AutoEngraving) {
automatorWorkingLabel.text = "ENGRAVING"
automatorWorkingLabel.color = "#cddc39"
} else if (astate === Automator.AutoCutting) {
automatorWorkingLabel.text = "CUTTING"
automatorWorkingLabel.color = "#cddc39"
}else if (astate === Automator.Scanning) {
automatorWorkingLabel.text = "SCANNING"
automatorWorkingLabel.color = "orange"
} else if (astate === Automator.EntryMissing) {
automatorWorkingLabel.text = "ENTRY MISSING"
automatorWorkingLabel.color = "#f44336"
}
}
}
}
Text {
color: "#ccc"
font.bold: true
text: automator.message
}
// Slider {
// from: -100
// to: 100
// onValueChanged: {
// compValue.text = value
// compTest.text = automator.compensate(value)
// }
// }
// Text {
// id: compValue
// color: "white"
// }
// Text {
// id: compTest
// color: "white"
// }
}
RowLayout {
Text {
color: "#ccc"
font.bold: true
text: "Max PWR:"
}
Slider {
id: maxPowerSlider
property real lastValue: 1.0
from: 0.4
to: 5
value: 1.0
onPressedChanged: {
if (value !== lastValue) {
lastValue = value
automator.maxPower = value
}
}
}
Text {
color: "#ccc"
font.bold: true
text: maxPowerSlider.value.toFixed(2)
}
}
RowLayout {
Text {
color: "#ccc"
font.bold: true
text: "Min PWR:"
}
Slider {
id: minPowerSlider
property real lastValue: 0.8
from: 0.4
to: 5
value: 0.8
onValueChanged: automator.minPower = value
onPressedChanged: {
if (value !== lastValue) {
lastValue = value
automator.minPower = value
}
}
}
Text {
color: "#ccc"
font.bold: true
text: minPowerSlider.value.toFixed(2)
}
}
RowLayout {
Text {
color: "#ccc"
font.bold: true
text: "AutoEngr/AutoCut:"
}
Switch {
onCheckedChanged: automator.cutModeEnabled = checked
}
Text {
color: "#ccc"
font.bold: true
text: "Auto PWR:"
}
Switch {
onCheckedChanged: automator.autosendPower = checked
}
Text {
color: "#ccc"
font.bold: true
text: "PWR:"
}
Text {
color: "#ccc"
font.bold: true
text: automator.lastSentPower.toFixed(2)
}
}
RowLayout {
Layout.fillHeight: true
}
}
}
ColumnLayout {
id: buttonsLayout
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.margins: 16
spacing: 10
width: 200
Button {
text: "Capture"
onClicked: {
captureController.start("abcd")
}
}
Button {
text: "Take pic"
onClicked: cameraCalibrator.takePicture()
}
Button {
text: "Save pics"
onClicked: cameraCalibrator.savePictures("./pictures")
}
Button {
text: "Load pics"
onClicked: cameraCalibrator.loadPictures("./pictures")
}
Button {
text: "Calibrate"
onClicked: cameraCalibrator.calibrate()
}
Button {
text: "Save calib"
onClicked: cameraCalibrator.saveCalibrationData("undistort.yaml")
}
Button {
text: "Load calib"
onClicked: cameraCalibrator.loadCalibrationData("undistort.yaml")
}
Button {
text: "Apply calib"
onClicked: cameraCalibrator.applyCalibrationData()
}
Item {
Layout.fillHeight: true
}
}
}