def main(): fruits = cv2.imread('fruits.jpg', cv2.IMREAD_COLOR) frame = np.zeros(fruits.shape, np.uint8) low_threshold = [50] high_threshold = [150] use_canny = [False] # Create a settings window using the EnhancedWindow class. settings = EnhancedWindow(10, 50, 270, 180, 'Settings') # Init cvui and tell it to create a OpenCV window, i.e. cv2.namedWindow(WINDOW_NAME). cvui.init(WINDOW_NAME) while (True): # Should we apply Canny edge? if use_canny[0]: # Yes, we should apply it. frame = cv2.cvtColor(fruits, cv2.COLOR_BGR2GRAY) frame = cv2.Canny(frame, low_threshold[0], high_threshold[0], 3) frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) else: # No, so just copy the original image to the displaying frame. frame[:] = fruits[:] # Render the settings window and its content, if it is not minimized. settings.begin(frame) if settings.isMinimized() == False: cvui.checkbox('Use Canny Edge', use_canny) cvui.trackbar(settings.width() - 20, low_threshold, 5, 150) cvui.trackbar(settings.width() - 20, high_threshold, 80, 300) cvui.space(20); # add 20px of empty space cvui.text('Drag and minimize this settings window', 0.4, 0xff0000) settings.end() # This function must be called *AFTER* all UI components. It does # all the behind the scenes magic to handle mouse clicks, etc. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def main(): lena = cv2.imread('lena.jpg', cv2.IMREAD_COLOR) frame = np.zeros(lena.shape, np.uint8) low_threshold = [50] high_threshold = [150] use_canny = [False] # Init cvui and tell it to create a OpenCV window, i.e. cv2.namedWindow(WINDOW_NAME). cvui.init(WINDOW_NAME) while (True): # Should we apply Canny edge? if use_canny[0]: # Yes, we should apply it. frame = cv2.cvtColor(lena, cv2.COLOR_BGR2GRAY) frame = cv2.Canny(frame, low_threshold[0], high_threshold[0], 3) frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) else: # No, so just copy the original image to the displaying frame. frame[:] = lena[:] # Render the settings window to house the checkbox # and the trackbars below. cvui.window(frame, 10, 50, 180, 180, 'Settings') # Checkbox to enable/disable the use of Canny edge cvui.checkbox(frame, 15, 80, 'Use Canny Edge', use_canny) # Two trackbars to control the low and high threshold values # for the Canny edge algorithm. cvui.trackbar(frame, 15, 110, 165, low_threshold, 5, 150) cvui.trackbar(frame, 15, 180, 165, high_threshold, 80, 300) # This function must be called *AFTER* all UI components. It does # all the behind the scenes magic to handle mouse clicks, etc. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def user_interface(self, global_image): handsign=global_image.copy() cvui.checkbox(global_image, 0,50, "handsign", self.handsign_state) cvui.checkbox(global_image, 0,75, "start recording", self.record) x=cv2.getTrackbarPos("x", "Control") y=cv2.getTrackbarPos("y", "Control") w=cv2.getTrackbarPos("w", "Control") h=cv2.getTrackbarPos("h", "Control") if self.handsign_state[0] == True: self.handsign_capture(handsign, global_image, x,y,w,h) if self.record[0] == True: self.record_images(handsign) #cv2.destroyWindow("Image") cv2.imshow("Control", global_image) cvui.update()
def main(): frame = np.zeros((600, 800, 3), np.uint8) # Create variables used by some components values = [] checked = [False] checked2 = [False] value = [1.0] value2 = [1.0] value3 = [1.0] padding = 10 img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR) imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR) imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR) # Fill the vector with a few random values for i in range(0, 20): values.append(random.uniform(0., 300.0)) # Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME). cvui.init(WINDOW_NAME) while (True): # Fill the frame with a nice color frame[:] = (49, 52, 49) # In a row, all added elements are # horizontally placed, one next the other (from left to right) # # Within the cvui.beginRow() and cvui.endRow(), # all elements will be automatically positioned by cvui. # # Notice that all component calls within the begin/end block # DO NOT have (x,y) coordinates. # # Let's create a row at position (10,20) with width 100 and height 50. cvui.beginRow(frame, 10, 20, 100, 50) cvui.text('This is ') cvui.printf('a row') cvui.checkbox('checkbox', checked) cvui.window(80, 80, 'window') cvui.rect(50, 50, 0x00ff00, 0xff0000) cvui.sparkline(values, 50, 50) cvui.counter(value) cvui.button(100, 30, 'Fixed') cvui.image(img) cvui.button(img, imgGray, imgRed) cvui.endRow() # Here is another row, this time with a padding of 50px among components. padding = 50 cvui.beginRow(frame, 10, 150, 100, 50, padding) cvui.text('This is ') cvui.printf('another row') cvui.checkbox('checkbox', checked2) cvui.window(80, 80, 'window') cvui.button(100, 30, 'Fixed') cvui.printf('with 50px padding.') cvui.endRow() # Another row mixing several components cvui.beginRow(frame, 10, 250, 100, 50) cvui.text('This is ') cvui.printf('another row with a trackbar ') #cvui.trackbar(150, &value2, 0., 5.); cvui.printf(' and a button ') cvui.button(100, 30, 'button') cvui.endRow() # In a column, all added elements are vertically placed, # one below the other, from top to bottom. Let's create # a column at (50, 300) with width 100 and height 200. cvui.beginColumn(frame, 50, 330, 100, 200) cvui.text('Column 1 (no padding)') cvui.button('button1') cvui.button('button2') cvui.text('End of column 1') cvui.endColumn() # Here is another column, using a padding value of 10, # which will add an space of 10px between each component. padding = 10 cvui.beginColumn(frame, 300, 330, 100, 200, padding) cvui.text('Column 2 (padding = 10)') cvui.button('button1') cvui.button('button2') #cvui.trackbar(150, &value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25); cvui.text('End of column 2') cvui.endColumn() # You can also add an arbitrary amount of space between # components by calling cvui.space(). # # cvui.space() is aware of context, so if it is used # within a beginColumn()/endColumn() block, the space will # be vertical. If it is used within a beginRow()/endRow() # block, space will be horizontal. cvui.beginColumn(frame, 550, 330, 100, 200) cvui.text('Column 3 (use space)') # Add 5 pixels of (vertical) space. cvui.space(5) cvui.button('button1 5px below') # Add 50 pixels of (vertical) space. cvui.space(50) cvui.text('Text 50px below') # Add 20 pixels of (vertical) space. cvui.space(20) cvui.button('Button 20px below') # Add 40 pixels of (vertical) space. cvui.space(40) cvui.text('End of column 2 (40px below)') cvui.endColumn() # This function must be called *AFTER* all UI components. It does # all the behind the scenes magic to handle mouse clicks, etc. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def draw_settings(ctrl_frame, control_panes, canny_state, threshold_state, stage_mode, focus_mode, tracker_mode): # define the mutually-exclusive mode toggles stage_manual = [stage_mode == 'MANUAL'] stage_auto = [stage_mode == 'AUTO'] stage_paused = [stage_mode == 'PAUSED'] focus_manual = [focus_mode == 'MANUAL'] focus_sharpness = [focus_mode == 'SHARPNESS'] focus_depth = [focus_mode == 'DEPTH'] tracker_box_kcf = [tracker_mode == 'KCF'] tracker_box_canny = [tracker_mode == 'CANNY'] tracker_box_threshold = [tracker_mode == 'THRESHOLD'] macro_resweep = False ll_resweep = False control_panes.stage_control_pane.begin(ctrl_frame) if not control_panes.stage_control_pane.isMinimized(): cvui.space(100) # add 20px of empty space cvui.checkbox('Stage Paused', stage_paused) cvui.checkbox('Stage Manual', stage_manual) cvui.checkbox('Stage Auto', stage_auto) control_panes.stage_control_pane.end() control_panes.focus_control_pane.begin(ctrl_frame) if not control_panes.focus_control_pane.isMinimized(): cvui.space(80) # add 20px of empty space cvui.checkbox('Focus Manual', focus_manual) cvui.checkbox('Focus Sharpness', focus_sharpness) cvui.checkbox('Focus Depth', focus_depth) control_panes.focus_control_pane.end() control_panes.tracker_select_pane.begin(ctrl_frame) if not control_panes.tracker_select_pane.isMinimized(): cvui.space(60) # add 20px of empty space cvui.checkbox('KCF Tracker', tracker_box_kcf) cvui.checkbox('Canny Tracker', tracker_box_canny) cvui.checkbox('Threshold Tracker', tracker_box_threshold) control_panes.tracker_select_pane.end() control_panes.canny_settings_pane.begin(ctrl_frame) if not control_panes.canny_settings_pane.isMinimized(): cvui.space(40) # add 20px of empty space cvui.text('Canny Low Threshold') cvui.trackbar(control_panes.canny_settings_pane.width() - 20, canny_state.canny_low, 5, 150) cvui.text('Canny High Threshold') cvui.trackbar(control_panes.canny_settings_pane.width() - 20, canny_state.canny_high, 80, 300) control_panes.canny_settings_pane.end() control_panes.threshold_setting_pane.begin(ctrl_frame) if not control_panes.threshold_setting_pane.isMinimized(): cvui.space(20) # add 20px of empty space cvui.text('Binarization Threshold') cvui.trackbar(control_panes.threshold_setting_pane.width() - 20, threshold_state.threshold, 0, 255) cvui.checkbox('Show Binary Image', threshold_state.show_binary) cvui.text('MOVE THESE!!!!') if cvui.button('Force Macro Focus Sweep'): macro_resweep = True else: macro_resweep = False if cvui.button('Liquid Lens Focus Sweep'): ll_resweep = True else: ll_resweep = False control_panes.threshold_setting_pane.end() if stage_manual[0] and not stage_mode == 'MANUAL': stage_mode = 'MANUAL' elif stage_auto[0] and not stage_mode == 'AUTO': stage_mode = 'AUTO' elif stage_paused[0] and not stage_mode == 'PAUSED': stage_mode = 'PAUSED' if focus_manual[0] and not focus_mode == 'MANUAL': focus_mode = 'MANUAL' elif focus_sharpness[0] and not focus_mode == 'SHARPNESS': focus_mode = 'SHARPNESS' elif focus_depth[0] and not focus_mode == 'DEPTH': focus_mode = 'DEPTH' if tracker_box_kcf[0] and not tracker_mode == 'KCF': tracker_mode = 'KCF' elif tracker_box_canny[0] and not tracker_mode == 'CANNY': tracker_mode = 'CANNY' elif tracker_box_threshold and not tracker_mode == 'THRESHOLD': tracker_mode = 'THRESHOLD' return stage_mode, focus_mode, tracker_mode, macro_resweep, ll_resweep
def main(): frame = np.zeros((300, 600, 3), np.uint8) checked = [False] checked2 = [True] count = [0] countFloat = [0.0] trackbarValue = [0.0] # Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME). cvui.init(WINDOW_NAME) while (True): # Fill the frame with a nice color frame[:] = (49, 52, 49) # Show some pieces of text. cvui.text(frame, 50, 30, 'Hey there!') # You can also specify the size of the text and its color # using hex 0xRRGGBB CSS-like style. cvui.text(frame, 200, 30, 'Use hex 0xRRGGBB colors easily', 0.4, 0xff0000) # Sometimes you want to show text that is not that simple, e.g. strings + numbers. # You can use cvui.printf for that. It accepts a variable number of parameter, pretty # much like printf does. cvui.printf(frame, 200, 50, 0.4, 0x00ff00, 'Use printf formatting: %d + %.2f = %f', 2, 3.2, 5.2) # Buttons will return true if they were clicked, which makes # handling clicks a breeze. if cvui.button(frame, 50, 60, 'Button'): print('Button clicked') # If you do not specify the button width/height, the size will be # automatically adjusted to properly house the label. cvui.button(frame, 200, 70, 'Button with large label') # You can tell the width and height you want cvui.button(frame, 410, 70, 15, 15, 'x') # Window components are useful to create HUDs and similars. At the # moment, there is no implementation to constraint content within a # a window. cvui.window(frame, 50, 120, 120, 100, 'Window') # The counter component can be used to alter int variables. Use # the 4th parameter of the function to point it to the variable # to be changed. cvui.counter(frame, 200, 120, count) # Counter can be used with doubles too. You can also specify # the counter's step (how much it should change # its value after each button press), as well as the format # used to print the value. cvui.counter(frame, 320, 120, countFloat, 0.1, '%.1f') # The trackbar component can be used to create scales. # It works with all numerical types (including chars). cvui.trackbar(frame, 420, 110, 150, trackbarValue, 0., 50.) # Checkboxes also accept a pointer to a variable that controls # the state of the checkbox (checked or not). cvui.checkbox() will # automatically update the value of the boolean after all # interactions, but you can also change it by yourself. Just # do "checked = [True]" somewhere and the checkbox will change # its appearance. cvui.checkbox(frame, 200, 160, 'Checkbox', checked) cvui.checkbox(frame, 200, 190, 'A checked checkbox', checked2) # Display the lib version at the bottom of the screen cvui.printf(frame, 600 - 80, 300 - 20, 0.4, 0xCECECE, 'cvui v.%s', cvui.VERSION) # This function must be called *AFTER* all UI components. It does # all the behind the scenes magic to handle mouse clicks, etc. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def main(): # We have one mat for each window. frame1 = np.zeros((600, 800, 3), np.uint8) frame2 = np.zeros((600, 800, 3), np.uint8) # Create variables used by some components window1_values = [] window2_values = [] window1_checked = [False] window1_checked2 = [False] window2_checked = [False] window2_checked2 = [False] window1_value = [1.0] window1_value2 = [1.0] window1_value3 = [1.0] window2_value = [1.0] window2_value2 = [1.0] window2_value3 = [1.0] img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR) imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR) imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR) padding = 10 # Fill the vector with a few random values for i in range(0, 20): window1_values.append(random.uniform(0., 300.0)) window2_values.append(random.uniform(0., 300.0)) # Start two OpenCV windows cv2.namedWindow(WINDOW1_NAME) cv2.namedWindow(WINDOW2_NAME) # Init cvui and inform it to use the first window as the default one. # cvui.init() will automatically watch the informed window. cvui.init(WINDOW1_NAME) # Tell cvui to keep track of mouse events in window2 as well. cvui.watch(WINDOW2_NAME) while (True): # Inform cvui that all subsequent component calls and events are related to window 1. cvui.context(WINDOW1_NAME) # Fill the frame with a nice color frame1[:] = (49, 52, 49) cvui.beginRow(frame1, 10, 20, 100, 50) cvui.text('This is ') cvui.printf('a row') cvui.checkbox('checkbox', window1_checked) cvui.window(80, 80, 'window') cvui.rect(50, 50, 0x00ff00, 0xff0000) cvui.sparkline(window1_values, 50, 50) cvui.counter(window1_value) cvui.button(100, 30, 'Fixed') cvui.image(img) cvui.button(img, imgGray, imgRed) cvui.endRow() padding = 50 cvui.beginRow(frame1, 10, 150, 100, 50, padding) cvui.text('This is ') cvui.printf('another row') cvui.checkbox('checkbox', window1_checked2) cvui.window(80, 80, 'window') cvui.button(100, 30, 'Fixed') cvui.printf('with 50px paddin7hg.') cvui.endRow() cvui.beginRow(frame1, 10, 250, 100, 50) cvui.text('This is ') cvui.printf('another row with a trackbar ') cvui.trackbar(150, window1_value2, 0., 5.) cvui.printf(' and a button ') cvui.button(100, 30, 'button') cvui.endRow() cvui.beginColumn(frame1, 50, 330, 100, 200) cvui.text('Column 1 (no padding)') cvui.button('button1') cvui.button('button2') cvui.text('End of column 1') cvui.endColumn() padding = 10 cvui.beginColumn(frame1, 300, 330, 100, 200, padding) cvui.text('Column 2 (padding = 10)') cvui.button('button1') cvui.button('button2') cvui.trackbar(150, window1_value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25) cvui.text('End of column 2') cvui.endColumn() cvui.beginColumn(frame1, 550, 330, 100, 200) cvui.text('Column 3 (use space)') cvui.space(5) cvui.button('button1 5px below') cvui.space(50) cvui.text('Text 50px below') cvui.space(20) cvui.button('Button 20px below') cvui.space(40) cvui.text('End of column 2 (40px below)') cvui.endColumn() # Update all components of window1, e.g. mouse clicks, and show it. cvui.update(WINDOW1_NAME) cv2.imshow(WINDOW1_NAME, frame1) # From this point on, we are going to render the second window. We need to inform cvui # that all updates and components from now on are connected to window 2. # We do that by calling cvui.context(). cvui.context(WINDOW2_NAME) frame2[:] = (49, 52, 49) cvui.beginRow(frame2, 10, 20, 100, 50) cvui.text('This is ') cvui.printf('a row') cvui.checkbox('checkbox', window2_checked) cvui.window(80, 80, 'window') cvui.rect(50, 50, 0x00ff00, 0xff0000) cvui.sparkline(window2_values, 50, 50) cvui.counter(window2_value) cvui.button(100, 30, 'Fixed') cvui.image(img) cvui.button(img, imgGray, imgRed) cvui.endRow() padding = 50 cvui.beginRow(frame2, 10, 150, 100, 50, padding) cvui.text('This is ') cvui.printf('another row') cvui.checkbox('checkbox', window2_checked2) cvui.window(80, 80, 'window') cvui.button(100, 30, 'Fixed') cvui.printf('with 50px paddin7hg.') cvui.endRow() # Another row mixing several components cvui.beginRow(frame2, 10, 250, 100, 50) cvui.text('This is ') cvui.printf('another row with a trackbar ') cvui.trackbar(150, window2_value2, 0., 5.) cvui.printf(' and a button ') cvui.button(100, 30, 'button') cvui.endRow() cvui.beginColumn(frame2, 50, 330, 100, 200) cvui.text('Column 1 (no padding)') cvui.button('button1') cvui.button('button2') cvui.text('End of column 1') cvui.endColumn() padding = 10 cvui.beginColumn(frame2, 300, 330, 100, 200, padding) cvui.text('Column 2 (padding = 10)') cvui.button('button1') cvui.button('button2') cvui.trackbar(150, window2_value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25) cvui.text('End of column 2') cvui.endColumn() cvui.beginColumn(frame2, 550, 330, 100, 200) cvui.text('Column 3 (use space)') cvui.space(5) cvui.button('button1 5px below') cvui.space(50) cvui.text('Text 50px below') cvui.space(20) cvui.button('Button 20px below') cvui.space(40) cvui.text('End of column 2 (40px below)') cvui.endColumn() # Update all components of window2, e.g. mouse clicks, and show it. cvui.update(WINDOW2_NAME) cv2.imshow(WINDOW2_NAME, frame2) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def fizeau(frame, expr): curr_expr = expr experiments = [[False] for i in range(2)] fizeau_default = cv2.imread(resource_path("images/fizeau_default.png"), 3) fizeau_not_default = cv2.imread(resource_path("images/fizeau_not_default.png"), 3) fizeau_line = cv2.imread(resource_path("images/fizeau_line.png"), 3) fizeau_distance = cv2.imread(resource_path("images/fizeau_distance.png"), 3) fizeau_dot = cv2.imread(resource_path("images/fizeau_dot.png"), cv2.IMREAD_UNCHANGED) fizeau_dot_grey = cv2.imread(resource_path("images/fizeau_dot_grey.png"), cv2.IMREAD_UNCHANGED) fizeau_sprocket = cv2.imread(resource_path("images/fizeau_sprocket.png"), cv2.IMREAD_UNCHANGED) fizeau_metre = cv2.imread(resource_path("images/fizeau_metre.png"), cv2.IMREAD_UNCHANGED) fizeau_blank = cv2.imread(resource_path("images/fizeau_blank.png"), cv2.IMREAD_UNCHANGED) fizeau_darkstripes = cv2.imread(resource_path("images/fizeau_darkstripes.png"), cv2.IMREAD_UNCHANGED) fizeau_lightstripes = cv2.imread(resource_path("images/fizeau_lightstripes.png"), cv2.IMREAD_UNCHANGED) wheel_sprites_pos = get_120(fizeau_default, fizeau_sprocket) wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey) wheel_sprites_pos.rotate(30) wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey) wheel_sprites_pos.rotate(30) wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey) wheel_sprites_pos.rotate(30) wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey) wheel_sprites_neg = get_120(fizeau_not_default, fizeau_sprocket) wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey) wheel_sprites_neg.rotate(30) wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey) wheel_sprites_neg.rotate(30) wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey) wheel_sprites_neg.rotate(30) wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey) animation = 0 frequency_tr = [6.0] while (True): frame[:] = (49,52,49) #Animation window coord = get_coord(frequency_tr[0]) if coord == 23: cvui.image(frame, 0, 0, wheel_sprites_neg[animation]) cvui.text(frame, 33, 200, "Calculation of the speed of light", 0.5) cvui.text(frame, 34, 220, "distance ... s = {:,} m" .format(8633), 0.5) cvui.text(frame, 34, 240, "number of teeth in sprocket ... N = 720", 0.5) cvui.text(frame, 34, 260, "c=4*s*N*f=4*{:,}*{:,}*{:,}={:,} km/s" .format(8633, 7200, round(frequency_tr[0], 2), round((4 * 8633 * 7200 * frequency_tr[0])/1000, 2)), 0.5) else: cvui.image(frame, 0, 0, wheel_sprites_pos[animation]) cvui.text(frame, 33, 200, "Calculation of the speed of light", 0.5) cvui.text(frame, 34, 220, "distance ... s = {:,} m" .format(8633), 0.5) cvui.text(frame, 34, 240, "number of teeth in sprocket ... N = 720", 0.5) cvui.text(frame, 34, 260, "c=4*s*N*f ... proper frequency wasn't found", 0.5) cvui.image(frame, 872, 499, fizeau_line) cvui.image(frame, 874, 687, fizeau_distance) animation += 1 if animation == 120: animation = 0 cvui.text(frame, 58, 660, "Light source") cvui.text(frame, 473, 660, "Semipermeable mirror") cvui.text(frame, 840, 660, "Sprocket") cvui.text(frame, 994, 673, "Distance") cvui.text(frame, 1145, 660, "Mirror") cvui.text(frame, 892, 277, "-> Light behind sprocket") img = get_graph(fizeau_metre, fizeau_blank, fizeau_darkstripes, fizeau_lightstripes, coord=0, crop_light=False) cvui.image(frame, 896, 298, img) cvui.text(frame, 892, 377, "<- Reflected light before sprocket") img = get_graph(fizeau_metre, fizeau_blank, fizeau_darkstripes, fizeau_lightstripes, coord=coord, crop_light=False) cvui.image(frame, 896, 397, img) cvui.text(frame, 434, 100, "Reflected light behind sprocket") img = get_graph(fizeau_metre, fizeau_blank, fizeau_darkstripes, fizeau_lightstripes, coord=coord, crop_light=True) cvui.image(frame, 434, 120, img) #Experiment settings window cvui.window(frame, 1033.5, 2, 243.5, 104, 'Experiment settings') cvui.trackbar(frame, 1030, 39, 249, frequency_tr, 0.01, 12.0577) cvui.rect(frame, 1035, 39, 240, 12, 0x313131, 0x313131) cvui.rect(frame, 1035, 74, 240, 25, 0x313131, 0x313131) cvui.text(frame, 1041, 32, "Frequency") cvui.text(frame, 1042, 82, "{:,} Hz".format(round(frequency_tr[0], 2))) #Experiments window cvui.window(frame, 2, 2, 155, 75, 'Experiments') cvui.checkbox(frame, 10, 30, "1638 - Galileo", experiments[0]) cvui.checkbox(frame, 10, 53, "1849 - Fizeau", experiments[1]) curr_expr = exp_type(curr_expr, experiments) experiments = [[False] for i in range(2)] experiments[curr_expr] = [True] cvui.update() cv2.imshow('Speed of Light Measurement', frame) if cv2.waitKey(20) == 27: return -1 if curr_expr != expr: return curr_expr
def renderInfo(self, frame): cvui.window(frame, 10, 50, 100, 120, 'Info') cvui.checkbox(frame, 15, 80, 'Checked', self.checked)
def galileo(frame, expr): curr_expr = expr experiments = [[False] for i in range(2)] restart = True distance_tr = [1.1] galileo_default = cv2.imread(resource_path("images/galileo_default.png"), 3) galileo_yellow_dot = cv2.imread( resource_path("images/galileo_yellow_dot.png"), 3) galileo_fire = cv2.imread(resource_path("images/galileo_fire.png"), 3) while (True): frame[:] = (49, 52, 49) if restart: animation = 0 animate = False galileo_coord_bottom = 385 galileo_coord_top = 985 first_graph_f = False second_graph_f = False first_graph = False second_graph = False first_delay = 0 second_delay = 0 delay = 0 speed_of_light = 299792 half = False first_after_half = 0 first_after_end = 0 restart = False static_distance = False if not first_graph_f: first_graph, lag = get_graph() first_delay = lag first_graph_f = True if not second_graph_f: second_graph, lag = get_graph() second_delay = lag second_graph_f = True #Animation window cvui.image(frame, 0, 0, galileo_default) if animate: galileo_coord_bottom = 368 galileo_coord_top = 968 cvui.image(frame, 314, 393, galileo_fire) if animation < 21: for _ in range(animation + 1): cvui.image(frame, galileo_coord_bottom, 400, galileo_yellow_dot) galileo_coord_bottom = galileo_coord_bottom + 30 else: for _ in range(21): cvui.image(frame, galileo_coord_bottom, 400, galileo_yellow_dot) galileo_coord_bottom = galileo_coord_bottom + 30 if animation >= 21 and animation < 42: cvui.image(frame, 960, 200, first_graph) cvui.text(frame, 1045, 186, "Reaction delay", 0.4) cvui.text(frame, 1079, 278, str(int(first_delay)) + "ms", 0.4) cvui.image(frame, 1036, 390, galileo_fire) for _ in range(animation + 1 - 21): cvui.image(frame, galileo_coord_top, 375, galileo_yellow_dot) galileo_coord_top = galileo_coord_top - 30 elif animation == 42: if first_after_end != 0: if (timer() - first_after_end) > (second_delay / 1000): first_after_end = 0 cvui.image(frame, 131, 205, second_graph) cvui.text(frame, 216, 191, "Reaction delay", 0.4) cvui.text(frame, 248, 285, str(int(second_delay)) + "ms", 0.4) delay = static_distance / speed_of_light + ( first_delay / 1000) + (second_delay / 1000) else: cvui.image(frame, 131, 205, second_graph) cvui.text(frame, 216, 191, "Reaction delay", 0.4) cvui.text(frame, 248, 285, str(int(second_delay)) + "ms", 0.4) cvui.image(frame, 1036, 390, galileo_fire) for _ in range(21): cvui.image(frame, galileo_coord_top, 375, galileo_yellow_dot) galileo_coord_top = galileo_coord_top - 30 if animation < 42: act_time = timer() - start_time whole_distance = static_distance if half: traveled_distance = (act_time - (first_delay / 1000)) * speed_of_light else: traveled_distance = act_time * speed_of_light piece_of_distance = whole_distance / 21 traveled_parts = traveled_distance / piece_of_distance if first_after_half != 0: if (timer() - first_after_half) > (first_delay / 1000): first_after_half = 0 else: if not half: if traveled_parts >= 21: animation = 20 half = True first_after_half = timer() else: animation = int(traveled_parts) else: if traveled_parts >= 42: animation = 42 first_after_end = timer() else: animation = int(traveled_parts) else: cvui.image(frame, 960, 200, first_graph) cvui.text(frame, 1045, 186, "Reaction delay", 0.4) cvui.text(frame, 1079, 278, str(int(first_delay)) + "ms", 0.4) if delay != 0: cvui.text(frame, 640, 320, "Total time", 0.5) cvui.text(frame, 660, 343, str(round(delay, 2)) + "s", 0.5) cvui.text(frame, 345, 60, "Calculation of the speed of light", 0.5) cvui.text( frame, 345, 80, "distance between mountains ... s = {:,} km".format( static_distance / 2), 0.5) cvui.text(frame, 345, 100, "average human reaction time ... d = 250 ms", 0.5) cvui.text( frame, 345, 120, "c=(2*s)/(t-2*d)=(2*{:,})/({}-2*0.25)={:,} km/s". format( static_distance / 2, str(round(delay, 2)), round( static_distance / (round(delay, 2) - 2 * 0.25), 2)), 0.5) if delay == 0: cvui.text(frame, 345, 60, "Calculation of the speed of light", 0.5) if static_distance: cvui.text( frame, 345, 80, "distance between mountains ... s = {:,} km".format( static_distance / 2), 0.5) else: cvui.text( frame, 345, 80, "distance between mountains ... s = {:,} km".format( round((distance_tr[0])**8, 0)), 0.5) cvui.text(frame, 345, 100, "average human reaction time ... d = 250 ms", 0.5) cvui.text(frame, 345, 120, "c=(2*s)/(t-2*d) ... total time wasn't measured", 0.5) #Experiment settings window cvui.window(frame, 1033.5, 2, 243.5, 133, 'Experiment settings') cvui.trackbar(frame, 1030, 39, 249, distance_tr, 1.1, 10.0) cvui.rect(frame, 1035, 39, 240, 12, 0x313131, 0x313131) cvui.rect(frame, 1035, 74, 240, 25, 0x313131, 0x313131) cvui.text(frame, 1041, 32, "Distance") cvui.text(frame, 1042, 82, "{:,} km".format(round((distance_tr[0])**8, 0))) if cvui.button(frame, 1040, 102, "Measure time"): if not animate: static_distance = round((distance_tr[0])**8, 0) * 2 animate = True start_time = timer() if cvui.button(frame, 1161, 102, "Clear"): restart = True #Experiments window cvui.window(frame, 2, 2, 155, 75, 'Experiments') cvui.checkbox(frame, 10, 30, "1638 - Galileo", experiments[0]) cvui.checkbox(frame, 10, 53, "1849 - Fizeau", experiments[1]) curr_expr = exp_type(curr_expr, experiments) experiments = [[False] for i in range(2)] experiments[curr_expr] = [True] cvui.update() cv2.imshow('Speed of Light Measurement', frame) if cv2.waitKey(20) == 27: return -1 if curr_expr != expr: return curr_expr
import numpy as np import cv2 import cvui WINDOW_NAME = 'CVUI CheckBox Example' cvui.init(WINDOW_NAME) frame = np.zeros((200, 400, 3), np.uint8) # use an array/list because this variable will be changed by cvui checkboxState = [True] while True: frame[:] = (49, 52, 49) # Render the checkbox. Notice that checkboxState is used AS IS, # e.g. simply "checkboxState" instead of "checkboxState[0]". # Only internally that cvui will use checkboxState[0]. cvui.checkbox(frame, 10, 15, 'checkbox', checkboxState) cvui.update() cv2.imshow(WINDOW_NAME, frame) if cv2.waitKey(1) & 0xFF == ord('q'): break
cvui.trackbar(250, anchorTV, 0, 20, 5) cvui.space(10) cvui.text("Minimum Distance", 0.4) cvui.space(5) cvui.trackbar(250, length, 0, 20, 5) cvui.space(10) cvui.text("Sparse Area Coefficient", 0.4) cvui.space(5) cvui.trackbar(250, times, 1, 10, 5) cvui.space(10) cvui.text("Scan interval", 0.4) cvui.space(5) cvui.trackbar(250, scanIntervals, 1, 5, 4, '%d', cvui.TRACKBAR_DISCRETE, 1) cvui.space(5) cvui.beginRow() cvui.checkbox('Mean or Mid', mean) cvui.space(5) cvui.checkbox('Video', isVideo) cvui.endRow() cvui.space(5) cvui.beginRow() if (cvui.button("&Process")): if isVideo[0]: outcnt = 0 for i in range(thds): tpool[i].start() startFlag = True else: THD = Thread(target=loader, args=(imag, )) THD.start() cvui.space(5)
data = file.readlines() polygon, trap_edges, partition, triangles = parse_data(data) steps_1 = get_sl_steps(np.array(polygon), np.array(trap_edges), np.array(partition), np.array(triangles)) state = 0 state_count = len(steps_0) algorithm = 0 algorithm_0 = [True] algorithm_1 = [False] while True: frame[:] = (49, 52, 49) cvui.window(frame, 10, 10, 116, 78, "Algorithms") cvui.checkbox(frame, 20, 40, "Ear clipping", algorithm_0) cvui.checkbox(frame, 20, 62, "Sweep line", algorithm_1) if algorithm == 0 and algorithm_0[0] and algorithm_1[0]: algorithm = 1 algorithm_0 = [False] algorithm_1 = [True] state = 0 state_count = len(steps_1) elif algorithm == 1 and algorithm_0[0] and algorithm_1[0]: algorithm = 0 algorithm_0 = [True] algorithm_1 = [False] state = 0 state_count = len(steps_0) if (cvui.button(frame, 555, 40, "Previous")):
def main(): frame = np.zeros((600, 800, 3), np.uint8) # Create variables used by some components values = [] checked = [False] checked2 = [False] value = [1.0] value2 = [1.0] value3 = [1.0] padding = 10 img = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR) imgRed = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR) imgGray = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR) # Fill the vector with a few random values for i in range(0, 20): values.append(random.uniform(0., 300.0)) # Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME). cvui.init(WINDOW_NAME) while (True): # Fill the frame with a nice color frame[:] = (49, 52, 49) # In a row, all added elements are # horizontally placed, one next the other (from left to right) # # Within the cvui.beginRow() and cvui.endRow(), # all elements will be automatically positioned by cvui. # # Notice that all component calls within the begin/end block # DO NOT have (x,y) coordinates. # # Let's create a row at position (10,20) with width 100 and height 50. cvui.beginRow(frame, 10, 20, 100, 50) cvui.text('This is ') cvui.printf('a row') cvui.checkbox('checkbox', checked) cvui.window(80, 80, 'window') cvui.rect(50, 50, 0x00ff00, 0xff0000); cvui.sparkline(values, 50, 50); cvui.counter(value) cvui.button(100, 30, 'Fixed') cvui.image(img) cvui.button(img, imgGray, imgRed) cvui.endRow() # Here is another row, this time with a padding of 50px among components. padding = 50; cvui.beginRow(frame, 10, 150, 100, 50, padding) cvui.text('This is ') cvui.printf('another row') cvui.checkbox('checkbox', checked2) cvui.window(80, 80, 'window') cvui.button(100, 30, 'Fixed') cvui.printf('with 50px padding.') cvui.endRow() # Another row mixing several components cvui.beginRow(frame, 10, 250, 100, 50) cvui.text('This is ') cvui.printf('another row with a trackbar ') #cvui.trackbar(150, &value2, 0., 5.); cvui.printf(' and a button ') cvui.button(100, 30, 'button') cvui.endRow() # In a column, all added elements are vertically placed, # one below the other, from top to bottom. Let's create # a column at (50, 300) with width 100 and height 200. cvui.beginColumn(frame, 50, 330, 100, 200) cvui.text('Column 1 (no padding)') cvui.button('button1') cvui.button('button2') cvui.text('End of column 1') cvui.endColumn() # Here is another column, using a padding value of 10, # which will add an space of 10px between each component. padding = 10 cvui.beginColumn(frame, 300, 330, 100, 200, padding) cvui.text('Column 2 (padding = 10)') cvui.button('button1') cvui.button('button2') #cvui.trackbar(150, &value3, 0., 5., 1, '%3.2Lf', cvui.TRACKBAR_DISCRETE, 0.25); cvui.text('End of column 2') cvui.endColumn() # You can also add an arbitrary amount of space between # components by calling cvui.space(). # # cvui.space() is aware of context, so if it is used # within a beginColumn()/endColumn() block, the space will # be vertical. If it is used within a beginRow()/endRow() # block, space will be horizontal. cvui.beginColumn(frame, 550, 330, 100, 200) cvui.text('Column 3 (use space)') # Add 5 pixels of (vertical) space. cvui.space(5) cvui.button('button1 5px below') # Add 50 pixels of (vertical) space. cvui.space(50) cvui.text('Text 50px below') # Add 20 pixels of (vertical) space. cvui.space(20) cvui.button('Button 20px below') # Add 40 pixels of (vertical) space. cvui.space(40) cvui.text('End of column 2 (40px below)') cvui.endColumn() # This function must be called *AFTER* all UI components. It does # all the behind the scenes magic to handle mouse clicks, etc. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break