Skip to content

Commit 6a1dd1e

Browse files
committed
Merge branch 'dev'
2 parents 53cbc6f + 083c814 commit 6a1dd1e

File tree

2 files changed

+55
-110
lines changed

2 files changed

+55
-110
lines changed

keystone.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
8.300000000000000000e+02 7.500000000000000000e+01
2-
1.138000000000000000e+03 1.260000000000000000e+02
3-
8.170000000000000000e+02 3.000000000000000000e+02
4-
9.490000000000000000e+02 2.860000000000000000e+02
1+
4.160000000000000000e+02 2.360000000000000000e+02
2+
9.020000000000000000e+02 2.360000000000000000e+02
3+
3.070000000000000000e+02 5.820000000000000000e+02
4+
1.126000000000000000e+03 5.820000000000000000e+02

modules.py

Lines changed: 51 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ def scanner_function(multiprocess_shared_dict):
6363
keystone_points_array = np.loadtxt(
6464
get_folder_path()+'keystone.txt', dtype=np.float32)
6565

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+
6680
# init type list array
6781
TYPES_LIST = []
6882

@@ -100,13 +114,6 @@ def scanner_function(multiprocess_shared_dict):
100114
cv2.namedWindow('scanner_gui_window', cv2.WINDOW_NORMAL)
101115
cv2.resizeWindow('scanner_gui_window', 400, 400)
102116
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)
110117

111118
# call colors dictionary
112119
DICTIONARY_COLORS = {
@@ -132,10 +139,9 @@ def scanner_function(multiprocess_shared_dict):
132139

133140
# run the video loop forever
134141
while True:
135-
136142
# get a new matrix transformation every frame
137143
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))
139145

140146
# zero an array to collect the scanners
141147
CELL_COLORS_ARRAY = []
@@ -415,78 +421,19 @@ def get_folder_path():
415421
##################################################
416422

417423

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):
471425
"""
472426
listens to user interaction.
473427
474428
Steps:
475-
listen to a list of sliders
429+
listen to UI
476430
477431
Args:
478432
479433
Returns 4x2 array of points location for key-stoning
480434
"""
481435

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)
490437

491438
global selected_corner
492439
global corner_direction
@@ -495,68 +442,66 @@ def listen_to_UI_interaction():
495442
move_keys = ['w', 'a', 's', 'd']
496443

497444
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:
503446
selected_corner = chr(KEY_STROKE & 255)
504447
if selected_corner != None and chr(KEY_STROKE & 255) in move_keys:
505448
corner_direction = chr(KEY_STROKE & 255)
506449

507-
print(selected_corner, corner_direction)
508-
509450
if selected_corner == '1':
510451
if corner_direction == 'd':
511-
ulx = ulx - 1
452+
init_keystone[0] = init_keystone[0] - 1
512453
elif corner_direction == 'a':
513-
ulx = ulx + 1
454+
init_keystone[0] = init_keystone[0] + 1
514455
elif corner_direction == 'w':
515-
uly = uly + 1
456+
init_keystone[1] = init_keystone[1] + 1
516457
elif corner_direction == 's':
517-
uly = uly - 1
458+
init_keystone[1] = init_keystone[1] - 1
518459

519460
elif selected_corner == '2':
520461
if corner_direction == 'd':
521-
urx = urx - 1
462+
init_keystone[2] = init_keystone[2] - 1
522463
elif corner_direction == 'a':
523-
urx = urx + 1
464+
init_keystone[2] = init_keystone[2] + 1
524465
elif corner_direction == 'w':
525-
ury = ury + 1
466+
init_keystone[3] = init_keystone[3] + 1
526467
elif corner_direction == 's':
527-
ury = ury - 1
468+
init_keystone[3] = init_keystone[3] - 1
528469

529470
elif selected_corner == '3':
530471
if corner_direction == 'd':
531-
blx = blx - 1
472+
init_keystone[4] = init_keystone[4] - 1
532473
elif corner_direction == 'a':
533-
blx = blx + 1
474+
init_keystone[4] = init_keystone[4] + 1
534475
elif corner_direction == 'w':
535-
bly = bly + 1
476+
init_keystone[5] =init_keystone[5] + 1
536477
elif corner_direction == 's':
537-
bly = bly - 1
478+
init_keystone[5] =init_keystone[5] - 1
538479

539480
elif selected_corner == '4':
540481
if corner_direction == 'd':
541-
brx = brx - 1
482+
init_keystone[6] =init_keystone[6] - 1
542483
elif corner_direction == 'a':
543-
brx = brx + 1
484+
init_keystone[6] =init_keystone[6] + 1
544485
elif corner_direction == 'w':
545-
bry = bry + 1
486+
init_keystone[7] =init_keystone[7] + 1
546487
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)
560505

561506
##################################################
562507

0 commit comments

Comments
 (0)