Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    def textInput(self, x, y, w, h, title, char, writeOn, cursor, click,
                  writeOnBool):

        cvui.window(self.frame, x, y, w, h, title)
        # cvui.rect(self.frame, x + 1, y + 17, w - 2, h - 18, 0xf20c0c, 0xf20c0c)
        inBox = ((x + 1 <= cursor.x <= x + 1 + w - 2)
                 and (y + 17 <= cursor.y <= y + 17 + h - 18))

        if (inBox and click) or writeOnBool:
            writeOnBool = True
            if len(writeOn) < MAXCHAR:

                validChar = (32 <= char <= 33 or 35 <= char <= 41
                             or 43 <= char <= 46 or 48 <= char <= 57
                             or char == 59 or char == 61 or 64 <= char <= 91
                             or 93 <= char <= 123 or 125 <= char <= 127)
                if validChar:
                    writeOn = writeOn + chr(char)
                elif char == 8 and not len(writeOn) == 0:
                    writeOn = writeOn[:-1]
            elif 8 == char:
                writeOn = writeOn[:-1]

            self.t1 = self.darwBar(writeOn, self.t1, x + 5, y + 25)

        else:
            cvui.printf(self.frame, x + 5, y + 25, 0.4, 0xdd97fb, f'{writeOn}')

        if click and not inBox:
            writeOnBool = False

        return writeOnBool, writeOn
def 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
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
 def darwBar(self, text, t1, x, y):
     t2 = time.perf_counter()
     if t2 - t1 <= 1:
         cvui.printf(self.frame, x, y, 0.4, 0xdd97fb, f'{text}|')
         return t1
     elif 1 < t2 - t1 <= 2:
         cvui.printf(self.frame, x, y, 0.4, 0xdd97fb, f'{text}')
         return t1
     else:
         return t2
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
def main():
    frame = np.zeros((300, 600, 3), np.uint8)

    # 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 a rectangle on the screen.
        rectangle = cvui.Rect(50, 50, 100, 100)
        cvui.rect(frame, rectangle.x, rectangle.y, rectangle.width,
                  rectangle.height, 0xff0000)

        # Check what is the current status of the mouse cursor
        # regarding the previously rendered rectangle.
        status = cvui.iarea(rectangle.x, rectangle.y, rectangle.width,
                            rectangle.height)

        # cvui::iarea() will return the current mouse status:
        #  CLICK: mouse just clicked the interaction are
        #	DOWN: mouse button was pressed on the interaction area, but not released yet.
        #	OVER: mouse cursor is over the interaction area
        #	OUT: mouse cursor is outside the interaction area
        if status == cvui.CLICK: print('Rectangle was clicked!')
        if status == cvui.DOWN: cvui.printf(frame, 240, 70, "Mouse is: DOWN")
        if status == cvui.OVER: cvui.printf(frame, 240, 70, "Mouse is: OVER")
        if status == cvui.OUT: cvui.printf(frame, 240, 70, "Mouse is: OUT")

        # Show the coordinates of the mouse pointer on the screen
        cvui.printf(frame, 240, 50, "Mouse pointer is at (%d,%d)",
                    cvui.mouse().x,
                    cvui.mouse().y)

        # 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
Ejemplo n.º 11
0
def main():
	frame = np.zeros((300, 600, 3), np.uint8)

	# 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 a rectangle on the screen.
		rectangle = cvui.Rect(50, 50, 100, 100)
		cvui.rect(frame, rectangle.x, rectangle.y, rectangle.width, rectangle.height, 0xff0000)

		# Check what is the current status of the mouse cursor
		# regarding the previously rendered rectangle.
		status = cvui.iarea(rectangle.x, rectangle.y, rectangle.width, rectangle.height);

		# cvui::iarea() will return the current mouse status:
		#  CLICK: mouse just clicked the interaction are
		#	DOWN: mouse button was pressed on the interaction area, but not released yet.
		#	OVER: mouse cursor is over the interaction area
		#	OUT: mouse cursor is outside the interaction area
		if status == cvui.CLICK:  print('Rectangle was clicked!')
		if status == cvui.DOWN:   cvui.printf(frame, 240, 70, "Mouse is: DOWN")
		if status == cvui.OVER:   cvui.printf(frame, 240, 70, "Mouse is: OVER")
		if status == cvui.OUT:	  cvui.printf(frame, 240, 70, "Mouse is: OUT")

		# Show the coordinates of the mouse pointer on the screen
		cvui.printf(frame, 240, 50, "Mouse pointer is at (%d,%d)", cvui.mouse().x, cvui.mouse().y)

		# 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
