def main(): frame = np.zeros((300, 600, 3), np.uint8) out = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR) down = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR) over = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR) # 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) # Render an image-based button. You can provide images # to be used to render the button when the mouse cursor is # outside, over or down the button area. if cvui.button(frame, 200, 80, out, over, down): print('Image button clicked!') cvui.text(frame, 150, 200, 'This image behaves as a button') # Render a regular button. if cvui.button(frame, 360, 80, 'Button'): print('Regular button clicked!') # 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) out = cv2.imread('lena-face.jpg', cv2.IMREAD_COLOR) down = cv2.imread('lena-face-red.jpg', cv2.IMREAD_COLOR) over = cv2.imread('lena-face-gray.jpg', cv2.IMREAD_COLOR) # 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) # Render an image-based button. You can provide images # to be used to render the button when the mouse cursor is # outside, over or down the button area. if cvui.button(frame, 200, 80, out, over, down): print('Image button clicked!') cvui.text(frame, 150, 200, 'This image behaves as a button') # Render a regular button. if cvui.button(frame, 360, 80, 'Button'): print('Regular button clicked!') # 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 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 main(save_dir, laser_off): make_save_dir(save_dir) rs_mng = RealSenseManager() # default image size = (1280, 720) if laser_off: rs_mng.laser_turn_off() else: rs_mng.laser_turn_on() image_width, image_height = rs_mng.image_size res_image_width = int(image_width * 2 / 3) res_image_height = int(image_height * 2 / 3) window_image_width = int(image_width * 4 / 3) window_image_height = int(image_height) cvui.init("capture") frame = np.zeros((window_image_height, window_image_width, 3), np.uint8) captured_frame_count = count_images(save_dir) while True: key = cv2.waitKey(10) frame[:] = (49, 52, 49) status = rs_mng.update() if status: # Get Images ir_image_left = rs_mng.ir_frame_left ir_image_right = rs_mng.ir_frame_right color_image = rs_mng.color_frame depth_image = rs_mng.depth_frame depth_image_aligned2color = rs_mng.depth_frame_aligned2color # Visualize Images frame = draw_frames(frame, color_image, depth_image, res_image_width, res_image_height) if cvui.button(frame, 50, res_image_height + 50, 130, 50, "Save Result Image") or key & 0xFF == ord("s"): save_images(color_image, depth_image, depth_image_aligned2color, ir_image_left, ir_image_right, save_dir) captured_frame_count += 1 if cvui.button(frame, 200, res_image_height + 50, 130, 50, "Clear"): clean_save_dir(save_dir) captured_frame_count = 0 cvui.printf(frame, 50, res_image_height + 150, 0.8, 0x00FF00, "Number of Captured Images : %d", captured_frame_count) if key & 0xFF == ord("q"): break cvui.update() cvui.imshow("capture", frame) cv2.destroyAllWindows() del rs_mng
def main(): # We have one mat for each window. frame1 = np.zeros((1024, 768, 3), np.uint8) # Create variables used by some components window1_values = [] window2_values = [] img = cv2.imread('Images/yoga.jpg', cv2.IMREAD_COLOR) imgRed = cv2.imread('Images/mic.jpg', cv2.IMREAD_COLOR) imgGray = cv2.imread('Images/gamb.jpg', cv2.IMREAD_COLOR) img = cv2.resize(img, (200, 200)) imgRed = cv2.resize(imgGray, (200, 200)) imgGray = cv2.resize(imgRed, (200, 200)) 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, -1, -1, 10) cvui.image(img) cvui.button(img, imgGray, imgRed) cvui.endRow() # Update all components of window1, e.g. mouse clicks, and show it. cvui.update(WINDOW1_NAME) cv2.imshow(WINDOW1_NAME, frame1) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
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(toml_path, directory_for_save, config_name, rgb_rate, scale_for_visualization): rgb_manager = RGBCaptureManager(toml_path) inference = create_inference(config_name) width, height = rgb_manager.size scaling = partial(scaling_int, scale=scale_for_visualization) width_resized = scaling(width) height_resized = scaling(height) frame = np.zeros((height_resized + 300, width_resized * 2, 3), np.uint8) WINDOW_NAME = "Capture" cvui.init(WINDOW_NAME) while True: frame[:] = (49, 52, 49) key = cv2.waitKey(10) status = rgb_manager.update() if not status: continue rgb_image_raw = rgb_manager.read() rgb_image_masked = get_masked_image_with_segmentation( rgb_image_raw, rgb_manager, inference, rgb_rate) number_of_saved_frame = get_number_of_saved_image(directory_for_save) cvui.printf(frame, 50, height_resized + 50, 0.8, 0x00FF00, "Number of Captured Images : %d", number_of_saved_frame) if cvui.button(frame, 50, height_resized + 110, 200, 100, "capture image") or key & 0xFF == ord("s"): save_image(rgb_image_raw, directory_for_save) if cvui.button(frame, 300, height_resized + 110, 200, 100, "erase"): clean_save_dir(directory_for_save) rgb_image_resized = cv2.resize(rgb_image_raw, (width_resized, height_resized)) masked_image_resized = cv2.resize(rgb_image_masked, (width_resized, height_resized)) frame[0:height_resized, 0:width_resized, :] = rgb_image_resized frame[0:height_resized, width_resized:(width_resized * 2), :] = masked_image_resized if key == 27 or key == ord("q"): break cvui.update() cvui.imshow(WINDOW_NAME, frame) cv2.destroyAllWindows()
def main(): frame = np.zeros((150, 650, 3), np.uint8) # 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.text(frame, 40, 40, 'To exit this app click the button below or press Q (shortcut for the button below).') # 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, 300, 80, "&Quit"): break # 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 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(): frame = np.zeros((150, 650, 3), np.uint8) # 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.text( frame, 40, 40, 'To exit this app click the button below or press Q (shortcut for the button below).' ) # 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, 300, 80, "&Quit"): break # 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 window(name): # Create a frame for this window and fill it with a nice color frame = np.zeros((200, 500, 3), np.uint8) frame[:] = (49, 52, 49) # Inform cvui that the components to be rendered from now one belong to # a window in particular. # # If you don't inform that, cvui will assume the components belong to # the default window (informed in cvui.init()). In that case, the # interactions with all other windows being used will not work. cvui.context(name) # Show info regarding the window cvui.printf(frame, 110, 50, '%s - click the button', name) # Buttons return true if they are clicked if cvui.button(frame, 110, 90, 'Button'): cvui.printf(frame, 200, 95, 'Button clicked!') print('Button clicked on: ', name) # Tell cvui to update its internal structures regarding a particular window. # # If cvui is being used in multiple windows, you need to enclose all component # calls between the pair cvui.context(NAME)/cvui.update(NAME), where NAME is # the name of the window being worked on. cvui.update(name) # Show the content of this window on the screen cvui.imshow(name, frame)
def main(): frame = np.zeros((200, 500, 3), np.uint8) count = 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) # Buttons will return true if they were clicked, which makes # handling clicks a breeze. if (cvui.button(frame, 110, 80, "Hello, world!")): # The button was clicked, so let's increment our counter. count += 1 # 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. # Let's show how many times the button has been clicked. cvui.printf(frame, 250, 90, 0.4, 0xff0000, "Button click count: %d", count) # Update cvui stuff and show everything on the screen cvui.imshow(WINDOW_NAME, frame) # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
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(): frame = np.zeros((200, 500, 3), np.uint8) count = 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) # Buttons will return true if they were clicked, which makes # handling clicks a breeze. if (cvui.button(frame, 110, 80, "Hello, world!")): # The button was clicked, so let's increment our counter. count += 1 # 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. # Let's show how many times the button has been clicked. cvui.printf(frame, 250, 90, 0.4, 0xff0000, "Button click count: %d", count); # Update cvui stuff and show everything on the screen cvui.imshow(WINDOW_NAME, frame); # Check if ESC key was pressed if cv2.waitKey(20) == 27: break
def _cvui_gui(self, frame): if self._status: rgb_resize = cv2.resize(self._rgb_img.copy(), (1280, 720)) frame[:720, :1280, :] = rgb_resize if cvui.button(frame, 10, 800, 200, 50, "capture image") and self._status: self._save_image() cvui.text(frame, 300, 800, 'Image Num = {}'.format(self._file_count), 0.5)
def show_capture(self, *args): print(self.cam.isOpened()) while(self.cam.isOpened()): ret, frame=self.cam.read() if cvui.button(frame, 0, 150, "Quit"): break self.user_interface(global_image=frame) if(cv2.waitKey(1) > 0):pass self.cam.release() cv2.destroyAllWindows()
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()
def main(): frame = np.zeros((300, 800, 3), np.uint8) value = [2.25] values = [] # Init cvui and tell it to create a OpenCV window, i.e. cv.namedWindow(WINDOW_NAME). cvui.init(WINDOW_NAME, 20) 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 (20,80) with automatic width and height, and a padding of 10 cvui.beginRow(frame, 20, 80, -1, -1, 10); # trackbar accepts a pointer to a variable that controls their value. # Here we define a double trackbar between 0. and 5. if cvui.trackbar(150, value, 0., 5.): print('Trackbar was modified, value : ', value[0]) values.append(value[0]) if len(values) > 5: cvui.text('Your edits on a sparkline ->') cvui.sparkline(values, 240, 60) if cvui.button('Clear sparkline'): values = [] else: cvui.text('<- Move the trackbar') 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 adjustHyperparameters(l, hyperparameters, hyperparametersListNames, frameToShow, WINDOW_NAME, organizationTab): root = tk.Tk() horizontal = root.winfo_screenwidth() vertical = root.winfo_screenheight() if len(frameToShow[0]) > horizontal or len(frameToShow) > vertical: frameToShow = cv2.resize(frameToShow, (int(horizontal*0.8), int(vertical*0.8))) root.destroy() WINDOW_NAME_CTRL = "Adjust Parameters." frameNum = [l] hyperparametersList = [[hyperparameters[name]] for name in hyperparametersListNames] frameCtrlLengthY = math.ceil((len(hyperparametersListNames) + 2)/2) * 70 + 20 buttonclicked = False while frameNum[0] == l and hyperparametersList == [[hyperparameters[name]] for name in hyperparametersListNames] and not(buttonclicked): frameCtrl = np.full((frameCtrlLengthY, 1100), 100).astype('uint8') printStuffOnCtrlImg(frameCtrl, frameNum, 1, 35, 350, hyperparameters["firstFrame"], hyperparameters["lastFrame"], "Frame number", "You can also go through the video with the keys a or 4 (backward); d or 6 (forward); f or g (fast backward); h or j (fast forward)") for idx, hyperParamCurVal in enumerate(hyperparametersList): [minn, maxx] = printStuffOnCtrlImg(frameCtrl, hyperParamCurVal, organizationTab[idx][0], organizationTab[idx][1], organizationTab[idx][2], organizationTab[idx][3], organizationTab[idx][4], hyperparametersListNames[idx], organizationTab[idx][5]) organizationTab[idx][3] = minn organizationTab[idx][4] = maxx buttonclicked = cvui.button(frameCtrl, organizationTab[len(organizationTab)-1][0], organizationTab[len(organizationTab)-1][1], "Ok, done!") # cvui.text(frameCtrl, 100, 245, 'Warning: for some of the "overwrite" parameters, you will need to change the initial value for the "overwrite" to take effect.') cvui.imshow(WINDOW_NAME, frameToShow) cvui.imshow(WINDOW_NAME_CTRL, frameCtrl) r = cv2.waitKey(20) if (r == 54) or (r == 100) or (r == 0): frameNum[0] = frameNum[0] + 1 elif (r == 52) or (r == 97) or (r == 113): frameNum[0] = frameNum[0] - 1 l = int(frameNum[0]) if l >= hyperparameters["lastFrame"]: l = hyperparameters["lastFrame"] - 1 if l <= hyperparameters["firstFrame"]: l = hyperparameters["firstFrame"] for idx, hyperParamCurVal in enumerate(hyperparametersList): hyperparameters[hyperparametersListNames[idx]] = hyperParamCurVal[0] if buttonclicked: newhyperparameters = {} for idx, hyperparameterName in enumerate(hyperparametersListNames): newhyperparameters[hyperparameterName] = hyperparameters[hyperparameterName] pickle.dump(newhyperparameters, open('newhyperparameters', 'wb')) cv2.destroyAllWindows() raise ValueError return [l, hyperparameters, organizationTab]
def buttons_create_monitor(self): ortho_button_press = cvui.button(self.mainframe, 450, 650, 100, 30, self.ortho_button_text) if ortho_button_press and self.ortho_mode == False: self.ortho_mode = True self.ortho_button_text = 'ORTHO ON' elif ortho_button_press and self.ortho_mode == True: self.ortho_mode = False self.ortho_button_text = 'ORTHO OFF' autotune_button_press = cvui.button(self.mainframe, 450, 690, 100, 30, self.autotune_button_text) if autotune_button_press and self.autotune_mode == False: self.autotune_mode = True self.autotune_button_text = 'AUTO TUNE OFF' elif autotune_button_press and self.autotune_mode == True: self.autotune_mode = False self.autotune_button_text = 'AUTO TUNE ON' focus_button_press = cvui.button(self.mainframe, 570, 650, 100, 30, self.focus_button_text) if focus_button_press and self.start_focus_mode == True: self.start_focus_mode = False self.focus_button_text = 'FOCUS START' elif focus_button_press and self.start_focus_mode == False: self.start_focus_mode = True self.focus_button_text = 'FOCUS STOP' cal_button_press = cvui.button(self.mainframe, 570, 690, 100, 30, self.cal_button_text) if cal_button_press and self.cal_mode == True: self.cal_mode = False self.cal_button_text = 'CAL HOLD' elif cal_button_press and self.cal_mode == False: self.cal_mode = True self.cal_button_text = 'CAL HOLDING'
def drawGUI(width, x): global actionValue global moveValue frame[:] = (49, 52, 49) cvui.rect(frame, 2, 2, 355, 120, 0xffaa77, 0x4444aa) cvui.rect(frame, 2, 125, 355, 55, 0xffaa77, 0x4444aa) ######################################################### cvui.text(frame, x, 5, 'repeatValue (0 - 10)') cvui.trackbar(frame, x, 10, width, repeatValue, 0, 10, 1, '%.0Lf') cvui.text(frame, x, 65, 'moveValue (10 - 100)') cvui.trackbar(frame, x, 75, width, moveValue, 1, 100, 1, '%.0Lf') ######################################################### cvui.text(frame, x + (80 * 1.25), 130, "role") if cvui.button(frame, x, 145, "Horizon"): return "Horizon" if cvui.button(frame, x + (80 * 1.25), 145, "Vertical"): return "Vertical" if cvui.button(frame, x + (80 * 2.5), 145, "Stop"): return "Stop" if cvui.button(frame, x + (80 * 3.5), 145, "Exit"): exit() #cvui.update() cv2.imshow(WINDOW_NAME, frame) return ""
def compact(name): # Create a frame for this window and fill it with a nice color frame = np.zeros((200, 500, 3), np.uint8) frame[:] = (49, 52, 49) # Inform cvui that the components to be rendered from now one belong to # a window in particular. # # If you don't inform that, cvui will assume the components belong to # the default window (informed in cvui.init()). In that case, the # interactions with all other windows being used will not work. cvui.context(name) cvui.printf(frame, 110, 50, '%s - click the button', name) if cvui.button(frame, 110, 90, 'Button'): cvui.printf(frame, 200, 95, 'Button clicked!') print('Button clicked on: ', name) # Tell cvui to update its internal structures regarding a particular window # then show it. Below we are using cvui.imshow(), which is cvui's version of # the existing cv2.imshow(). They behave exactly the same, the only difference # is that cvui.imshow() will automatically call cvui.update(name) for you. cvui.imshow(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 prepareConfigFileForParamsAdjustements(configFile, wellNumber, firstFrameParamAdjust, videoToCreateConfigFileFor, adjustOnWholeVideo): initialFirstFrameValue = -1 initialLastFrameValue = -1 if "firstFrame" in configFile: initialFirstFrameValue = configFile["firstFrame"] if "lastFrame" in configFile: initialLastFrameValue = configFile["lastFrame"] cap = cv2.VideoCapture(videoToCreateConfigFileFor) max_l = int(cap.get(7)) if int(firstFrameParamAdjust): cap.set(1, 1) ret, frame = cap.read() WINDOW_NAME = "Choose where you want to start the procedure to adjust parameters." WINDOW_NAME_CTRL = "Control" cvui.init(WINDOW_NAME) cv2.moveWindow(WINDOW_NAME, 0,0) cvui.init(WINDOW_NAME_CTRL) cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300) value = [1] curValue = value[0] buttonclicked = False widgetX = 40 widgetY = 50 widgetL = 300 while not(buttonclicked): value[0] = int(value[0]) if curValue != value[0]: cap.set(1, value[0]) frameOld = frame ret, frame = cap.read() if not(ret): frame = frameOld curValue = value[0] frameCtrl = np.full((200, 400), 100).astype('uint8') frameCtrl[widgetY:widgetY+60, widgetX:widgetX+widgetL] = 0 cvui.text(frameCtrl, widgetX, widgetY, 'Frame') cvui.trackbar(frameCtrl, widgetX, widgetY+10, widgetL, value, 0, max_l-1) cvui.counter(frameCtrl, widgetX, widgetY+60, value) buttonclicked = cvui.button(frameCtrl, widgetX, widgetY+90, "Ok, I want the procedure to start at this frame.") cvui.text(frameCtrl, widgetX, widgetY+130, 'Keys: 4 or a: move backwards; 6 or d: move forward') cvui.text(frameCtrl, widgetX, widgetY+160, 'Keys: g or f: fast backwards; h or j: fast forward') cvui.imshow(WINDOW_NAME, frame) cvui.imshow(WINDOW_NAME_CTRL, frameCtrl) r = cv2.waitKey(20) if (r == 54) or (r == 100) or (r == 0): value[0] = value[0] + 1 elif (r == 52) or (r == 97) or (r == 113): value[0] = value[0] - 1 elif (r == 103): value[0] = value[0] - 30 elif (r == 104): value[0] = value[0] + 30 elif (r == 102): value[0] = value[0] - 100 elif (r == 106): value[0] = value[0] + 100 configFile["firstFrame"] = int(value[0]) cv2.destroyAllWindows() if not(int(adjustOnWholeVideo)): if ("lastFrame" in configFile): if (configFile["lastFrame"] - configFile["firstFrame"] > 500): configFile["lastFrame"] = configFile["firstFrame"] + 500 else: configFile["lastFrame"] = min(configFile["firstFrame"] + 500, max_l-10) else: if not(int(adjustOnWholeVideo)): if ("firstFrame" in configFile) and ("lastFrame" in configFile): if configFile["lastFrame"] - configFile["firstFrame"] > 500: configFile["lastFrame"] = configFile["firstFrame"] + 500 else: configFile["firstFrame"] = 1 configFile["lastFrame"] = min(max_l-10, 500) if "lastFrame" in configFile: if configFile["lastFrame"] > initialLastFrameValue and initialLastFrameValue != -1: configFile["lastFrame"] = initialLastFrameValue if len(wellNumber) != 0: configFile["onlyTrackThisOneWell"] = int(wellNumber) else: configFile["onlyTrackThisOneWell"] = 0 configFile["reloadBackground"] = 1 return [configFile, initialFirstFrameValue, initialLastFrameValue]
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 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
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) else:
# starting point of first line of arrow head p = (int(q[0] + arrow_magnitude * np.cos(angle + np.pi / 4)), int(q[1] + arrow_magnitude * np.sin(angle + np.pi / 4))) # draw first half of arrow head cv2.line(image, p, q, color, thickness, line_type, shift) # starting point of second line of arrow head p = (int(q[0] + arrow_magnitude * np.cos(angle - np.pi / 4)), int(q[1] + arrow_magnitude * np.sin(angle - np.pi / 4))) # draw second half of arrow head cv2.line(image, p, q, color, thickness, line_type, shift) if (len(new_epoints) > 2): fill_poligon = True # define button functions: if cvui.button(frame, layout_space_video + video_size_x + 30, 50, 'Clear All'): data = {} data['savedPoints'] = [] setZone = 0 setEntryExit = 0 if cvui.button(frame, layout_space_video + video_size_x + 30, 90, 'Set Zone'): setZone = 1 setEntryExit = 0 triggerSave = 1 if cvui.button(frame, layout_space_video + video_size_x + 30, 130, 'Set Entry/Exit'): setZone = 0 setEntryExit = 1
int(0.1 * frame_width):int(0.88 * frame_width)] frameR = frameR[0:frame_height, int(0.05 * frame_width):int(0.88 * frame_width)] frame_cat = cv.hconcat((frameL, frameR)) frame_height, frame_width = frame_cat.shape[:2] frame_cat[int(xLine - 1):int(xLine + 1), :] = [0, 255, 0] frame_cat[:, int(YLLeft - 1):int(YLLeft + 1)] = [0, 255, 0] frame_cat[:, int(YLRight - 1):int(YLRight + 1)] = [0, 255, 0] cv.circle(frame_cat, (YLLeft, xLine), radiusL, (0, 255, 0)) cv.circle(frame_cat, (YLRight, xLine), radiusR, (0, 255, 0)) cv.circle(frame_cat, (YLLeft, xLine), 240, (0, 255, 0)) if (cvui.button(cvui_img, start_col, start_row, button_width, button_height, "Ball")): object_dict['object'] = 'q' print("Ball clicked") if (cvui.button(cvui_img, start_col, start_row + 50, button_width, button_height, "Cube")): object_dict['object'] = 'm' print("Cube clicked") if (cvui.button(cvui_img, start_col, start_row + 100, button_width, button_height, "Up")): object_dict['action'] = 'z' print("Up clicked") if (cvui.button(cvui_img, start_col, start_row + 150, button_width, button_height, "Down")):
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(): global TOML_PATH_ZENSE global DATA_SAVE_DIR global WINDOW_NAME global IMAGE_WIDTH global IMAGE_HEIGHT if not os.path.exists(DATA_SAVE_DIR): os.mkdir(DATA_SAVE_DIR) if not os.path.exists(osp.join(DATA_SAVE_DIR, "depth")): os.mkdir(osp.join(DATA_SAVE_DIR, "depth")) if not os.path.exists(osp.join(DATA_SAVE_DIR, "color")): os.mkdir(osp.join(DATA_SAVE_DIR, "color")) number_of_saved_frame = len( glob.glob(osp.join(DATA_SAVE_DIR, "depth", "*.png"))) zense_mng = PyPicoZenseManager(0) cvui.init(WINDOW_NAME) key = cv2.waitKey(20) while ((key & 0xFF != ord('q')) or (key & 0xFF != 27)): status = zense_mng.update() if status: rgb_img = zense_mng.getRGBImage() depth_img = zense_mng.getDepthImage() rgb_img_resized = cv2.resize(rgb_img, (IMAGE_WIDTH, IMAGE_HEIGHT)) depth_img_colorized = np.zeros([IMAGE_HEIGHT, IMAGE_WIDTH, 3]).astype(np.uint8) depth_img_colorized[:, :, 1] = 255 depth_img_colorized[:, :, 2] = 255 _depth_img_zense_hue = depth_img.copy().astype(np.float32) _depth_img_zense_hue[np.where(_depth_img_zense_hue > 2000)] = 0 zero_idx = np.where((_depth_img_zense_hue > 2000) | (_depth_img_zense_hue == 0)) _depth_img_zense_hue *= 255.0 / 2000.0 depth_img_colorized[:, :, 0] = _depth_img_zense_hue.astype(np.uint8) depth_img_colorized = cv2.cvtColor(depth_img_colorized, cv2.COLOR_HSV2RGB) depth_img_colorized[zero_idx[0], zero_idx[1], :] = 0 frame = np.zeros((IMAGE_HEIGHT * 2, IMAGE_WIDTH * 2, 3), np.uint8) frame[0:IMAGE_HEIGHT, 0:IMAGE_WIDTH, :] = rgb_img_resized frame[0:IMAGE_HEIGHT, IMAGE_WIDTH:IMAGE_WIDTH * 2, :] = depth_img_colorized cvui.printf(frame, 50, IMAGE_HEIGHT + 50, 0.8, 0x00ff00, "Number of Captured Images : %d", number_of_saved_frame) if (cvui.button(frame, 100, IMAGE_HEIGHT + 100, 200, 100, "Capture")) or (key & 0xFF == ord('s')): cv2.imwrite( osp.join(DATA_SAVE_DIR, "depth", "%06d.png" % (number_of_saved_frame)), depth_img) cv2.imwrite( osp.join(DATA_SAVE_DIR, "color", "%06d.png" % (number_of_saved_frame)), rgb_img) number_of_saved_frame += 1 if cvui.button(frame, 350, IMAGE_HEIGHT + 100, 200, 100, "Erase Images"): shutil.rmtree(osp.join(DATA_SAVE_DIR, "depth")) os.mkdir(osp.join(DATA_SAVE_DIR, "depth")) shutil.rmtree(osp.join(DATA_SAVE_DIR, "color")) os.mkdir(osp.join(DATA_SAVE_DIR, "color")) number_of_saved_frame = 0 cvui.update() cv2.imshow(WINDOW_NAME, frame) key = cv2.waitKey(20) if key == 27: 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 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 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 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(): 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 chooseVideoToTroubleshootSplitVideo(self, controller): # Choosing video to split if globalVariables["mac"]: self.videoToTroubleshootSplitVideo = filedialog.askopenfilename(initialdir = os.path.expanduser("~"),title = "Select video") else: self.videoToTroubleshootSplitVideo = filedialog.askopenfilename(initialdir = os.path.expanduser("~"),title = "Select video",filetypes = (("video","*.*"),("all files","*.*"))) # User input of beginning and end of subvideo firstFrame = 1 lastFrame = 1000 cap = cv2.VideoCapture(self.videoToTroubleshootSplitVideo) max_l = int(cap.get(7)) - 2 cap.set(1, 1) ret, frame = cap.read() WINDOW_NAME = "Choose where the beginning of your sub-video should be." WINDOW_NAME_CTRL = "Control" cvui.init(WINDOW_NAME) cv2.moveWindow(WINDOW_NAME, 0,0) cvui.init(WINDOW_NAME_CTRL) cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300) value = [1] curValue = value[0] buttonclicked = False widgetX = 40 widgetY = 20 widgetL = 300 while not(buttonclicked): value[0] = int(value[0]) if curValue != value[0]: cap.set(1, value[0]) frameOld = frame ret, frame = cap.read() if not(ret): frame = frameOld curValue = value[0] frameCtrl = np.full((200, 750), 100).astype('uint8') frameCtrl[widgetY:widgetY+60, widgetX:widgetX+widgetL] = 0 cvui.text(frameCtrl, widgetX, widgetY, 'Frame') cvui.trackbar(frameCtrl, widgetX, widgetY+10, widgetL, value, 0, max_l) cvui.counter(frameCtrl, widgetX, widgetY+60, value) buttonclicked = cvui.button(frameCtrl, widgetX, widgetY+90, "Ok, I want the sub-video to start at this frame!") cvui.text(frameCtrl, widgetX, widgetY+130, 'Keys: 4 or a: move backwards; 6 or d: move forward') cvui.text(frameCtrl, widgetX, widgetY+160, 'Keys: g or f: fast backwards; h or j: fast forward') cvui.imshow(WINDOW_NAME, frame) cvui.imshow(WINDOW_NAME_CTRL, frameCtrl) r = cv2.waitKey(20) if (r == 54) or (r == 100) or (r == 0): value[0] = value[0] + 1 elif (r == 52) or (r == 97) or (r == 113): value[0] = value[0] - 1 elif (r == 103): value[0] = value[0] - 30 elif (r == 104): value[0] = value[0] + 30 elif (r == 102): value[0] = value[0] - 100 elif (r == 106): value[0] = value[0] + 100 cv2.destroyAllWindows() firstFrame = int(value[0]) cap.set(1, max_l) ret, frame = cap.read() while not(ret): max_l = max_l - 1 cap.set(1, max_l) ret, frame = cap.read() WINDOW_NAME = "Choose where the sub-video should end." WINDOW_NAME_CTRL = "Control" cvui.init(WINDOW_NAME) cv2.moveWindow(WINDOW_NAME, 0,0) cvui.init(WINDOW_NAME_CTRL) cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300) value = [max_l] curValue = value[0] buttonclicked = False widgetX = 40 widgetY = 20 widgetL = 300 while not(buttonclicked): value[0] = int(value[0]) if curValue != value[0]: cap.set(1, value[0]) frameOld = frame ret, frame = cap.read() if not(ret): frame = frameOld curValue = value[0] frameCtrl = np.full((200, 400), 100).astype('uint8') frameCtrl[widgetY:widgetY+60, widgetX:widgetX+widgetL] = 0 cvui.text(frameCtrl, widgetX, widgetY, 'Frame') cvui.trackbar(frameCtrl, widgetX, widgetY+10, widgetL, value, firstFrame + 1, max_l-1) cvui.counter(frameCtrl, widgetX, widgetY+60, value) buttonclicked = cvui.button(frameCtrl, widgetX, widgetY+90, "Ok, I want the sub-video to end at this frame!") cvui.text(frameCtrl, widgetX, widgetY+130, 'Keys: 4 or a: move backwards; 6 or d: move forward') cvui.text(frameCtrl, widgetX, widgetY+160, 'Keys: g or f: fast backwards; h or j: fast forward') cvui.imshow(WINDOW_NAME, frame) cvui.imshow(WINDOW_NAME_CTRL, frameCtrl) r = cv2.waitKey(20) if (r == 54) or (r == 100) or (r == 0): value[0] = value[0] + 1 elif (r == 52) or (r == 97) or (r == 113): value[0] = value[0] - 1 elif (r == 103): value[0] = value[0] - 30 elif (r == 104): value[0] = value[0] + 30 elif (r == 102): value[0] = value[0] - 100 elif (r == 106): value[0] = value[0] + 100 lastFrame = int(value[0]) cv2.destroyAllWindows() cap.release() # Choosing directory to save sub-video directoryChosen = filedialog.askdirectory(title='Choose in which folder you want to save the sub-video.') # Extracting sub-video cap = cv2.VideoCapture(self.videoToTroubleshootSplitVideo) if (cap.isOpened()== False): print("Error opening video stream or file") frame_width = int(cap.get(3)) frame_height = int(cap.get(4)) xmin = 0 xmax = frame_width ymin = 0 ymax = frame_height out = cv2.VideoWriter(os.path.join(directoryChosen, 'subvideo.avi'), cv2.VideoWriter_fourcc('M','J','P','G'), 10, (xmax-xmin,ymax-ymin)) i = firstFrame maxx = lastFrame cap.set(1, i) while(cap.isOpened() and (i<maxx)): i = i + 1 ret, frame = cap.read() if ret == True: frame2 = frame[ymin:ymax,xmin:xmax] if False: frame2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY) frame2 = cv2.cvtColor(frame2, cv2.COLOR_GRAY2BGR) out.write(frame2) else: break cap.release() self.show_frame("VideoToTroubleshootSplitVideo")
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 draw_settings(ctrl_frame, control_panes, canny_state, threshold_state, stage_mode, focus_mode, tracker_mode): # define the mutually-exclusive mode toggles stage_manual = [stage_mode == 'MANUAL'] stage_auto = [stage_mode == 'AUTO'] stage_paused = [stage_mode == 'PAUSED'] focus_manual = [focus_mode == 'MANUAL'] focus_sharpness = [focus_mode == 'SHARPNESS'] focus_depth = [focus_mode == 'DEPTH'] tracker_box_kcf = [tracker_mode == 'KCF'] tracker_box_canny = [tracker_mode == 'CANNY'] tracker_box_threshold = [tracker_mode == 'THRESHOLD'] macro_resweep = False ll_resweep = False control_panes.stage_control_pane.begin(ctrl_frame) if not control_panes.stage_control_pane.isMinimized(): cvui.space(100) # add 20px of empty space cvui.checkbox('Stage Paused', stage_paused) cvui.checkbox('Stage Manual', stage_manual) cvui.checkbox('Stage Auto', stage_auto) control_panes.stage_control_pane.end() control_panes.focus_control_pane.begin(ctrl_frame) if not control_panes.focus_control_pane.isMinimized(): cvui.space(80) # add 20px of empty space cvui.checkbox('Focus Manual', focus_manual) cvui.checkbox('Focus Sharpness', focus_sharpness) cvui.checkbox('Focus Depth', focus_depth) control_panes.focus_control_pane.end() control_panes.tracker_select_pane.begin(ctrl_frame) if not control_panes.tracker_select_pane.isMinimized(): cvui.space(60) # add 20px of empty space cvui.checkbox('KCF Tracker', tracker_box_kcf) cvui.checkbox('Canny Tracker', tracker_box_canny) cvui.checkbox('Threshold Tracker', tracker_box_threshold) control_panes.tracker_select_pane.end() control_panes.canny_settings_pane.begin(ctrl_frame) if not control_panes.canny_settings_pane.isMinimized(): cvui.space(40) # add 20px of empty space cvui.text('Canny Low Threshold') cvui.trackbar(control_panes.canny_settings_pane.width() - 20, canny_state.canny_low, 5, 150) cvui.text('Canny High Threshold') cvui.trackbar(control_panes.canny_settings_pane.width() - 20, canny_state.canny_high, 80, 300) control_panes.canny_settings_pane.end() control_panes.threshold_setting_pane.begin(ctrl_frame) if not control_panes.threshold_setting_pane.isMinimized(): cvui.space(20) # add 20px of empty space cvui.text('Binarization Threshold') cvui.trackbar(control_panes.threshold_setting_pane.width() - 20, threshold_state.threshold, 0, 255) cvui.checkbox('Show Binary Image', threshold_state.show_binary) cvui.text('MOVE THESE!!!!') if cvui.button('Force Macro Focus Sweep'): macro_resweep = True else: macro_resweep = False if cvui.button('Liquid Lens Focus Sweep'): ll_resweep = True else: ll_resweep = False control_panes.threshold_setting_pane.end() if stage_manual[0] and not stage_mode == 'MANUAL': stage_mode = 'MANUAL' elif stage_auto[0] and not stage_mode == 'AUTO': stage_mode = 'AUTO' elif stage_paused[0] and not stage_mode == 'PAUSED': stage_mode = 'PAUSED' if focus_manual[0] and not focus_mode == 'MANUAL': focus_mode = 'MANUAL' elif focus_sharpness[0] and not focus_mode == 'SHARPNESS': focus_mode = 'SHARPNESS' elif focus_depth[0] and not focus_mode == 'DEPTH': focus_mode = 'DEPTH' if tracker_box_kcf[0] and not tracker_mode == 'KCF': tracker_mode = 'KCF' elif tracker_box_canny[0] and not tracker_mode == 'CANNY': tracker_mode = 'CANNY' elif tracker_box_threshold and not tracker_mode == 'THRESHOLD': tracker_mode = 'THRESHOLD' return stage_mode, focus_mode, tracker_mode, macro_resweep, ll_resweep
def main(): frame = np.zeros((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