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 main(): thresholdValue = [108] chooseInt = [0] # Size of trackbars trackbar_width = 400 #init cvui cvui.init(WINDOW_NAME, 20) ui_frame = np.zeros((480, 640, 3), np.uint8) #camera setting cap = cv2.VideoCapture(0) cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 640) cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 480) #main loop while (True): ret, frame = cap.read() #print frame.dtype #to gray gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) ui_frame[:] = (49, 52, 49) cvui.beginColumn(ui_frame, 20, 20, -1, -1, 6) cvui.text('Threshold Adject') cvui.trackbar(trackbar_width, thresholdValue, 0, 255) cvui.counter(chooseInt) cvui.space(5) cvui.text(strArr[chooseInt[0]]) if cvui.button('&Quit'): break cvui.space(5) cvui.endColumn() th1, gray = cv2.threshold(gray, thresholdValue[0], 255, chooseArr[chooseInt[0]]) merged = cv2.merge([gray, gray, gray]) dst = cv2.addWeighted(ui_frame, 1.0, merged, 0.4, 0.0) cvui.update() cv2.imshow(WINDOW_NAME, dst) cap.release() cv2.destroyAllWindows()
scanIntervals=scanIntervals[0], Mean=mean[0], times=times[0], alpha=alpha[0], ksize=ksize[0]))[1].tofile(name + "lowpoly.jpg") startFlag = False global thds thds = 7 global Size while True: # your app logic here frame[:] = (49, 52, 49) cvui.text(frame, 50, 750, 'Produced by BQSG', .6) cvui.beginColumn(frame, 10, 20) if (cvui.button("&OpenFile")): file_path = filedialog.askopenfilename() # print(file_path) if isVideo[0]: try: cap = cv2.VideoCapture(file_path) sumcnt = int(round(cap.get(cv2.CAP_PROP_FRAME_COUNT))) print(sumcnt) for i in range(sumcnt): ret, image = cap.read() if ret: if image.shape[0] > image.shape[1]: image = cv2.resize(image, (int( 800 * image.shape[1] / image.shape[0]), 800), interpolation=cv2.INTER_CUBIC)
def run(self): self.main_frame = np.zeros((380, 400, 3), np.uint8) cv.namedWindow(self.main_window_name) cvui.init(self.main_window_name) while True: cvui.context(self.main_window_name) self.main_frame[:] = (49, 52, 49) cvui.beginColumn(self.main_frame, 50, 20, -1, -1, 10) cvui.text('Click to open an image') if cvui.button('Select Image'): self.load_image() cvui.text('Load a previously saved txt file to current image') if cvui.button("Read Txt file"): self.read_txt() cvui.text('Save to txt file') if cvui.button('Save'): self.save_to_txt() if cvui.button("Show/Hide Index"): self.has_index = not self.has_index if cvui.button("Clear All Points"): self.points.clear() self.high_light_point = None cvui.text('Max click distance to select one point') cvui.text('adjust smaller if you want to click two close points') cvui.trackbar(200, self.threshold, 0.000, 0.02, 2, '%.4Lf') cvui.endColumn() cvui.update(self.main_window_name) cv.imshow(self.main_window_name, self.main_frame) key = cv.waitKey(20) if key == 27 or not self.is_window_open(self.main_window_name): self.tkinter_root.destroy() break if self.is_window_open(self.image_window_name): cvui.context(self.image_window_name) self.show_image = cv.resize( self.origin_image, (self.actual_width, self.actual_height)) for i, point in enumerate(self.points): if i not in self.deleted_list: self.draw_intersection(self.show_image, point, i) if self.high_light_point is not None: point = self.points[self.high_light_point] cv.circle(self.show_image, (int(point[0] * self.actual_width), int(point[1] * self.actual_height)), 5, (0, 255, 255), 1) # Fill the error window if a vibrant color # if self.image_window_flag: cvui.update(self.image_window_name) cv.imshow(self.image_window_name, self.show_image) self.keyboard(key)
def main(): intValue = [30] ucharValue = [30] charValue = [30] floatValue = [12.] doubleValue1 = [15.] doubleValue2 = [10.3] doubleValue3 = [2.25] frame = np.zeros((650, 450, 3), np.uint8) # Size of trackbars width = 400 # 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): # Fill the frame with a nice color frame[:] = (49, 52, 49) cvui.beginColumn(frame, 20, 20, -1, -1, 6) cvui.text('int trackbar, no customization') cvui.trackbar(width, intValue, 0, 100) cvui.space(5) cvui.text('uchar trackbar, no customization') cvui.trackbar(width, ucharValue, 0, 255) cvui.space(5) cvui.text('signed char trackbar, no customization') cvui.trackbar(width, charValue, -128, 127) cvui.space(5) cvui.text('float trackbar, no customization') cvui.trackbar(width, floatValue, 10., 15.) cvui.space(5) cvui.text('float trackbar, 4 segments') cvui.trackbar(width, doubleValue1, 10., 20., 4) cvui.space(5) cvui.text('double trackbar, label %.1Lf, TRACKBAR_DISCRETE') cvui.trackbar(width, doubleValue2, 10., 10.5, 1, '%.1Lf', cvui.TRACKBAR_DISCRETE, 0.1) cvui.space(5) cvui.text('double trackbar, label %.2Lf, 2 segments, TRACKBAR_DISCRETE') cvui.trackbar(width, doubleValue3, 0., 4., 2, '%.2Lf', cvui.TRACKBAR_DISCRETE, 0.25) cvui.space(10) # 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('&Quit'): break cvui.endColumn() # Since cvui.init() received a param regarding waitKey, # there is no need to call cv.waitKey() anymore. cvui.update() # will do it automatically. cvui.update() cv2.imshow(WINDOW_NAME, frame)
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(): # 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
# 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': cvui.text('a* low') cvui.trackbar(width, lowCh1, limitsCh1[0], limitsCh1[1], 10, '%.0Lf', options, 1)
def main(): # We have one mat for each window. frame1 = np.zeros((150, 600, 3), np.uint8) frame2 = np.zeros((150, 600, 3), np.uint8) error_frame = np.zeros((100, 300, 3), np.uint8) # Flag to control if we should show an error window. error = False # Create two OpenCV windows cv2.namedWindow(GUI_WINDOW1_NAME) cv2.namedWindow(GUI_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(GUI_WINDOW1_NAME) # Tell cvui to keep track of mouse events in window2 as well. cvui.watch(GUI_WINDOW2_NAME) while (True): # Inform cvui that all subsequent component calls and events are related to window 1. cvui.context(GUI_WINDOW1_NAME) # Fill the frame with a nice color frame1[:] = (49, 52, 49) cvui.beginColumn(frame1, 50, 20, -1, -1, 10) cvui.text('[Win1] Use the buttons below to control the error window') if cvui.button('Close'): closeWindow(ERROR_WINDOW_NAME) # If the button is clicked, we open the error window. # The content and rendering of such error window will be performed # after we handled all other windows. if cvui.button('Open'): error = True openWindow(ERROR_WINDOW_NAME) cvui.endColumn() # Update all components of window1, e.g. mouse clicks, and show it. cvui.update(GUI_WINDOW1_NAME) cv2.imshow(GUI_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(GUI_WINDOW2_NAME) frame2[:] = (49, 52, 49) cvui.beginColumn(frame2, 50, 20, -1, -1, 10) cvui.text('[Win2] Use the buttons below to control the error window') if cvui.button('Close'): closeWindow(ERROR_WINDOW_NAME) # If the button is clicked, we open the error window. # The content and rendering of such error window will be performed # after we handled all other windows. if cvui.button('Open'): openWindow(ERROR_WINDOW_NAME) error = True cvui.endColumn() # Update all components of window2, e.g. mouse clicks, and show it. cvui.update(GUI_WINDOW2_NAME) cv2.imshow(GUI_WINDOW2_NAME, frame2) # Handle the content and rendering of the error window, # if we have un active error and the window is actually open. if error and isWindowOpen(ERROR_WINDOW_NAME): # Inform cvui that all subsequent component calls and events are # related to the error window from now on cvui.context(ERROR_WINDOW_NAME) # Fill the error window if a vibrant color error_frame[:] = (10, 10, 49) cvui.text(error_frame, 70, 20, 'This is an error message', 0.4, 0xff0000) if cvui.button(error_frame, 110, 40, 'Close'): error = False if error: # We still have an active error. # Update all components of the error window, e.g. mouse clicks, and show it. cvui.update(ERROR_WINDOW_NAME) cv2.imshow(ERROR_WINDOW_NAME, error_frame) else: # No more active error. Let's close the error window. closeWindow(ERROR_WINDOW_NAME) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def main(): intValue = [30] ucharValue = [30] charValue = [30] floatValue = [12.] doubleValue1 = [15.] doubleValue2 = [10.3] doubleValue3 = [2.25] frame = np.zeros((650, 450, 3), np.uint8) # Size of trackbars width = 400 # 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): # Fill the frame with a nice color frame[:] = (49, 52, 49) cvui.beginColumn(frame, 20, 20, -1, -1, 6) cvui.text('int trackbar, no customization') cvui.trackbar(width, intValue, 0, 100) cvui.space(5) cvui.text('uchar trackbar, no customization') cvui.trackbar(width, ucharValue, 0, 255) cvui.space(5) cvui.text('signed char trackbar, no customization') cvui.trackbar(width, charValue, -128, 127) cvui.space(5) cvui.text('float trackbar, no customization') cvui.trackbar(width, floatValue, 10., 15.) cvui.space(5) cvui.text('float trackbar, 4 segments') cvui.trackbar(width, doubleValue1, 10., 20., 4) cvui.space(5) cvui.text('double trackbar, label %.1Lf, TRACKBAR_DISCRETE') cvui.trackbar(width, doubleValue2, 10., 10.5, 1, '%.1Lf', cvui.TRACKBAR_DISCRETE, 0.1) cvui.space(5) cvui.text( 'double trackbar, label %.2Lf, 2 segments, TRACKBAR_DISCRETE') cvui.trackbar(width, doubleValue3, 0., 4., 2, '%.2Lf', cvui.TRACKBAR_DISCRETE, 0.25) cvui.space(10) # 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('&Quit'): break cvui.endColumn() # Since cvui.init() received a param regarding waitKey, # there is no need to call cv.waitKey() anymore. cvui.update() # will do it automatically. cvui.update() cv2.imshow(WINDOW_NAME, frame)
def main(): frame = np.zeros((600, 800, 3), np.uint8) values = [] checked = [False] value = [1.0] # 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) # Define a row at position (10, 50) with width 100 and height 150. cvui.beginRow(frame, 10, 50, 100, 150) # The components below will be placed one beside the other. cvui.text('Row starts') cvui.button('here') # When a column or row is nested within another, it behaves like # an ordinary component with the specified size. In this case, # let's create a column with width 100 and height 50. The # next component added will behave like it was added after # a component with width 100 and heigth 150. cvui.beginColumn(100, 150) cvui.text('Column 1') cvui.button('button1') cvui.button('button2') cvui.button('button3') cvui.text('End of column 1') cvui.endColumn() # Add two pieces of text cvui.text('Hi again,') cvui.text('its me!') # Start a new column cvui.beginColumn(100, 50) cvui.text('Column 2') cvui.button('button1') cvui.button('button2') cvui.button('button3') cvui.space() cvui.text('Another text') cvui.space(40) cvui.text('End of column 2') cvui.endColumn() # Add more text cvui.text('this is the ') cvui.text('end of the row!') cvui.endRow() # Here is another nested row/column cvui.beginRow(frame, 50, 300, 100, 150) # If you don't want to calculate the size of any row/column WITHIN # a begin*()/end*() block, just use negative width/height when # calling beginRow() or beginColumn() (or don't provide width/height at all!) # For instance, the following column will have its width/height # automatically adjusted according to its content. cvui.beginColumn() cvui.text('Column 1') cvui.button('button with very large label') cvui.text('End of column 1') cvui.endColumn() # Add two pieces of text cvui.text('Hi again,') cvui.text('its me!') # Start a new column cvui.beginColumn() cvui.text('Column 2') cvui.button('btn') cvui.space() cvui.text('text') cvui.button('btn2') cvui.text('text2') if cvui.button('&Quit'): break cvui.endColumn() # Add more text cvui.text('this is the ') cvui.text('end of the row!') cvui.endRow() # 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) 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(): 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(): 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