@@ -63,6 +63,20 @@ def scanner_function(multiprocess_shared_dict):
63
63
keystone_points_array = np .loadtxt (
64
64
get_folder_path ()+ 'keystone.txt' , dtype = np .float32 )
65
65
66
+ # break it to points
67
+ ulx = keystone_points_array [0 ][0 ]
68
+ uly = keystone_points_array [0 ][1 ]
69
+ urx = keystone_points_array [1 ][0 ]
70
+ ury = keystone_points_array [1 ][1 ]
71
+ blx = keystone_points_array [2 ][0 ]
72
+ bly = keystone_points_array [2 ][1 ]
73
+ brx = keystone_points_array [3 ][0 ]
74
+ bry = keystone_points_array [3 ][1 ]
75
+ # init keystone
76
+ init_keystone = [ulx ,uly ,urx ,ury ,blx ,bly ,brx ,bry ]
77
+
78
+ print (init_keystone )
79
+
66
80
# init type list array
67
81
TYPES_LIST = []
68
82
@@ -100,13 +114,6 @@ def scanner_function(multiprocess_shared_dict):
100
114
cv2 .namedWindow ('scanner_gui_window' , cv2 .WINDOW_NORMAL )
101
115
cv2 .resizeWindow ('scanner_gui_window' , 400 , 400 )
102
116
cv2 .moveWindow ('scanner_gui_window' , 10 , 100 )
103
- cv2 .namedWindow ('sliders_gui_window' , cv2 .WINDOW_NORMAL )
104
- cv2 .resizeWindow ('sliders_gui_window' , 800 , 400 )
105
- cv2 .moveWindow ('sliders_gui_window' , 550 , 100 )
106
-
107
- # make the sliders GUI
108
- create_user_intreface (
109
- keystone_points_array , video_resolution_x , video_resolution_y )
110
117
111
118
# call colors dictionary
112
119
DICTIONARY_COLORS = {
@@ -132,10 +139,9 @@ def scanner_function(multiprocess_shared_dict):
132
139
133
140
# run the video loop forever
134
141
while True :
135
-
136
142
# get a new matrix transformation every frame
137
143
KEY_STONE_DATA = keystone (
138
- video_resolution_x , video_resolution_y , listen_to_UI_interaction ())
144
+ video_resolution_x , video_resolution_y , listen_to_UI_interaction (init_keystone ))
139
145
140
146
# zero an array to collect the scanners
141
147
CELL_COLORS_ARRAY = []
@@ -415,78 +421,19 @@ def get_folder_path():
415
421
##################################################
416
422
417
423
418
- def create_user_intreface (keystone_points_array , video_resolution_x , video_resolution_y ):
419
- """
420
- Creates user interface and keystone sliders
421
-
422
- Steps:
423
- makes a list of sliders for interaction
424
-
425
- Args:
426
-
427
- Returns none
428
- """
429
-
430
- cv2 .createTrackbar ('Upper Left X' , 'sliders_gui_window' ,
431
- - video_resolution_x , video_resolution_x , dont_return_on_ui )
432
- cv2 .createTrackbar ('Upper Left Y' , 'sliders_gui_window' ,
433
- - video_resolution_y , video_resolution_y , dont_return_on_ui )
434
- cv2 .createTrackbar ('Upper Right X' , 'sliders_gui_window' ,
435
- - video_resolution_x , video_resolution_x , dont_return_on_ui )
436
- cv2 .createTrackbar ('Upper Right Y' , 'sliders_gui_window' ,
437
- - video_resolution_y , video_resolution_y , dont_return_on_ui )
438
- cv2 .createTrackbar ('Bottom Left X' , 'sliders_gui_window' ,
439
- - video_resolution_x , video_resolution_x , dont_return_on_ui )
440
- cv2 .createTrackbar ('Bottom Left Y' , 'sliders_gui_window' ,
441
- - video_resolution_y , video_resolution_y , dont_return_on_ui )
442
- cv2 .createTrackbar ('Bottom Right X' , 'sliders_gui_window' ,
443
- - video_resolution_x , video_resolution_x , dont_return_on_ui )
444
- cv2 .createTrackbar ('Bottom Right Y' , 'sliders_gui_window' ,
445
- - video_resolution_y , video_resolution_y , dont_return_on_ui )
446
-
447
- # now set the sliders position based on the saved values
448
- cv2 .setTrackbarPos ('Upper Left X' , 'sliders_gui_window' ,
449
- keystone_points_array [0 ][0 ])
450
- cv2 .setTrackbarPos ('Upper Left Y' , 'sliders_gui_window' ,
451
- keystone_points_array [0 ][1 ])
452
- cv2 .setTrackbarPos ('Upper Right X' , 'sliders_gui_window' ,
453
- keystone_points_array [1 ][0 ])
454
- cv2 .setTrackbarPos ('Upper Right Y' , 'sliders_gui_window' ,
455
- keystone_points_array [1 ][1 ])
456
- cv2 .setTrackbarPos ('Bottom Left X' , 'sliders_gui_window' ,
457
- keystone_points_array [2 ][0 ])
458
- cv2 .setTrackbarPos ('Bottom Left Y' , 'sliders_gui_window' ,
459
- keystone_points_array [2 ][1 ])
460
- cv2 .setTrackbarPos ('Bottom Right X' , 'sliders_gui_window' ,
461
- keystone_points_array [3 ][0 ])
462
- cv2 .setTrackbarPos ('Bottom Right Y' , 'sliders_gui_window' ,
463
- keystone_points_array [3 ][1 ])
464
-
465
-
466
- def dont_return_on_ui (event ):
467
- pass
468
-
469
-
470
- def listen_to_UI_interaction ():
424
+ def listen_to_UI_interaction (init_keystone ):
471
425
"""
472
426
listens to user interaction.
473
427
474
428
Steps:
475
- listen to a list of sliders
429
+ listen to UI
476
430
477
431
Args:
478
432
479
433
Returns 4x2 array of points location for key-stoning
480
434
"""
481
435
482
- ulx = cv2 .getTrackbarPos ('Upper Left X' , 'sliders_gui_window' )
483
- uly = cv2 .getTrackbarPos ('Upper Left Y' , 'sliders_gui_window' )
484
- urx = cv2 .getTrackbarPos ('Upper Right X' , 'sliders_gui_window' )
485
- ury = cv2 .getTrackbarPos ('Upper Right Y' , 'sliders_gui_window' )
486
- blx = cv2 .getTrackbarPos ('Bottom Left X' , 'sliders_gui_window' )
487
- bly = cv2 .getTrackbarPos ('Bottom Left Y' , 'sliders_gui_window' )
488
- brx = cv2 .getTrackbarPos ('Bottom Right X' , 'sliders_gui_window' )
489
- bry = cv2 .getTrackbarPos ('Bottom Right Y' , 'sliders_gui_window' )
436
+ print (init_keystone )
490
437
491
438
global selected_corner
492
439
global corner_direction
@@ -495,68 +442,66 @@ def listen_to_UI_interaction():
495
442
move_keys = ['w' , 'a' , 's' , 'd' ]
496
443
497
444
KEY_STROKE = cv2 .waitKey (1 )
498
- # saves to file
499
- if chr (KEY_STROKE & 255 ) == 'k' :
500
- save_keystone_to_file (
501
- listen_to_UI_interaction ())
502
- elif chr (KEY_STROKE & 255 ) in corner_keys :
445
+ if chr (KEY_STROKE & 255 ) in corner_keys :
503
446
selected_corner = chr (KEY_STROKE & 255 )
504
447
if selected_corner != None and chr (KEY_STROKE & 255 ) in move_keys :
505
448
corner_direction = chr (KEY_STROKE & 255 )
506
449
507
- print (selected_corner , corner_direction )
508
-
509
450
if selected_corner == '1' :
510
451
if corner_direction == 'd' :
511
- ulx = ulx - 1
452
+ init_keystone [ 0 ] = init_keystone [ 0 ] - 1
512
453
elif corner_direction == 'a' :
513
- ulx = ulx + 1
454
+ init_keystone [ 0 ] = init_keystone [ 0 ] + 1
514
455
elif corner_direction == 'w' :
515
- uly = uly + 1
456
+ init_keystone [ 1 ] = init_keystone [ 1 ] + 1
516
457
elif corner_direction == 's' :
517
- uly = uly - 1
458
+ init_keystone [ 1 ] = init_keystone [ 1 ] - 1
518
459
519
460
elif selected_corner == '2' :
520
461
if corner_direction == 'd' :
521
- urx = urx - 1
462
+ init_keystone [ 2 ] = init_keystone [ 2 ] - 1
522
463
elif corner_direction == 'a' :
523
- urx = urx + 1
464
+ init_keystone [ 2 ] = init_keystone [ 2 ] + 1
524
465
elif corner_direction == 'w' :
525
- ury = ury + 1
466
+ init_keystone [ 3 ] = init_keystone [ 3 ] + 1
526
467
elif corner_direction == 's' :
527
- ury = ury - 1
468
+ init_keystone [ 3 ] = init_keystone [ 3 ] - 1
528
469
529
470
elif selected_corner == '3' :
530
471
if corner_direction == 'd' :
531
- blx = blx - 1
472
+ init_keystone [ 4 ] = init_keystone [ 4 ] - 1
532
473
elif corner_direction == 'a' :
533
- blx = blx + 1
474
+ init_keystone [ 4 ] = init_keystone [ 4 ] + 1
534
475
elif corner_direction == 'w' :
535
- bly = bly + 1
476
+ init_keystone [ 5 ] = init_keystone [ 5 ] + 1
536
477
elif corner_direction == 's' :
537
- bly = bly - 1
478
+ init_keystone [ 5 ] = init_keystone [ 5 ] - 1
538
479
539
480
elif selected_corner == '4' :
540
481
if corner_direction == 'd' :
541
- brx = brx - 1
482
+ init_keystone [ 6 ] = init_keystone [ 6 ] - 1
542
483
elif corner_direction == 'a' :
543
- brx = brx + 1
484
+ init_keystone [ 6 ] = init_keystone [ 6 ] + 1
544
485
elif corner_direction == 'w' :
545
- bry = bry + 1
486
+ init_keystone [ 7 ] = init_keystone [ 7 ] + 1
546
487
elif corner_direction == 's' :
547
- bry = bry - 1
548
-
549
- # now set the sliders position based on the saved values
550
- cv2 .setTrackbarPos ('Upper Left X' , 'sliders_gui_window' , ulx )
551
- cv2 .setTrackbarPos ('Upper Left Y' , 'sliders_gui_window' , uly )
552
- cv2 .setTrackbarPos ('Upper Right X' , 'sliders_gui_window' , urx )
553
- cv2 .setTrackbarPos ('Upper Right Y' , 'sliders_gui_window' , ury )
554
- cv2 .setTrackbarPos ('Bottom Left X' , 'sliders_gui_window' , blx )
555
- cv2 .setTrackbarPos ('Bottom Left Y' , 'sliders_gui_window' , bly )
556
- cv2 .setTrackbarPos ('Bottom Right X' , 'sliders_gui_window' , brx )
557
- cv2 .setTrackbarPos ('Bottom Right Y' , 'sliders_gui_window' , bry )
558
-
559
- return np .asarray ([(ulx , uly ), (urx , ury ), (blx , bly ), (brx , bry )], dtype = np .float32 )
488
+ init_keystone [7 ] = init_keystone [7 ] - 1
489
+ # saves to file
490
+ elif chr (KEY_STROKE & 255 ) == 'k' :
491
+ save_keystone_to_file (
492
+ listen_to_UI_interaction (init_keystone ))
493
+
494
+ ulx = init_keystone [0 ]
495
+ uly = init_keystone [1 ]
496
+ urx = init_keystone [2 ]
497
+ ury = init_keystone [3 ]
498
+ blx = init_keystone [4 ]
499
+ bly = init_keystone [5 ]
500
+ brx = init_keystone [6 ]
501
+ bry = init_keystone [7 ]
502
+
503
+
504
+ return np .asarray ([(ulx , uly ), (urx , ury ), (blx , bly ), (brx ,bry )], dtype = np .float32 )
560
505
561
506
##################################################
562
507
0 commit comments