Ejemplo n.º 12
0
def main():
	lena = cv2.imread('lena.jpg')
	frame = np.zeros(lena.shape, np.uint8)
	anchor = cvui.Point()
	roi = cvui.Rect(0, 0, 0, 0)
	working = False

	# 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 Lena's image
		frame[:] = lena[:]

		# Show the coordinates of the mouse pointer on the screen
		cvui.text(frame, 10, 10, 'Click (any) mouse button and drag the pointer around to select a ROI.')

		# The function 'bool cvui.mouse(int query)' allows you to query the mouse for events.
		# E.g. cvui.mouse(cvui.DOWN)
		#
		# Available queries:
		#	- cvui.DOWN: any mouse button was pressed. cvui.mouse() returns true for single frame only.
		#	- cvui.UP: any mouse button was released. cvui.mouse() returns true for single frame only.
		#	- cvui.CLICK: any mouse button was clicked (went down then up, no matter the amount of frames in between). cvui.mouse() returns true for single frame only.
		#	- cvui.IS_DOWN: any mouse button is currently pressed. cvui.mouse() returns true for as long as the button is down/pressed.

		# Did any mouse button go down?
		if cvui.mouse(cvui.DOWN):
			# Position the anchor at the mouse pointer.
			anchor.x = cvui.mouse().x
			anchor.y = cvui.mouse().y

			# Inform we are working, so the ROI window is not updated every frame
			working = True

		# Is any mouse button down (pressed)?
		if cvui.mouse(cvui.IS_DOWN):
			# Adjust roi dimensions according to mouse pointer
			width = cvui.mouse().x - anchor.x
			height = cvui.mouse().y - anchor.y
			
			roi.x = anchor.x + width if width < 0 else anchor.x
			roi.y = anchor.y + height if height < 0 else anchor.y
			roi.width = abs(width)
			roi.height = abs(height)

			# Show the roi coordinates and size
			cvui.printf(frame, roi.x + 5, roi.y + 5, 0.3, 0xff0000, '(%d,%d)', roi.x, roi.y)
			cvui.printf(frame, cvui.mouse().x + 5, cvui.mouse().y + 5, 0.3, 0xff0000, 'w:%d, h:%d', roi.width, roi.height)

		# Was the mouse clicked (any button went down then up)?
		if cvui.mouse(cvui.UP):
			# We are done working with the ROI.
			working = False

		# Ensure ROI is within bounds
		lenaRows, lenaCols, lenaChannels = lena.shape
		roi.x = 0 if roi.x < 0 else roi.x
		roi.y = 0 if roi.y < 0 else roi.y
		roi.width = roi.width + lena.cols - (roi.x + roi.width) if roi.x + roi.width > lenaCols else roi.width
		roi.height = roi.height + lena.rows - (roi.y + roi.height) if roi.y + roi.height > lenaRows else roi.height

		# Render the roi
		cvui.rect(frame, roi.x, roi.y, roi.width, roi.height, 0xff0000)

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

		# If the ROI is valid, show it.
		if roi.area() > 0 and working == False:
			lenaRoi = lena[roi.y : roi.y + roi.height, roi.x : roi.x + roi.width]
			cv2.imshow(ROI_WINDOW, lenaRoi)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
Ejemplo n.º 13
0
def main(toml_path, directory_for_save, save_raw_data, scale, timelapse_mode,
         interval_minute):
    make_save_dir(directory_for_save)
    see3cam_mng = RgbCameraManager(toml_path)
    lens_undistorter = LensUndistorter(toml_path)
    scaling = partial(scaling_int, scale=scale)

    WINDOW_NAME = "Capture"
    cvui.init(WINDOW_NAME)
    while True:
        key = cv2.waitKey(10)
        frame = np.zeros((scaling(960), scaling(1400), 3), np.uint8)
        frame[:] = (49, 52, 49)

        status = see3cam_mng.update()

        number_of_saved_frame = len(
            glob.glob(os.path.join(directory_for_save, "*.png")))
        cvui.printf(frame, 50, scaling(750), 0.8, 0x00FF00,
                    "Number of Captured Images : %d", number_of_saved_frame)

        if status:
            see3cam_rgb_image_raw = see3cam_mng.read()
            see3cam_rgb_image_undist = lens_undistorter.correction(
                see3cam_rgb_image_raw)
            scaled_width = scaling(1280)
            scaled_height = scaling(720)
            see3cam_rgb_resize = cv2.resize(see3cam_rgb_image_undist,
                                            (scaled_width, scaled_height))

            cvui.text(frame, 10, 10, "See3CAM", 0.5)
            frame[10:scaled_height + 10,
                  10:scaled_width + 10, :] = see3cam_rgb_resize

            # For time lapse capturing
            capture_condition = cvui.button(
                frame, 50, scaling(800), 200, 100,
                "capture image") or key & 0xFF == ord("s")
            if timelapse_mode:
                current_time = datetime.now()
                if current_time.minute % interval_minute == 0 and current_time.second % 60 == 0:
                    print("captured:{}, time:{}".format(
                        number_of_saved_frame, current_time))
                    capture_condition = True

            if capture_condition:
                if status:
                    if save_raw_data:
                        save_image(see3cam_rgb_image_raw, directory_for_save)
                    else:
                        save_image(see3cam_rgb_image_undist,
                                   directory_for_save)

            if timelapse_mode:
                time.sleep(1)

            if cvui.button(frame, 300, scaling(800), 200, 100, "erase"):
                clean_save_dir(directory_for_save)

        if key == 27 or key == ord("q"):
            break

        cvui.update()
        cvui.imshow(WINDOW_NAME, frame)
    cv2.destroyAllWindows()
