def overWrite(self, finalPath): self.frame[:] = (49, 52, 49) cvui.window(self.frame, 5, 5, X_SCREEN - 10, Y_SCREEN - 10, "Folder Alredy Exist") cvui.printf( self.frame, 10, 50, 0.4, 0xee1c1c, "Do you want to delete the original folder and overwrite it with the new copy? Everything in the" ) cvui.printf(self.frame, X_SCREEN / 2 - 100, 70, 0.4, 0xee1c1c, "original folder will be deleted!!!!") if cvui.button(self.frame, X_SCREEN / 2 - (14 * 10 + 10), 140, "Yes, Overwrite"): shutil.rmtree(finalPath) coping = self.copyFolders(self.numberFolder[0], finalPath, False) if coping == None: return None else: return True if cvui.button(self.frame, X_SCREEN / 2 + 5, 140, "No F**k! Go Back!"): return False return -1
def textInput(self, x, y, w, h, title, char, writeOn, cursor, click, writeOnBool): cvui.window(self.frame, x, y, w, h, title) # cvui.rect(self.frame, x + 1, y + 17, w - 2, h - 18, 0xf20c0c, 0xf20c0c) inBox = ((x + 1 <= cursor.x <= x + 1 + w - 2) and (y + 17 <= cursor.y <= y + 17 + h - 18)) if (inBox and click) or writeOnBool: writeOnBool = True if len(writeOn) < MAXCHAR: validChar = (32 <= char <= 33 or 35 <= char <= 41 or 43 <= char <= 46 or 48 <= char <= 57 or char == 59 or char == 61 or 64 <= char <= 91 or 93 <= char <= 123 or 125 <= char <= 127) if validChar: writeOn = writeOn + chr(char) elif char == 8 and not len(writeOn) == 0: writeOn = writeOn[:-1] elif 8 == char: writeOn = writeOn[:-1] self.t1 = self.darwBar(writeOn, self.t1, x + 5, y + 25) else: cvui.printf(self.frame, x + 5, y + 25, 0.4, 0xdd97fb, f'{writeOn}') if click and not inBox: writeOnBool = False return writeOnBool, writeOn
def begin(self, frame): mouseInsideTitleArea = cvui.mouse().inside(cvui.Rect(self.__x, self.__y, self.__width, 20)) self.__height = 20 if self.__minimized else self.__heightNotMinimized if self.__isMoving == False and cvui.mouse(cvui.DOWN) and mouseInsideTitleArea: self.__deltaX = cvui.mouse().x - self.__x self.__deltaY = cvui.mouse().y - self.__y self.__isMoving = True elif self.__isMoving and cvui.mouse(cvui.IS_DOWN): self.__x = cvui.mouse().x - self.__deltaX self.__y = cvui.mouse().y - self.__deltaY else: frameRows,frameCols,frameChannels = frame.shape self.__isMoving = False self.__x = max(0, self.__x) self.__y = max(0, self.__y) self.__x = min(frameCols - self.__width, self.__x) self.__y = min(frameRows - 20, self.__y) cvui.window(frame, self.__x, self.__y, self.__width, self.__height, self.__title) if self.__minimizable and cvui.button(frame, self.__x + self.__width - 20, self.__y + 1, 18, 18, '+' if self.__minimized else '-'): self.__minimized = not self.__minimized cvui.beginRow(frame, self.__x + 10, self.__y + 30, self.__width - 20, self.__height - 20) cvui.beginColumn(self.__width - 10, self.__height - 20)
def begin(self, frame): mouseInsideTitleArea = cvui.mouse().inside(cvui.Rect(self.__x, self.__y, self.__width, 20)) self.__height = 20 if self.__minimized else self.__heightNotMinimized if self.__isMoving == False and cvui.mouse(cvui.DOWN) and mouseInsideTitleArea: self.__deltaX = cvui.mouse().x - self.__x self.__deltaY = cvui.mouse().y - self.__y self.__isMoving = True elif self.__isMoving and cvui.mouse(cvui.IS_DOWN): self.__x = cvui.mouse().x - self.__deltaX self.__y = cvui.mouse().y - self.__deltaY else: frameRows,frameCols,frameChannels = frame.shape self.__isMoving = False self.__x = max(0, self.__x) self.__y = max(0, self.__y) self.__x = min(frameCols - self.__width, self.__x) self.__y = min(frameRows - 20, self.__y) cvui.window(frame, self.__x, self.__y, self.__width, self.__height, self.__title) if self.__minimizable and cvui.button(frame, self.__x + self.__width - 20, self.__y + 1, 18, 18, '+' if self.__minimized else '-'): self.__minimized = not self.__minimized cvui.beginRow(frame, self.__x + 10, self.__y + 30, self.__width - 20, self.__height - 20) cvui.beginColumn(self.__width - 10, self.__height - 20)
def button_click(frame, win_name_cvui): cvui.init(win_name_cvui) h, w = frame.shape[:2] start_col = w - 100 start_row = 50 button_width = 50 button_height = 30 setting_col = start_col - 20 setting_row = start_row - 30 setting_width = button_width + 40 setting_height = button_height * 12 frame[int(h / 2 - 1):int(h / 2 + 1)][:] = [0, 255, 0] for i in range(0, h): frame[i][int(w / 2 - 1):int(w / 2 + 1)] = [0, 255, 0] object = "undefined" while True: cvui.window(frame, setting_col, setting_row, setting_width, setting_height, "Setting") if (cvui.button(frame, start_col, start_row, button_width, button_height, "Ball")): object = "B" print("ball clicked") if (cvui.button(frame, start_col, start_row + 50, button_width, button_height, "Rubick")): object = "R" print("rubick clicked") if (cvui.button(frame, start_col, start_row + 100, button_width, button_height, "Up")): object = "U" print("Up clicked") if (cvui.button(frame, start_col, start_row + 150, button_width, button_height, "Down")): object = "D" print("Down clicked") if (cvui.button(frame, start_col, start_row + 250, button_width, button_height, "Send")): object = "S" print("Send clicked") cvui.update() cv.namedWindow(win_name_cvui, cv.WINDOW_NORMAL) cv.imshow(win_name_cvui, frame) cv.waitKey(0)
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 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 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
def group(frame, x, y, width, height): padding = 5 w = (width - padding) / 4 h = (height - 15 - padding) / 2 pos = cvui.Point(x + padding, y + 5) cvui.text(frame, pos.x, pos.y, 'Group title') pos.y += 15 cvui.window(frame, pos.x, pos.y, width - padding * 2, h - padding, 'Something') cvui.rect(frame, pos.x + 2, pos.y + 20, width - padding * 2 - 5, h - padding - 20, 0xff0000) pos.y += h cvui.window(frame, pos.x, pos.y, w / 3 - padding, h, 'Some') cvui.text(frame, pos.x + 25, pos.y + 60, '65', 1.1) pos.x += w / 3 cvui.window(frame, pos.x, pos.y, w / 3 - padding, h, 'Info') cvui.text(frame, pos.x + 25, pos.y + 60, '30', 1.1) pos.x += w / 3 cvui.window(frame, pos.x, pos.y, w / 3 - padding, h, 'Here') cvui.text(frame, pos.x + 25, pos.y + 60, '70', 1.1) pos.x += w / 3 cvui.window(frame, pos.x, pos.y, w - padding, h, 'And') cvui.rect(frame, pos.x + 2, pos.y + 22, w - padding - 5, h - padding - 20, 0xff0000) pos.x += w cvui.window(frame, pos.x, pos.y, w - padding, h, 'Here') cvui.rect(frame, pos.x + 2, pos.y + 22, w - padding - 5, h - padding - 20, 0xff0000) pos.x += w cvui.window(frame, pos.x, pos.y, w - padding, h, 'More info') cvui.rect(frame, pos.x + 2, pos.y + 22, w - padding - 5, h - padding - 20, 0xff0000) pos.x += w
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 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 renderInfo(self, frame): cvui.window(frame, 10, 50, 100, 120, 'Info') cvui.checkbox(frame, 15, 80, 'Checked', self.checked)
########################################################################### # RESULTS ########################################################################### # Invert mask mask = cv2.bitwise_not(mask) # Put mask over top of the original image. result = cv2.bitwise_and(im, im, mask=mask) frame[:] = result[:] ########################################################################### # GUI ########################################################################### # Render the settings window to house the checkbox and the trackbars below cvui.window(frame, 10, 10, 200, 250, 'Settings') options = cvui.TRACKBAR_DISCRETE | cvui.TRACKBAR_HIDE_SEGMENT_LABELS cvui.beginColumn(frame, 10, 40, -1, -1, 6) if cs == 'hsv': cvui.text('Hue low') elif cs == 'lab': cvui.text('L low') cvui.trackbar(width, lowCh0, limitsCh0[0], limitsCh0[1], 10, '%.0Lf', options, 1) cvui.space(space) if cs == 'hsv': cvui.text('Sat low') elif cs == 'lab':
def coord_get_video(path): a, b = [0], [0] main_ui = "mainui" win_name_cvui = "cvui" frame = None def on_EVENT_LBUTTONDOWN(event, x, y, flags, param): if event == cv.EVENT_LBUTTONDOWN: xy = "%d,%d" % (x, y) a.append(x) b.append(y) cv.circle(frame, (x, y), 1, (0, 0, 255), thickness=-1) cv.putText(frame, xy, (x, y), cv.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 0), thickness=1) cv.imshow("image", frame) print(a[-1], b[-1]) return a, b cap = cv.VideoCapture(path) cvui.init(win_name_cvui) while True: ret, frame = cap.read() h, w = frame.shape[:2] start_col = w - 100 start_row = 50 button_width = 50 button_height = 30 setting_col = start_col - 20 setting_row = start_row - 30 setting_width = button_width + 40 setting_height = button_height * 12 object = "undefined" frame[int(h / 2 - 1):int(h / 2 + 1)][:] = [0, 255, 0] for i in range(0, h): frame[i][int(w / 2 - 1):int(w / 2 + 1)] = [0, 255, 0] cvui.window(frame, setting_col, setting_row, setting_width, setting_height, "Setting") if (cvui.button(frame, start_col, start_row, button_width, button_height, "Ball")): object = "B" print("ball clicked") if (cvui.button(frame, start_col, start_row + 50, button_width, button_height, "Rubick")): object = "R" print("rubick clicked") if (cvui.button(frame, start_col, start_row + 100, button_width, button_height, "Up")): object = "U" print("Up clicked") if (cvui.button(frame, start_col, start_row + 150, button_width, button_height, "Down")): object = "D" print("Down clicked") if (cvui.button(frame, start_col, start_row + 250, button_width, button_height, "Send")): object = "S" print("Send clicked") cvui.update() cv.namedWindow(win_name_cvui, cv.WINDOW_NORMAL) cv.imshow(win_name_cvui, frame) cv.namedWindow("image", cv.WINDOW_NORMAL) cv.setMouseCallback("image", on_EVENT_LBUTTONDOWN) cv.imshow("image", frame) print(a[-1], b[-1], "ss") if cv.waitKey(300) & 0xff == 27: cv.destroyAllWindows() 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
# sweep line with open("polygon_sl.txt") as file: 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)
def demo(source=None, height=240): """ method creates window, that shows, what is happening with image, when is analyzed by algorithm """ if not source: cap = cv2.VideoCapture(0) else: cap = cv2.VideoCapture(source) fgbg = cv2.createBackgroundSubtractorMOG2() ret, image = cap.read() image = imutils.resize(image, height=height) if image.shape[0] > image.shape[1]: width = image.shape[0] else: width = image.shape[1] frame = np.zeros(((height + 27) * 2 - 2, (width + 7) * 4 - 5, 3), np.uint8) cvui.init('Motion Detection') while (True): frame[:] = (49, 52, 49) ret, image = cap.read() if type(image).__module__ != np.__name__: break map_ = fgbg.apply(image) image, op_1, op_2, op_3, op_4, op_5, op_6, op_7, cnt = find_bbox( image, map_, verbose=False) #To BGR op_1 = cv2.cvtColor(op_1, cv2.COLOR_GRAY2BGR) op_2 = cv2.cvtColor(op_2, cv2.COLOR_GRAY2BGR) op_3 = cv2.cvtColor(op_3, cv2.COLOR_GRAY2BGR) op_4 = cv2.cvtColor(op_4, cv2.COLOR_GRAY2BGR) op_5 = cv2.cvtColor(op_5, cv2.COLOR_GRAY2BGR) op_6 = cv2.cvtColor(op_6, cv2.COLOR_GRAY2BGR) op_7 = cv2.cvtColor(op_7, cv2.COLOR_GRAY2BGR) #Resize image = imutils.resize(image, height=height) op_1 = imutils.resize(op_1, height=height) op_2 = imutils.resize(op_2, height=height) op_3 = imutils.resize(op_3, height=height) op_4 = imutils.resize(op_4, height=height) op_5 = imutils.resize(op_5, height=height) op_6 = imutils.resize(op_6, height=height) op_7 = imutils.resize(op_7, height=height) #Window cvui.window(frame, 2, 2, width + 3, 263, 'Motion Detection') cvui.image(frame, 4, 24, image) cvui.window(frame, (width + 3) + 4, 2, width + 3, 263, 'operation_1 - MOG2') cvui.image(frame, (width + 3) + 4 + 2, 24, op_1) cvui.window(frame, ((width + 3) + 2) * 2 + 2, 2, width + 3, 263, 'operation_2 - medianBlur') cvui.image(frame, ((width + 3) + 4) * 2, 24, op_2) cvui.window(frame, ((width + 3) + 2) * 3 + 2, 2, width + 3, 263, 'operation_3 - threshold') cvui.image(frame, ((width + 3) + 4) * 3 - 2, 24, op_3) cvui.window(frame, 2, 265 + 2, width + 3, 263, 'operation_4 - medianBlur') cvui.image(frame, 4, 265 + 24, op_4) cvui.window(frame, (width + 3) + 4, 265 + 2, width + 3, 263, 'operation_5 - distanceTransform, threshold') cvui.image(frame, (width + 3) + 4 + 2, 265 + 24, op_5) cvui.window(frame, ((width + 3) + 2) * 2 + 2, 265 + 2, width + 3, 263, 'operation_6 - medianBlur') cvui.image(frame, ((width + 3) + 4) * 2, 265 + 24, op_6) cvui.window(frame, ((width + 3) + 2) * 3 + 2, 265 + 2, width + 3, 263, 'operation_7 - morphologyEx') cvui.image(frame, ((width + 3) + 4) * 3 - 2, 265 + 24, op_7) cvui.update() cv2.imshow('Motion Detection', frame) if cv2.waitKey(20) == 27: return -1
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
cvui.text(frame, 10, 305, "Capture Area") cvui.text(frame, 10, 355, "Min Max") cvui.text(frame, 100, 285, "Starting") cvui.counter(frame, 100, 300, Starting, 10) cvui.text(frame, 200, 285, "Width") cvui.counter(frame, 200, 300, area_width, 10) cvui.text(frame, 300, 285, "Height") cvui.counter(frame, 300, 300, area_height, 10) cvui.text(frame, 100, 335, "Max") cvui.counter(frame, 100, 350, cap_max, 100) cvui.text(frame, 200, 335, "Min") cvui.counter(frame, 200, 350, cap_min, 100) cvui.text(frame, 300, 335, "sensitivity") cvui.counter(frame, 300, 350, sensitivity, 1) cvui.window(frame, 30, 390, 360, 100, "Log") cvui.printf(frame, 50, 420, 0.6, 0xffffff, "Success: %d", success_num) # cvui.update() # Show window content cvui.imshow(WINDOW_NAME, frame) visii = win32gui.IsWindowVisible(hwndMain2) # print(visii) # if cv2.getWindowProperty(WINDOW_NAME, cv2.WND_PROP_AUTOSIZE) is -1: # print(cv2.getWindowProperty(WINDOW_NAME, 1)) # cv2.waitKey(20) if cv2.waitKey(20) == 27 or visii is 0: break cv2.destroyAllWindows()
def main(): lena = cv2.imread('lena.jpg', cv2.IMREAD_COLOR) frame = np.zeros(lena.shape, np.uint8) doubleBuffer = np.zeros(lena.shape, np.uint8) trackbarWidth = 130 # Adjustments values for RGB and HSV rgb = [[1.], [1.], [1]] hsv = [[1.], [1.], [1]] # Copy the loaded image to the buffer doubleBuffer[:] = lena[:] # Init cvui and tell it to use a value of 20 for cv2.waitKey() # because we want to enable keyboard shortcut for # all components, e.g. button with label '&Quit'. # If cvui has a value for waitKey, it will call # waitKey() automatically for us within cvui.update(). cvui.init(WINDOW_NAME, 20) while (True): frame[:] = doubleBuffer[:] frameRows,frameCols,frameChannels = frame.shape # Exit the application if the quit button was pressed. # It can be pressed because of a mouse click or because # the user pressed the 'q' key on the keyboard, which is # marked as a shortcut in the button label ('&Quit'). if cvui.button(frame, frameCols - 100, frameRows - 30, '&Quit'): break # RGB HUD cvui.window(frame, 20, 50, 180, 240, 'RGB adjust') # Within the cvui.beginColumns() and cvui.endColumn(), # all elements will be automatically positioned by cvui. # In a columns, all added elements are vertically placed, # one under the other (from top to bottom). # # Notice that all component calls within the begin/end block # below DO NOT have (x,y) coordinates. # # Let's create a row at position (35,80) with automatic # width and height, and a padding of 10 cvui.beginColumn(frame, 35, 80, -1, -1, 10) rgbModified = False # Trackbar accept a pointer to a variable that controls their value # They return true upon edition if cvui.trackbar(trackbarWidth, rgb[0], 0., 2., 2, '%3.02Lf'): rgbModified = True if cvui.trackbar(trackbarWidth, rgb[1], 0., 2., 2, '%3.02Lf'): rgbModified = True if cvui.trackbar(trackbarWidth, rgb[2], 0., 2., 2, '%3.02Lf'): rgbModified = True cvui.space(2) cvui.printf(0.35, 0xcccccc, ' RGB: %3.02lf,%3.02lf,%3.02lf', rgb[0][0], rgb[1][0], rgb[2][0]) if (rgbModified): b,g,r = cv2.split(lena) b = b * rgb[2][0] g = g * rgb[1][0] r = r * rgb[0][0] cv2.merge((b,g,r), doubleBuffer) cvui.endColumn() # HSV lenaRows,lenaCols,lenaChannels = lena.shape cvui.window(frame, lenaCols - 200, 50, 180, 240, 'HSV adjust') cvui.beginColumn(frame, lenaCols - 180, 80, -1, -1, 10) hsvModified = False if cvui.trackbar(trackbarWidth, hsv[0], 0., 2., 2, '%3.02Lf'): hsvModified = True if cvui.trackbar(trackbarWidth, hsv[1], 0., 2., 2, '%3.02Lf'): hsvModified = True if cvui.trackbar(trackbarWidth, hsv[2], 0., 2., 2, '%3.02Lf'): hsvModified = True cvui.space(2) cvui.printf(0.35, 0xcccccc, ' HSV: %3.02lf,%3.02lf,%3.02lf', hsv[0][0], hsv[1][0], hsv[2][0]) if hsvModified: hsvMat = cv2.cvtColor(lena, cv2.COLOR_BGR2HSV) h,s,v = cv2.split(hsvMat) h = h * hsv[0][0] s = s * hsv[1][0] v = v * hsv[2][0] cv2.merge((h,s,v), hsvMat) doubleBuffer = cv2.cvtColor(hsvMat, cv2.COLOR_HSV2BGR) cvui.endColumn() # Display the lib version at the bottom of the screen cvui.printf(frame, frameCols - 300, frameRows - 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. # # Since cvui.init() received a param regarding waitKey, # there is no need to call cv2.waitKey() anymore. cvui.update() # will do it automatically. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame)
def onWork(self): self.frame[:] = (49, 52, 49) char = cv.waitKey(1) doOverw = False writeOnName = False writeOnSubject = False writeOnProf = False stringCopy = '' stringCopyColor = 0x10dca1 while True: cursor = cvui.mouse(WINDOW_NAME) click = cvui.mouse(cvui.CLICK) # (self, x, y, w, h, title, char, writeOn, cursor, click, writeOnBool): writeOnName, self.folderName = self.textInput( 5, 5, 305, 40, "Folder Name:", char, self.folderName, cursor, click, writeOnName) writeOnSubject, self.subjectName = self.textInput( 5 + X_SCREEN / 2, 5, 305, 40, "Subject Name:", char, self.subjectName, cursor, click, writeOnSubject) writeOnProf, self.tempName = self.textInput( 5 + X_SCREEN / 2, 105, 305, 40, "Professors:", char, self.tempName, cursor, click, writeOnProf) cvui.rect(self.frame, 6 + X_SCREEN / 2, 155, X_SCREEN / 2 - 63, 235 - 165, 0x8d9797, 0x3c4747) cvui.rect(self.frame, X_SCREEN - 52, 155, 47, 235 - 165, 0x8d9797, 0x293939) if cvui.button( self.frame, X_SCREEN - 49, 157, "+") and not self.tempName == '' and len(self.names) < 4: self.names.append(self.tempName) self.tempName = '' if cvui.button(self.frame, X_SCREEN - 49, 196, "-") and not len(self.names) == 0: del self.names[-1] for i in range(len(self.names)): cvui.printf(self.frame, 10 + X_SCREEN / 2, 160 + 15 * i, 0.4, 0xdd97fb, self.names[i]) xp = int((X_SCREEN - 20) / 4) cvui.window(self.frame, 5, 235, X_SCREEN - 10, Y_SCREEN - 235 - 5, "Premade:") if cvui.button(self.frame, 10 + xp - 10 * 11, 260, "Lab. Micro."): self.subjectName = '22.99 Laboratorio De Microprocesadores' self.names.clear() self.names.append('Jacoby, Daniel Andres') self.names.append('Magliola, Nicolas') self.names.append('Ismirlian, Diego Matias') self.group[0] = 3 if cvui.button(self.frame, 10 + xp * 2 - 10 * 7, 260, "Control"): self.subjectName = '22.85 Sistemas de Control' self.names.clear() self.names.append('Nasini, Victor Gustavo') self.names.append('Zujew, Cristian Alejo') if cvui.button(self.frame, 10 + xp * 3 - 10 * 9, 260, "Transinfo"): self.subjectName = '22.61 Transmision de la Informacion' self.names.clear() self.names.append('Bertucci, Eduardo Adolfo') self.names.append('Vila Krause, Luis Gustavo') if cvui.button(self.frame, 10 + xp * 4 - 10 * 11, 260, "Electromag."): self.subjectName = '22.37 Electromagnetismo' self.names.clear() self.names.append('Munoz, Claudio Marcelo') self.names.append('Dobrusin, Pablo') cvui.printf(self.frame, 5, 55, 0.4, 0xdd97fb, f'N Exercises:') cvui.counter(self.frame, 5, 70, self.numberFolder) if self.numberFolder[0] <= 0: cvui.rect(self.frame, 5 + 25, 72, 40, 17, 0x292929, 0x292929) self.numberFolder[0] = 1 cvui.printf(self.frame, 5 + 41, 76, 0.4, 0x9C9C9C, '1') cvui.printf(self.frame, 5 + X_SCREEN / 6, 55, 0.4, 0xdd97fb, f'Day:') cvui.counter(self.frame, 5 + X_SCREEN / 6, 70, self.day) if self.day[0] <= 0: cvui.rect(self.frame, 5 + X_SCREEN / 6 + 25, 72, 40, 17, 0x292929, 0x292929) self.day[0] = 1 cvui.printf(self.frame, 5 + X_SCREEN / 6 + 41, 76, 0.4, 0x9C9C9C, '1') elif self.day[0] >= 31: self.day[0] = 31 cvui.printf(self.frame, 5 + X_SCREEN * 2 / 6, 55, 0.4, 0xdd97fb, f'Month:') cvui.counter(self.frame, 5 + X_SCREEN * 2 / 6, 70, self.month) if self.month[0] <= 0: cvui.rect(self.frame, 5 + X_SCREEN * 2 / 6 + 25, 72, 40, 17, 0x292929, 0x292929) self.month[0] = 1 cvui.printf(self.frame, 5 + X_SCREEN * 2 / 6 + 41, 76, 0.4, 0x9C9C9C, '1') elif self.month[0] >= 12: self.month[0] = 12 cvui.printf(self.frame, 5 + X_SCREEN * 3 / 6, 55, 0.4, 0xdd97fb, f'Year:') cvui.counter(self.frame, 5 + X_SCREEN * 3 / 6, 70, self.year) if self.year[0] <= 19: cvui.rect(self.frame, 5 + X_SCREEN * 3 / 6 + 25, 72, 40, 17, 0x292929, 0x292929) self.year[0] = 20 cvui.printf(self.frame, 5 + X_SCREEN * 3 / 6 + 37, 76, 0.4, 0x9C9C9C, '20') elif self.year[0] >= 22: self.year[0] = 22 cvui.printf(self.frame, 5 + X_SCREEN * 4 / 6, 55, 0.4, 0xdd97fb, f'N Group:') cvui.counter(self.frame, 5 + X_SCREEN * 4 / 6, 70, self.group) if self.group[0] <= 0: cvui.rect(self.frame, 5 + X_SCREEN * 4 / 6 + 25, 72, 40, 17, 0x292929, 0x292929) self.group[0] = 1 cvui.printf(self.frame, 5 + X_SCREEN * 4 / 6 + 41, 76, 0.4, 0x9C9C9C, '1') elif self.group[0] >= 7: self.group[0] = 7 cvui.printf(self.frame, 5 + X_SCREEN * 5 / 6, 55, 0.4, 0xdd97fb, f'N TP:') cvui.counter(self.frame, 5 + X_SCREEN * 5 / 6, 70, self.tp) if self.tp[0] <= 0: cvui.rect(self.frame, 5 + X_SCREEN * 5 / 6 + 25, 72, 40, 17, 0x292929, 0x292929) self.tp[0] = 1 cvui.printf(self.frame, 5 + X_SCREEN * 5 / 6 + 41, 76, 0.4, 0x9C9C9C, '1') if cvui.button(self.frame, X_SCREEN / 4 - 10 * 16 / 2, 110, "Load Folder Path") and not doOverw: self.folderPath = self.getPath() cvui.window(self.frame, 5, 155, X_SCREEN / 2 - 10, 40, "Folder Path Selected") if len(self.folderPath) < MAXCHAR + 3: cvui.printf(self.frame, 10, 180, 0.4, 0xdd97fb, self.folderPath) else: cvui.printf(self.frame, 10, 180, 0.4, 0xdd97fb, self.folderPath[0:MAXCHAR + 2] + '...') if (not self.folderPath == '') and (not self.folderName == '') and (not self.subjectName == ''): if cvui.button(self.frame, 120, 200, "Start Copy"): self.startCopy = True stringCopy = "Wait While Copying..." stringCopyColor = 0xdc1076 cvui.printf(self.frame, 5, 205, 0.4, stringCopyColor, stringCopy) if self.startCopy: self.startCopy = False while self.folderName[-1] == ' ': #32: self.folderName = self.folderName[:-1] finalPath = self.folderPath + '/' + self.folderName coping = self.copyFolders(self.numberFolder[0], finalPath, True) if not coping == None: if not coping: doOverw = True else: stringCopy = "Copy Done!" stringCopyColor = 0x10dca1 else: stringCopy = "Template Not Found!!" stringCopyColor = 0xdc1076 if doOverw: check = self.overWrite(finalPath) if not check == -1: if check == None: stringCopy = "Template Not Found!!" stringCopyColor = 0xdc1076 else: if check == True: stringCopy = "Copy Done!" stringCopyColor = 0x10dca1 else: stringCopy = "Unable To Copy" stringCopyColor = 0xdc1076 doOverw = False cvui.imshow(WINDOW_NAME, self.frame) char = cv.waitKey(1) self.frame[:] = (49, 52, 49) if (char == 27) or not cv.getWindowProperty( WINDOW_NAME, cv.WND_PROP_VISIBLE): break
def renderInfo(self, frame): cvui.window(frame, 10, 50, 100, 120, 'Info') cvui.checkbox(frame, 15, 80, 'Checked', self.checked)
def main(): lena = cv2.imread('lena.jpg', cv2.IMREAD_COLOR) frame = np.zeros(lena.shape, np.uint8) doubleBuffer = np.zeros(lena.shape, np.uint8) trackbarWidth = 130 # Adjustments values for RGB and HSV rgb = [[1.], [1.], [1]] hsv = [[1.], [1.], [1]] # Copy the loaded image to the buffer doubleBuffer[:] = lena[:] # Init cvui and tell it to use a value of 20 for cv2.waitKey() # because we want to enable keyboard shortcut for # all components, e.g. button with label '&Quit'. # If cvui has a value for waitKey, it will call # waitKey() automatically for us within cvui.update(). cvui.init(WINDOW_NAME, 20) while (True): frame[:] = doubleBuffer[:] frameRows, frameCols, frameChannels = frame.shape # Exit the application if the quit button was pressed. # It can be pressed because of a mouse click or because # the user pressed the 'q' key on the keyboard, which is # marked as a shortcut in the button label ('&Quit'). if cvui.button(frame, frameCols - 100, frameRows - 30, '&Quit'): break # RGB HUD cvui.window(frame, 20, 50, 180, 240, 'RGB adjust') # Within the cvui.beginColumns() and cvui.endColumn(), # all elements will be automatically positioned by cvui. # In a columns, all added elements are vertically placed, # one under the other (from top to bottom). # # Notice that all component calls within the begin/end block # below DO NOT have (x,y) coordinates. # # Let's create a row at position (35,80) with automatic # width and height, and a padding of 10 cvui.beginColumn(frame, 35, 80, -1, -1, 10) rgbModified = False # Trackbar accept a pointer to a variable that controls their value # They return true upon edition if cvui.trackbar(trackbarWidth, rgb[0], 0., 2., 2, '%3.02Lf'): rgbModified = True if cvui.trackbar(trackbarWidth, rgb[1], 0., 2., 2, '%3.02Lf'): rgbModified = True if cvui.trackbar(trackbarWidth, rgb[2], 0., 2., 2, '%3.02Lf'): rgbModified = True cvui.space(2) cvui.printf(0.35, 0xcccccc, ' RGB: %3.02lf,%3.02lf,%3.02lf', rgb[0][0], rgb[1][0], rgb[2][0]) if (rgbModified): b, g, r = cv2.split(lena) b = b * rgb[2][0] g = g * rgb[1][0] r = r * rgb[0][0] cv2.merge((b, g, r), doubleBuffer) cvui.endColumn() # HSV lenaRows, lenaCols, lenaChannels = lena.shape cvui.window(frame, lenaCols - 200, 50, 180, 240, 'HSV adjust') cvui.beginColumn(frame, lenaCols - 180, 80, -1, -1, 10) hsvModified = False if cvui.trackbar(trackbarWidth, hsv[0], 0., 2., 2, '%3.02Lf'): hsvModified = True if cvui.trackbar(trackbarWidth, hsv[1], 0., 2., 2, '%3.02Lf'): hsvModified = True if cvui.trackbar(trackbarWidth, hsv[2], 0., 2., 2, '%3.02Lf'): hsvModified = True cvui.space(2) cvui.printf(0.35, 0xcccccc, ' HSV: %3.02lf,%3.02lf,%3.02lf', hsv[0][0], hsv[1][0], hsv[2][0]) if hsvModified: hsvMat = cv2.cvtColor(lena, cv2.COLOR_BGR2HSV) h, s, v = cv2.split(hsvMat) h = h * hsv[0][0] s = s * hsv[1][0] v = v * hsv[2][0] cv2.merge((h, s, v), hsvMat) doubleBuffer = cv2.cvtColor(hsvMat, cv2.COLOR_HSV2BGR) cvui.endColumn() # Display the lib version at the bottom of the screen cvui.printf(frame, frameCols - 300, frameRows - 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. # # Since cvui.init() received a param regarding waitKey, # there is no need to call cv2.waitKey() anymore. cvui.update() # will do it automatically. cvui.update() # Show everything on the screen cv2.imshow(WINDOW_NAME, frame)
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 group(frame, x, y, width, height): padding = 5 w = (width - padding) / 4 h = (height - 15 - padding) / 2 pos = cvui.Point(x + padding, y + 5) cvui.text(frame, pos.x, pos.y, 'Group title') pos.y += 15 cvui.window(frame, pos.x, pos.y, width - padding * 2, h - padding, 'Something') cvui.rect(frame, pos.x + 2, pos.y + 20, width - padding * 2 - 5, h - padding - 20, 0xff0000) pos.y += h cvui.window(frame, pos.x, pos.y, w / 3 - padding, h, 'Some') cvui.text(frame, pos.x + 25, pos.y + 60, '65', 1.1) pos.x += w / 3 cvui.window(frame, pos.x, pos.y, w / 3 - padding, h, 'Info') cvui.text(frame, pos.x + 25, pos.y + 60, '30', 1.1) pos.x += w / 3 cvui.window(frame, pos.x, pos.y, w / 3 - padding, h, 'Here') cvui.text(frame, pos.x + 25, pos.y + 60, '70', 1.1) pos.x += w / 3 cvui.window(frame, pos.x, pos.y, w - padding, h, 'And') cvui.rect(frame, pos.x + 2, pos.y + 22, w - padding - 5, h - padding - 20, 0xff0000) pos.x += w cvui.window(frame, pos.x, pos.y, w - padding, h, 'Here') cvui.rect(frame, pos.x + 2, pos.y + 22, w - padding - 5, h - padding - 20, 0xff0000) pos.x += w cvui.window(frame, pos.x, pos.y, w - padding, h, 'More info') cvui.rect(frame, pos.x + 2, pos.y + 22, w - padding - 5, h - padding - 20, 0xff0000) pos.x += w
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