def main():
    # We have one mat for each window.
    frame1 = np.zeros((200, 500, 3), np.uint8)
    frame2 = np.zeros((200, 500, 3), np.uint8)
    frame3 = np.zeros((200, 500, 3), np.uint8)

    # Init cvui, instructing it to create 3 OpenCV windows.
    windows = [WINDOW1_NAME, WINDOW2_NAME, WINDOW3_NAME]
    cvui.init(windows, 3)

    while (True):
        # clear all frames
        frame1[:] = (49, 52, 49)
        frame2[:] = (49, 52, 49)
        frame3[:] = (49, 52, 49)

        # Inform cvui that all subsequent component calls and events are related to window 1.
        # We do that by calling cvui.context().
        cvui.context(WINDOW1_NAME)
        cvui.printf(
            frame1, 10, 10,
            'In window1, mouse is at: %d,%d (obtained from window name)',
            cvui.mouse(WINDOW1_NAME).x,
            cvui.mouse(WINDOW1_NAME).y)
        if cvui.mouse(WINDOW1_NAME, cvui.LEFT_BUTTON, cvui.IS_DOWN):
            cvui.printf(frame1, 10, 30,
                        'In window1, mouse LEFT_BUTTON is DOWN')
        cvui.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.
        cvui.context(WINDOW2_NAME)
        cvui.printf(frame2, 10, 10,
                    'In window2, mouse is at: %d,%d (obtained from context)',
                    cvui.mouse().x,
                    cvui.mouse().y)
        if cvui.mouse(cvui.LEFT_BUTTON, cvui.IS_DOWN):
            cvui.printf(frame2, 10, 30,
                        'In window2, mouse LEFT_BUTTON is DOWN')
        cvui.imshow(WINDOW2_NAME, frame2)

        # Finally we are going to render the thrid window. Again we need to inform cvui
        # that all updates and components from now on are connected to window 3.
        cvui.context(WINDOW3_NAME)
        cvui.printf(frame3, 10, 10, 'In window1, mouse is at: %d,%d',
                    cvui.mouse(WINDOW1_NAME).x,
                    cvui.mouse(WINDOW1_NAME).y)
        cvui.printf(frame3, 10, 30, 'In window2, mouse is at: %d,%d',
                    cvui.mouse(WINDOW2_NAME).x,
                    cvui.mouse(WINDOW2_NAME).y)
        cvui.printf(frame3, 10, 50, 'In window3, mouse is at: %d,%d',
                    cvui.mouse(WINDOW3_NAME).x,
                    cvui.mouse(WINDOW3_NAME).y)
        if cvui.mouse(WINDOW1_NAME, cvui.LEFT_BUTTON, cvui.IS_DOWN):
            cvui.printf(frame3, 10, 90, 'window1: LEFT_BUTTON is DOWN')
        if cvui.mouse(WINDOW2_NAME, cvui.LEFT_BUTTON, cvui.IS_DOWN):
            cvui.printf(frame3, 10, 110, 'window2: LEFT_BUTTON is DOWN')
        if cvui.mouse(WINDOW3_NAME, cvui.LEFT_BUTTON, cvui.IS_DOWN):
            cvui.printf(frame3, 10, 130, 'window3: LEFT_BUTTON is DOWN')
        cvui.imshow(WINDOW3_NAME, frame3)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
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()
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
def main():
    frame = np.zeros((300, 600, 3), np.uint8)

    # Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME).
    cvui.init(WINDOW_NAME)

    # Rectangle to be rendered according to mouse interactions.
    rectangle = cvui.Rect(0, 0, 0, 0)

    while (True):
        # Fill the frame with a nice color
        frame[:] = (49, 52, 49)

        # Show the coordinates of the mouse pointer on the screen
        cvui.text(
            frame, 10, 30,
            'Click (any) mouse button and drag the pointer around to select an area.'
        )
        cvui.printf(frame, 10, 50, 'Mouse pointer is at (%d,%d)',
                    cvui.mouse().x,
                    cvui.mouse().y)

        # The function "bool cvui.mouse(int query)" allows you to query the mouse for events.
        # E.g. cvui.mouse(cvui.DOWN)
        #
        # Available queries:
        #	- cvui.DOWN: any mouse button was pressed. cvui.mouse() returns true for a single frame only.
        #	- cvui.UP: any mouse button was released. cvui.mouse() returns true for a single frame only.
        #	- cvui.CLICK: any mouse button was clicked (went down then up, no matter the amount of frames in between). cvui.mouse() returns true for a single frame only.
        #	- cvui.IS_DOWN: any mouse button is currently pressed. cvui.mouse() returns true for as long as the button is down/pressed.

        # Did any mouse button go down?
        if cvui.mouse(cvui.DOWN):
            # Position the rectangle at the mouse pointer.
            rectangle.x = cvui.mouse().x
            rectangle.y = cvui.mouse().y

        # Is any mouse button down (pressed)?
        if cvui.mouse(cvui.IS_DOWN):
            # Adjust rectangle dimensions according to mouse pointer
            rectangle.width = cvui.mouse().x - rectangle.x
            rectangle.height = cvui.mouse().y - rectangle.y

            # Show the rectangle coordinates and size
            cvui.printf(frame, rectangle.x + 5, rectangle.y + 5, 0.3, 0xff0000,
                        '(%d,%d)', rectangle.x, rectangle.y)
            cvui.printf(frame,
                        cvui.mouse().x + 5,
                        cvui.mouse().y + 5, 0.3, 0xff0000, 'w:%d, h:%d',
                        rectangle.width, rectangle.height)

        # Did any mouse button go up?
        if cvui.mouse(cvui.UP):
            # Hide the rectangle
            rectangle.x = 0
            rectangle.y = 0
            rectangle.width = 0
            rectangle.height = 0

        # Was the mouse clicked (any button went down then up)?
        if cvui.mouse(cvui.CLICK):
            cvui.text(frame, 10, 70, 'Mouse was clicked!')

        # Render the rectangle
        cvui.rect(frame, rectangle.x, rectangle.y, rectangle.width,
                  rectangle.height, 0xff0000)

        # This function must be called *AFTER* all UI components. It does
        # all the behind the scenes magic to handle mouse clicks, etc, then
        # shows the frame in a window like cv2.imshow() does.
        cvui.imshow(WINDOW_NAME, frame)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
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
            cvui.text(frame, 10, 355, "Min Max")

            cvui.text(frame, 100, 285, "Starting")
            cvui.counter(frame, 100, 300, Starting, 10)
            cvui.text(frame, 200, 285, "Width")
            cvui.counter(frame, 200, 300, area_width, 10)
            cvui.text(frame, 300, 285, "Height")
            cvui.counter(frame, 300, 300, area_height, 10)
            cvui.text(frame, 100, 335, "Max")
            cvui.counter(frame, 100, 350, cap_max, 100)
            cvui.text(frame, 200, 335, "Min")
            cvui.counter(frame, 200, 350, cap_min, 100)
            cvui.text(frame, 300, 335, "sensitivity")
            cvui.counter(frame, 300, 350, sensitivity, 1)
            cvui.window(frame, 30, 390, 360, 100, "Log")
            cvui.printf(frame, 50, 420, 0.6, 0xffffff, "Success: %d",
                        success_num)

        # cvui.update()
        # Show window content
        cvui.imshow(WINDOW_NAME, frame)
        visii = win32gui.IsWindowVisible(hwndMain2)
        # print(visii)
        # if cv2.getWindowProperty(WINDOW_NAME, cv2.WND_PROP_AUTOSIZE) is -1:
        #     print(cv2.getWindowProperty(WINDOW_NAME, 1))

        # cv2.waitKey(20)
        if cv2.waitKey(20) == 27 or visii is 0:
            break
            cv2.destroyAllWindows()
            # print("aaa")
        # if visii is 0:
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
def main():
    lena = cv2.imread('lena.jpg')
    frame = np.zeros(lena.shape, np.uint8)
    anchors = [cvui.Point()
               for i in range(3)]  # one anchor for each mouse button
    rois = [cvui.Rect() for i in range(3)]  # one ROI for each mouse button
    colors = [0xff0000, 0x00ff00, 0x0000ff]

    # 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 Lena's image
        frame[:] = lena[:]

        # Show the coordinates of the mouse pointer on the screen
        cvui.text(
            frame, 10, 10,
            'Click (any) mouse button then drag the pointer around to select a ROI.'
        )
        cvui.text(
            frame, 10, 25,
            'Use different mouse buttons (right, middle and left) to select different ROIs.'
        )

        # Iterate all mouse buttons (left, middle  and right button)
        button = cvui.LEFT_BUTTON
        while button <= cvui.RIGHT_BUTTON:
            # Get the anchor, ROI and color associated with the mouse button
            anchor = anchors[button]
            roi = rois[button]
            color = colors[button]

            # The function 'bool cvui.mouse(int button, int query)' allows you to query a particular mouse button for events.
            # E.g. cvui.mouse(cvui.RIGHT_BUTTON, cvui.DOWN)
            #
            # Available queries:
            #	- cvui.DOWN: mouse button was pressed. cvui.mouse() returns true for single frame only.
            #	- cvui.UP: mouse button was released. cvui.mouse() returns true for single frame only.
            #	- cvui.CLICK: mouse button was clicked (went down then up, no matter the amount of frames in between). cvui.mouse() returns true for single frame only.
            #	- cvui.IS_DOWN: mouse button is currently pressed. cvui.mouse() returns true for as long as the button is down/pressed.

            # Did the mouse button go down?
            if cvui.mouse(button, cvui.DOWN):
                # Position the anchor at the mouse pointer.
                anchor.x = cvui.mouse().x
                anchor.y = cvui.mouse().y

            # Is any mouse button down (pressed)?
            if cvui.mouse(button, cvui.IS_DOWN):
                # Adjust roi dimensions according to mouse pointer
                width = cvui.mouse().x - anchor.x
                height = cvui.mouse().y - anchor.y

                roi.x = anchor.x + width if width < 0 else anchor.x
                roi.y = anchor.y + height if height < 0 else anchor.y
                roi.width = abs(width)
                roi.height = abs(height)

                # Show the roi coordinates and size
                cvui.printf(frame, roi.x + 5, roi.y + 5, 0.3, color, '(%d,%d)',
                            roi.x, roi.y)
                cvui.printf(frame,
                            cvui.mouse().x + 5,
                            cvui.mouse().y + 5, 0.3, color, 'w:%d, h:%d',
                            roi.width, roi.height)

            # Ensure ROI is within bounds
            lenaRows, lenaCols, lenaChannels = lena.shape
            roi.x = 0 if roi.x < 0 else roi.x
            roi.y = 0 if roi.y < 0 else roi.y
            roi.width = roi.width + lenaCols - (
                roi.x +
                roi.width) if roi.x + roi.width > lenaCols else roi.width
            roi.height = roi.height + lenaRows - (
                roi.y +
                roi.height) if roi.y + roi.height > lenaRows else roi.height

            # If the ROI is valid, render it in the frame and show in a window.
            if roi.area() > 0:
                cvui.rect(frame, roi.x, roi.y, roi.width, roi.height, color)
                cvui.printf(frame, roi.x + 5, roi.y - 10, 0.3, color, 'ROI %d',
                            button)

                lenaRoi = lena[roi.y:roi.y + roi.height,
                               roi.x:roi.x + roi.width]
                cv2.imshow('ROI button' + str(button), lenaRoi)

            button += 1

        # 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
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
    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
Ejemplo n.º 25
0
 def createPrint(self, y, x, charsize, charcolor, Info, vars):
     cvui.printf(self.background, y, x, charsize, charcolor, Info, vars)
Ejemplo n.º 26
0
    def Setting(self):
        wallpaper = cv.imread('wallpaper.jpg')
        frame = cv.resize(wallpaper, (self.WindowHeight, self.WindowWidth))
        x = 1920 / 2 - self.WindowWidth / 2
        y = 1080 / 2 - self.WindowHeight / 2
        # print(x, y)
        # cv.namedWindow(winname=self.WindowName)
        cvui.init(self.WindowName)
        cv.moveWindow(winname=self.WindowName, x=450, y=190)
        cur = frame
        choose = 0
        signin = time.strftime("%Y-%m-%d %H:%M:%S",
                               time.localtime()) + ' (default) '
        text = ''
        set = 0
        while True:
            # frame[:] = self.color
            frame = cv.resize(wallpaper, (self.WindowHeight, self.WindowWidth))
            status, cap = self.capture.read()
            cap = cv.resize(cap, (600, 600))
            cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            cvui.printf(frame, 30, 30, 0.7, 0xff0000, "current    time : %s",
                        cur_time)
            cvui.printf(frame, 30, 70, 0.7, 0xff0000, "signin     time : %s",
                        signin)
            cvui.printf(frame, 30, 100, 0.7, 0xff0000, "computer time : %s",
                        int(time.time()))
            if cvui.button(frame, 30, 180, 'Linux Button') == True:
                choose = 1
                signin = '2020-05-20 08:00:00'
                # signin = '2020-05-20 01:46:30' #test

            if cvui.button(frame, 150, 180, 'algebra Button') == True:
                choose = 0
                signin = '2020-05-21 07:58:00'
                # signin = '2020-05-21 01:00:40' #test
            if cvui.button(frame, 300, 180, 'set name') == True:
                set = set ^ 1
            cvui.image(frame, 590, 10, cap)
            cvui.printf(frame, 30, 250, 0.7, 0xff0000, "your choice : %s",
                        'Linux' if choose == 1 else 'algebra')
            if set == 1:
                cv.putText(frame, 'your name :' + text, (30, 300),
                           cv.FONT_HERSHEY_COMPLEX, 1.0, 0xff0000, 2)
            cvui.update(theWindowName=self.WindowName)
            cv.imshow(self.WindowName, frame)
            c = cv.waitKey(10)

            if int(time.time()) % 1800 == 0:
                '''
                Report On Time
                '''
                ReportOnTime(Time=cur_time)

            if c == 27:
                break
            if 48 <= c <= 57 or 97 <= c <= 122 or 65 <= c <= 90 and set == 1:
                text += chr(c)
            if c == 8 and len(text) != 0 and set == 1:
                text = text[0:-1]
            if c == 13 and set == 1:
                msg = '''successfully initialize'''
                tk.messagebox.showinfo(title='tips', message=msg)
                set = 0
            if signin == cur_time:
                web() if choose == 1 else SignIn()
                break
        cv.destroyWindow(winname=self.WindowName)
Ejemplo n.º 27
0
def main():
    lena = cv2.imread('lena.jpg')
    frame = np.zeros(lena.shape, np.uint8)
    anchor = cvui.Point()
    roi = cvui.Rect(0, 0, 0, 0)
    working = False

    # 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 Lena's image
        frame[:] = lena[:]

        # Show the coordinates of the mouse pointer on the screen
        cvui.text(
            frame, 10, 10,
            'Click (any) mouse button and drag the pointer around to select a ROI.'
        )

        # The function 'bool cvui.mouse(int query)' allows you to query the mouse for events.
        # E.g. cvui.mouse(cvui.DOWN)
        #
        # Available queries:
        #	- cvui.DOWN: any mouse button was pressed. cvui.mouse() returns true for single frame only.
        #	- cvui.UP: any mouse button was released. cvui.mouse() returns true for single frame only.
        #	- cvui.CLICK: any mouse button was clicked (went down then up, no matter the amount of frames in between). cvui.mouse() returns true for single frame only.
        #	- cvui.IS_DOWN: any mouse button is currently pressed. cvui.mouse() returns true for as long as the button is down/pressed.

        # Did any mouse button go down?
        if cvui.mouse(cvui.DOWN):
            # Position the anchor at the mouse pointer.
            anchor.x = cvui.mouse().x
            anchor.y = cvui.mouse().y

            # Inform we are working, so the ROI window is not updated every frame
            working = True

        # Is any mouse button down (pressed)?
        if cvui.mouse(cvui.IS_DOWN):
            # Adjust roi dimensions according to mouse pointer
            width = cvui.mouse().x - anchor.x
            height = cvui.mouse().y - anchor.y

            roi.x = anchor.x + width if width < 0 else anchor.x
            roi.y = anchor.y + height if height < 0 else anchor.y
            roi.width = abs(width)
            roi.height = abs(height)

            # Show the roi coordinates and size
            cvui.printf(frame, roi.x + 5, roi.y + 5, 0.3, 0xff0000, '(%d,%d)',
                        roi.x, roi.y)
            cvui.printf(frame,
                        cvui.mouse().x + 5,
                        cvui.mouse().y + 5, 0.3, 0xff0000, 'w:%d, h:%d',
                        roi.width, roi.height)

        # Was the mouse clicked (any button went down then up)?
        if cvui.mouse(cvui.UP):
            # We are done working with the ROI.
            working = False

        # Ensure ROI is within bounds
        lenaRows, lenaCols, lenaChannels = lena.shape
        roi.x = 0 if roi.x < 0 else roi.x
        roi.y = 0 if roi.y < 0 else roi.y
        roi.width = roi.width + lena.cols - (
            roi.x + roi.width) if roi.x + roi.width > lenaCols else roi.width
        roi.height = roi.height + lena.rows - (
            roi.y +
            roi.height) if roi.y + roi.height > lenaRows else roi.height

        # Render the roi
        cvui.rect(frame, roi.x, roi.y, roi.width, roi.height, 0xff0000)

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

        # If the ROI is valid, show it.
        if roi.area() > 0 and working == False:
            lenaRoi = lena[roi.y:roi.y + roi.height, roi.x:roi.x + roi.width]
            cv2.imshow(ROI_WINDOW, lenaRoi)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
Ejemplo n.º 28
0
def main(save_dir):
    make_save_dir(save_dir)
    zense_camera = PyZenseManager()
    pt2_camera = PyPureThermal2()
    image_width, image_height = zense_camera.image_size

    res_image_width = int(image_width * 0.75)
    res_image_height = int(image_height * 0.75)
    window_image_width = int(res_image_width * 3)
    window_image_height = int(res_image_height * 1.5)

    cvui.init("capture")
    frame = np.zeros((window_image_height, window_image_width + 540, 3),
                     np.uint8)
    captured_frame_count = count_images(save_dir)

    while True:
        key = cv2.waitKey(10)
        frame[:] = (49, 52, 49)

        status = zense_camera.update(verbose=UPDATE_VERBOSE)
        status &= pt2_camera.update()
        if status:
            # Get Images
            ir_image = zense_camera.ir_image.copy()
            depth_image = zense_camera.depth_image.copy()

            thermal_image = pt2_camera.thermal_image.copy()
            thermal_image_colorized = pt2_camera.thermal_image_colorized.copy()

            # Visualize Images
            frame = draw_frames(frame, depth_image, ir_image,
                                thermal_image_colorized, res_image_width,
                                res_image_height)
            if cvui.button(frame, 50, window_image_height - 50, 130, 50,
                           "Save Result Image") or key & 0xFF == ord("s"):
                save_images(
                    depth_image,
                    ir_image,
                    thermal_image,
                    thermal_image_colorized,
                    save_dir,
                )
                captured_frame_count += 1

            if cvui.button(frame, 200, window_image_height - 50, 130, 50,
                           "Clear"):
                clean_save_dir(save_dir)
                captured_frame_count = 0

            cvui.printf(
                frame,
                900,
                window_image_height - 30,
                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()
Ejemplo n.º 29
0
def main():
	lena = cv2.imread('lena.jpg')
	frame = np.zeros(lena.shape, np.uint8)
	anchors = [cvui.Point() for i in range(3)]   # one anchor for each mouse button
	rois = [cvui.Rect() for i in range(3)]       # one ROI for each mouse button
	colors = [0xff0000, 0x00ff00, 0x0000ff]

	# 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 Lena's image
		frame[:] = lena[:]

		# Show the coordinates of the mouse pointer on the screen
		cvui.text(frame, 10, 10, 'Click (any) mouse button then drag the pointer around to select a ROI.')
		cvui.text(frame, 10, 25, 'Use different mouse buttons (right, middle and left) to select different ROIs.')

		# Iterate all mouse buttons (left, middle  and right button)
		button = cvui.LEFT_BUTTON
		while button <= cvui.RIGHT_BUTTON:
			# Get the anchor, ROI and color associated with the mouse button
			anchor = anchors[button]
			roi = rois[button]
			color = colors[button]

			# The function 'bool cvui.mouse(int button, int query)' allows you to query a particular mouse button for events.
			# E.g. cvui.mouse(cvui.RIGHT_BUTTON, cvui.DOWN)
			#
			# Available queries:
			#	- cvui.DOWN: mouse button was pressed. cvui.mouse() returns true for single frame only.
			#	- cvui.UP: mouse button was released. cvui.mouse() returns true for single frame only.
			#	- cvui.CLICK: mouse button was clicked (went down then up, no matter the amount of frames in between). cvui.mouse() returns true for single frame only.
			#	- cvui.IS_DOWN: mouse button is currently pressed. cvui.mouse() returns true for as long as the button is down/pressed.

			# Did the mouse button go down?
			if cvui.mouse(button, cvui.DOWN):
				# Position the anchor at the mouse pointer.
				anchor.x = cvui.mouse().x
				anchor.y = cvui.mouse().y

			# Is any mouse button down (pressed)?
			if cvui.mouse(button, cvui.IS_DOWN):
				# Adjust roi dimensions according to mouse pointer
				width = cvui.mouse().x - anchor.x
				height = cvui.mouse().y - anchor.y

				roi.x = anchor.x + width if width < 0 else anchor.x
				roi.y = anchor.y + height if height < 0 else anchor.y
				roi.width = abs(width)
				roi.height = abs(height)

				# Show the roi coordinates and size
				cvui.printf(frame, roi.x + 5, roi.y + 5, 0.3, color, '(%d,%d)', roi.x, roi.y)
				cvui.printf(frame, cvui.mouse().x + 5, cvui.mouse().y + 5, 0.3, color, 'w:%d, h:%d', roi.width, roi.height)

			# Ensure ROI is within bounds
			lenaRows, lenaCols, lenaChannels = lena.shape
			roi.x = 0 if roi.x < 0 else roi.x
			roi.y = 0 if roi.y < 0 else roi.y
			roi.width = roi.width + lenaCols - (roi.x + roi.width) if roi.x + roi.width > lenaCols else roi.width
			roi.height = roi.height + lenaRows - (roi.y + roi.height) if roi.y + roi.height > lenaRows else roi.height

			# If the ROI is valid, render it in the frame and show in a window.
			if roi.area() > 0:
				cvui.rect(frame, roi.x, roi.y, roi.width, roi.height, color)
				cvui.printf(frame, roi.x + 5, roi.y - 10, 0.3, color, 'ROI %d', button)

				lenaRoi = lena[roi.y : roi.y + roi.height, roi.x : roi.x + roi.width]
				cv2.imshow('ROI button' + str(button), lenaRoi)

			button += 1

		# 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
Ejemplo n.º 30
0
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
Ejemplo n.º 31
0
def main():
	frame = np.zeros((300, 600, 3), np.uint8)

	# Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME).
	cvui.init(WINDOW_NAME);

	# Rectangle to be rendered according to mouse interactions.
	rectangle = cvui.Rect(0, 0, 0, 0)

	while (True):
		# Fill the frame with a nice color
		frame[:] = (49, 52, 49)

		# Show the coordinates of the mouse pointer on the screen
		cvui.text(frame, 10, 30, 'Click (any) mouse button and drag the pointer around to select an area.')
		cvui.printf(frame, 10, 50, 'Mouse pointer is at (%d,%d)', cvui.mouse().x, cvui.mouse().y)

		# The function "bool cvui.mouse(int query)" allows you to query the mouse for events.
		# E.g. cvui.mouse(cvui.DOWN)
		#
		# Available queries:
		#	- cvui.DOWN: any mouse button was pressed. cvui.mouse() returns true for a single frame only.
		#	- cvui.UP: any mouse button was released. cvui.mouse() returns true for a single frame only.
		#	- cvui.CLICK: any mouse button was clicked (went down then up, no matter the amount of frames in between). cvui.mouse() returns true for a single frame only.
		#	- cvui.IS_DOWN: any mouse button is currently pressed. cvui.mouse() returns true for as long as the button is down/pressed.

		# Did any mouse button go down?
		if cvui.mouse(cvui.DOWN):
			# Position the rectangle at the mouse pointer.
			rectangle.x = cvui.mouse().x
			rectangle.y = cvui.mouse().y

		# Is any mouse button down (pressed)?
		if cvui.mouse(cvui.IS_DOWN):
			# Adjust rectangle dimensions according to mouse pointer
			rectangle.width = cvui.mouse().x - rectangle.x
			rectangle.height = cvui.mouse().y - rectangle.y

			# Show the rectangle coordinates and size
			cvui.printf(frame, rectangle.x + 5, rectangle.y + 5, 0.3, 0xff0000, '(%d,%d)', rectangle.x, rectangle.y)
			cvui.printf(frame, cvui.mouse().x + 5, cvui.mouse().y + 5, 0.3, 0xff0000, 'w:%d, h:%d', rectangle.width, rectangle.height)

		# Did any mouse button go up?
		if cvui.mouse(cvui.UP):
			# Hide the rectangle
			rectangle.x = 0
			rectangle.y = 0
			rectangle.width = 0
			rectangle.height = 0

		# Was the mouse clicked (any button went down then up)?
		if cvui.mouse(cvui.CLICK):
			cvui.text(frame, 10, 70, 'Mouse was clicked!')

		# Render the rectangle
		cvui.rect(frame, rectangle.x, rectangle.y, rectangle.width, rectangle.height, 0xff0000)

		# This function must be called *AFTER* all UI components. It does
		# all the behind the scenes magic to handle mouse clicks, etc, then
		# shows the frame in a window like cv2.imshow() does.
		cvui.imshow(WINDOW_NAME, frame)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
Ejemplo n.º 32
0
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