Beispiel #1
0
    def __init__(self, *args, **kw):
        self.timer = 0
        self.t0 = 0
        self.t1 = 0
        self.startCopy = False

        # String
        self.folderName = ''
        self.folderPath = ''
        self.subjectName = ''
        self.tempName = ''

        self.names = []

        # Numbers
        self.numberFolder = [5]
        self.day = [1]
        self.month = [10]
        self.year = [20]
        self.group = [3]
        self.tp = [1]

        # Frames
        self.frame = np.zeros((Y_SCREEN, X_SCREEN, 3), np.uint8)
        cv.namedWindow(WINDOW_NAME)  #, cv.WINDOW_NORMAL)
        cvui.init(WINDOW_NAME)
def initializeAdjustHyperparametersWindows(WINDOW_NAME):
  cv2.destroyAllWindows()
  WINDOW_NAME_CTRL = "Adjust Parameters."
  cvui.init(WINDOW_NAME)
  cv2.moveWindow(WINDOW_NAME, 0, 0)
  cvui.init(WINDOW_NAME_CTRL)
  cv2.moveWindow(WINDOW_NAME_CTRL, 0, 300)
Beispiel #3
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
Beispiel #4
0
def anotate(img, out_path, wnd_height=800):
    img_height, img_width = img.shape[:2]
    wnd_width = int(wnd_height * img_width / img_height)

    frame = np.zeros((wnd_height + 200, wnd_width, 3), np.uint8)
    roi_size = [img_height // 10 * 5]
    roi_shiftx = [0]
    roi_shifty = [0]
    x1 = [0]
    x2 = [img_width // 2]
    y1 = [0]
    y2 = [img_height // 2]

    WINDOW_NAME = 'Roi Anotater'
    cvui.init(WINDOW_NAME)

    anchor = cvui.Point()

    while (True):

        y = cvui.mouse().y
        x = cvui.mouse().x

        if (x > 0 and x < wnd_width and y > 0 and y < wnd_height):
            if cvui.mouse(cvui.DOWN):
                anchor.y = y
                anchor.x = x

            if cvui.mouse(cvui.IS_DOWN):
                if x > anchor.x and y > anchor.y:
                    x1[0] = anchor.x * img_width // wnd_width
                    x2[0] = x * img_width // wnd_width
                    y1[0] = anchor.y * img_height // wnd_height
                    y2[0] = y * img_height // wnd_height

        frame[:] = (49, 52, 49)

        img_tmp = img.copy()
        img_tmp = cv2.rectangle(img_tmp, (x1[0], y1[0]), (x2[0], y2[0]),
                                (0, 0, 255), 1)
        cvui.image(frame, 0, 0, cv2.resize(img_tmp, (wnd_width, wnd_height)))
        param(frame, 50, wnd_height + 10, wnd_width - 400, x1, 0, x2[0], 'x1',
              1)
        param(frame, 50, wnd_height + 50, wnd_width - 400, x2, x1[0],
              img_width, 'x2', 1)
        param(frame, 50, wnd_height + 90, wnd_width - 400, y1, 0, y2[0], 'y1',
              1)
        param(frame, 50, wnd_height + 130, wnd_width - 400, y2, y1[0],
              img_height, 'y2', 1)

        cvui.update()
        cv2.imshow(WINDOW_NAME, frame)

        if cv2.waitKey(20) == 27:
            np.savez(out_path,
                     x1=x1[0] / img_width,
                     x2=x2[0] / img_width,
                     y1=y1[0] / img_height,
                     y2=y2[0] / img_height)
            break
Beispiel #5
0
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)
Beispiel #6
0
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():
    height = 220
    spacing = 10
    frame = np.zeros((height * 3, 1300, 3), np.uint8)

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

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

        rows, cols, channels = frame.shape

        # Render three groups of components.
        group(frame, 0, 0, cols, height - spacing)
        group(frame, 0, height, cols, height - spacing)
        group(frame, 0, height * 2, cols, height - spacing)

        # 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((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 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
Beispiel #10
0
def main():
	frame = np.zeros((300, 500, 3), np.uint8)

	c1 = Class1()
	c2 = Class2()

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

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

		c1.renderInfo(frame)
		c2.renderMessage(frame)

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

    c1 = Class1()
    c2 = Class2()

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

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

        c1.renderInfo(frame)
        c2.renderMessage(frame)

        # 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
Beispiel #12
0
def main():
	height = 220
	spacing = 10
	frame = np.zeros((height * 3, 1300, 3), np.uint8)

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

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

		rows, cols, channels = frame.shape

		# Render three groups of components.
		group(frame, 0, 0, cols, height - spacing)
		group(frame, 0, height, cols, height - spacing)
		group(frame, 0, height * 2, cols, height - spacing)

		# 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
Beispiel #13
0
def calculateBackgroundFreelySwim(self, controller, nbImagesForBackgroundCalculation):
  
  [pathToVideo, videoName, videoExt, configFile, argv] = getMainArguments(self)
  
  configFile["exitAfterBackgroundExtraction"] = 1
  configFile["debugExtractBack"]              = 1
  configFile["debugFindWells"]                = 1
  
  if int(nbImagesForBackgroundCalculation):
    configFile["nbImagesForBackgroundCalculation"] = int(nbImagesForBackgroundCalculation)
  
  WINDOW_NAME = "Please Wait"
  cvui.init(WINDOW_NAME)
  cv2.moveWindow(WINDOW_NAME, 0,0)
  
  try:
    mainZZ(pathToVideo, videoName, videoExt, configFile, argv)
  except ValueError:
    configFile["exitAfterBackgroundExtraction"] = 0
  
  cv2.destroyAllWindows()
  
  configFile["exitAfterBackgroundExtraction"]   = 0
  configFile["debugExtractBack"]                = 0
  configFile["debugFindWells"]                  = 0
  
  controller.show_frame("AdujstParamInsideAlgoFreelySwim")
Beispiel #14
0
    def __init__(self, auto_mode):
        self.pub_send_next_img = rospy.Publisher('/send_next_img',
                                                 Int16,
                                                 queue_size=1)

        self.terminate = 0
        self.pcd_list = []
        self.fitgeom_list = []
        self.vis = None
        self.plots = {}
        self.cvui_frame = None
        self.cvui_dbscan_eps = [DBSCAN_EPS]
        self.cvui_dbscan_minpoints = [DBSCAN_MINPOINTS]

        self.apply_fit = True
        self.show_fit_geometry = True
        self.show_goodbad_color = True

        if auto_mode:
            self.auto_mode = True
            self.show_2d = True
            self.show_3d = False
        else:
            self.auto_mode = False
            self.show_2d = True
            self.show_3d = True
            self.create_visualizer()
            self.cvui_frame = np.zeros((200, 500, 3), np.uint8)
            cvui.init(CVUI_WINDOW_NAME)
Beispiel #15
0
def main():
    window_name = 'cvui-double-knob-trackbar'
    cvui.init(window_name)

    trackbar_value1 = [25.0]
    trackbar_value2 = [75.0]

    while True:
        cvuiframe = np.zeros((140, 460, 3), np.uint8)
        cvuiframe[:] = (49, 52, 49)

        cvui.trackbar2(cvuiframe, 30, 30, 400, trackbar_value1,
                       trackbar_value2, 0., 100.)

        cvui.text(cvuiframe, 50, 100,
                  'value1 : ' + "{0:.1f}".format(trackbar_value1[0]))
        cvui.text(cvuiframe, 160, 100,
                  'value2 : ' + "{0:.1f}".format(trackbar_value2[0]))

        cvui.update()

        cv.imshow(window_name, cvuiframe)
        key = cv.waitKey(50)
        if key == 27:  # ESC
            break
Beispiel #16
0
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)
Beispiel #17
0
def wellOrganisation(self, controller, circular, rectangular, roi, other,
                     multipleROIs):
    if multipleROIs:
        controller.show_frame("NbRegionsOfInterest")
    else:
        if rectangular:
            self.shape = 'rectangular'
            self.configFile["wellsAreRectangles"] = 1
            controller.show_frame("CircularOrRectangularWells")
        else:
            if circular and self.organism != 'drosoorrodent':  # should remove the self.organism != 'drosoorrodent' at some point
                self.shape = 'circular'
                controller.show_frame("CircularOrRectangularWells")
            else:
                self.shape = 'other'
                if roi:
                    cap = cv2.VideoCapture(self.videoToCreateConfigFileFor)
                    cap.set(1, 10)
                    ret, frame = cap.read()
                    frame2 = frame.copy()
                    [
                        frame2, getRealValueCoefX, getRealValueCoefY,
                        horizontal, vertical
                    ] = resizeImageTooLarge(frame2, True, 0.85)

                    WINDOW_NAME = "Click on the top left of the region of interest"
                    cvui.init(WINDOW_NAME)
                    cv2.moveWindow(WINDOW_NAME, 0, 0)
                    cvui.imshow(WINDOW_NAME, frame2)
                    while not (cvui.mouse(cvui.CLICK)):
                        cursor = cvui.mouse()
                        if cv2.waitKey(20) == 27:
                            break
                    self.configFile["oneWellManuallyChosenTopLeft"] = [
                        int(getRealValueCoefX * cursor.x),
                        int(getRealValueCoefY * cursor.y)
                    ]
                    cv2.destroyAllWindows()

                    WINDOW_NAME = "Click on the bottom right of the region of interest"
                    cvui.init(WINDOW_NAME)
                    cv2.moveWindow(WINDOW_NAME, 0, 0)
                    cvui.imshow(WINDOW_NAME, frame2)
                    while not (cvui.mouse(cvui.CLICK)):
                        cursor = cvui.mouse()
                        if cv2.waitKey(20) == 27:
                            break
                    self.configFile["oneWellManuallyChosenBottomRight"] = [
                        int(getRealValueCoefX * cursor.x),
                        int(getRealValueCoefY * cursor.y)
                    ]
                    cv2.destroyAllWindows()

                    self.configFile["nbWells"] = 1
                    chooseBeginningAndEndOfVideo(self, controller)
                else:
                    self.configFile["noWellDetection"] = 1
                    self.configFile["nbWells"] = 1
                    chooseBeginningAndEndOfVideo(self, controller)
Beispiel #18
0
def main(camera_toml_path, enable_distortion_correction, scale_val = 0.65):
    camera_config = get_config(camera_toml_path)
    camera = Camera(camera_config)
    print(camera)

    scaling = partial(scaling_int, scale=scale_val)
    if camera_config.roi_size != 4:
        sys.exit('This script is only supported on "camera_config.roi_size == 4" ')
    if camera_config.auto_exposure != "roi":
        sys.exit('This script is only supported on "camera_config.auto_exposure == roi" ')

    image_width = camera.image_width
    image_height = camera.image_height

    roi = cvui.Rect(0, 0, 0, 0)
    WINDOW_NAME = "Capture"
    cvui.init(WINDOW_NAME)
    click_pos_x = image_width // 2
    click_pos_y = image_height // 2

    while True:
        key = cv2.waitKey(10)
        frame = np.zeros((scaling(image_height), scaling(image_width), 3), np.uint8)
        frame[:] = (49, 52, 49)

        status = camera.update()
        if status:
            # WARNING:If distortion correction is enabled, the rectangle on windows doesn't indicate actual RoI area for auto exposure.
            see3cam_rgb_image = camera.remap_image if enable_distortion_correction else camera.image
            scaled_width = scaling(image_width)
            scaled_height = scaling(image_height)
            see3cam_rgb_image_resized = cv2.resize(see3cam_rgb_image, (scaled_width, scaled_height))
            frame[:scaled_height, :scaled_width, :] = see3cam_rgb_image_resized

            window_w = image_width // 2
            window_h = image_height // 2
            if cvui.mouse(cvui.DOWN):
                click_pos_x = int(cvui.mouse().x / scale_val)
                click_pos_y = int(cvui.mouse().y / scale_val)

            camera.set_roi_properties(click_pos_x, click_pos_y, win_size=4)
            roi = cvui.Rect(scaling(click_pos_x - image_width // 4), scaling(click_pos_y - image_height // 4), scaling(window_w), scaling(window_h))

            # Ensure ROI is within bounds
            roi.x = 0 if roi.x < 0 else roi.x
            roi.y = 0 if roi.y < 0 else roi.y

            roi.width = roi.width + scaled_width - (roi.x + roi.width) if roi.x + roi.width > scaled_width else roi.width
            roi.height = roi.height + scaled_height - (roi.y + roi.height) if roi.y + roi.height > scaled_height else roi.height

            cvui.rect(frame, roi.x, roi.y, roi.width, roi.height, 0xFF0000)

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

        cvui.update()
        cvui.imshow(WINDOW_NAME, frame)
    cv2.destroyAllWindows()
Beispiel #19
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
Beispiel #20
0
def main():
    frame = np.zeros((720, 1280, 3), np.uint8)
    cvui.init('Speed of Light Measurement')

    curr_experiment = 0
    while (True):
        if curr_experiment == 0:
            curr_experiment = galileo(frame, curr_experiment)
        elif curr_experiment == 1:
            curr_experiment = fizeau(frame, curr_experiment)
Beispiel #21
0
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()
Beispiel #22
0
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 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 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)
Beispiel #25
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((600, 800, 3), np.uint8)
    value = [50]

    settings = EnhancedWindow(20, 80, 200, 120, 'Settings')
    info = EnhancedWindow(250, 80, 330, 60, 'Info')

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

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

        # Place some instructions on the screen regarding the
        # settings window
        cvui.text(
            frame, 20, 20,
            'The Settings and the Info windows below are movable and minimizable.'
        )
        cvui.text(frame, 20, 40,
                  'Click and drag any window\'s title bar to move it around.')

        # Render a movable and minimizable settings window using
        # the EnhancedWindow class.
        settings.begin(frame)
        if settings.isMinimized() == False:
            cvui.text('Adjust something')
            cvui.space(10)  # add 10px of space between UI components
            cvui.trackbar(settings.width() - 20, value, 5, 150)
        settings.end()

        # Render a movable and minimizable settings window using
        # the EnhancedWindow class.
        info.begin(frame)
        if info.isMinimized() == False:
            cvui.text('Moving and minimizable windows are awesome!')
        info.end()

        # Update all cvui internal stuff, e.g. handle mouse clicks, and show
        # everything on the screen.
        cvui.imshow(WINDOW_NAME, frame)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
Beispiel #27
0
def detectBouts(self, controller, wellNumber, firstFrameParamAdjust, adjustOnWholeVideo):
  
  [pathToVideo, videoName, videoExt, configFile, argv] = getMainArguments(self)
  
  [configFile, initialFirstFrameValue, initialLastFrameValue] = prepareConfigFileForParamsAdjustements(configFile, wellNumber, firstFrameParamAdjust, self.videoToCreateConfigFileFor, adjustOnWholeVideo)
  
  configFile["noBoutsDetection"] = 0
  configFile["trackTail"]                   = 0
  configFile["adjustDetectMovWithRawVideo"] = 1
  configFile["reloadWellPositions"]         = 1
  
  if "thresForDetectMovementWithRawVideo" in configFile:
    if configFile["thresForDetectMovementWithRawVideo"] == 0:
      configFile["thresForDetectMovementWithRawVideo"] = 1
  else:
    configFile["thresForDetectMovementWithRawVideo"] = 1
  
  try:
    WINDOW_NAME = "Please Wait"
    cvui.init(WINDOW_NAME)
    cv2.moveWindow(WINDOW_NAME, 0,0)
    r = cv2.waitKey(2)
    mainZZ(pathToVideo, videoName, videoExt, configFile, argv)
    cv2.destroyAllWindows()
  except ValueError:
    newhyperparameters = pickle.load(open('newhyperparameters', 'rb'))
    for index in newhyperparameters:
      configFile[index] = newhyperparameters[index]
  
  configFile["onlyTrackThisOneWell"]        = -1
  configFile["trackTail"]                   = 1
  configFile["adjustDetectMovWithRawVideo"] = 0
  configFile["reloadWellPositions"]         = 0
  
  if initialLastFrameValue == -1:
    if 'firstFrame' in configFile:
      del configFile['firstFrame']
    if 'lastFrame' in configFile:
      del configFile['lastFrame']
  else:
    configFile["firstFrame"]                  = initialFirstFrameValue
    configFile["lastFrame"]                   = initialLastFrameValue
  
  configFile["reloadBackground"] = 0
  
  self.configFile = configFile
def findTailTipByUserInput(frame, frameNumber, videoPath, hyperparameters):
    # global ix
    # ix = -1
    # img = np.zeros((512,512,3), np.uint8)
    # cv2.namedWindow('Click on tail tip')
    # cv2.setMouseCallback('Click on tail tip',getXYCoordinates)
    # print("ix:", ix)
    # while(ix == -1):
    # cv2.imshow('Click on tail tip',frame)
    # k = cv2.waitKey(20) & 0xFF
    # if k == 27:
    # break
    # elif k == ord('a'):
    # print("yeah:",ix,iy)
    # cv2.destroyAllWindows()
    # return [ix,iy]

    WINDOW_NAME = "Click on tail tip"
    cvui.init(WINDOW_NAME)
    cv2.moveWindow(WINDOW_NAME, 0, 0)

    font = cv2.FONT_HERSHEY_SIMPLEX
    frame = cv2.rectangle(frame, (0, 0), (250, 29), (255, 255, 255), -1)
    cv2.putText(frame, 'Click any key if the tail is', (1, 10), font, 0.5,
                (0, 150, 0), 1, cv2.LINE_AA)
    cv2.putText(frame, 'not straight on this image', (1, 22), font, 0.5,
                (0, 150, 0), 1, cv2.LINE_AA)

    cvui.imshow(WINDOW_NAME, frame)
    plus = 1
    while not (cvui.mouse(WINDOW_NAME, cvui.CLICK)):
        cursor = cvui.mouse(WINDOW_NAME)
        if cv2.waitKey(20) != -1:
            [frame, thresh1] = headEmbededFrame(videoPath, frameNumber + plus,
                                                hyperparameters)
            frame = cv2.rectangle(frame, (0, 0), (250, 29), (255, 255, 255),
                                  -1)
            cv2.putText(frame, 'Click any key if the tail is', (1, 10), font,
                        0.5, (0, 150, 0), 1, cv2.LINE_AA)
            cv2.putText(frame, 'not straight on this image', (1, 22), font,
                        0.5, (0, 150, 0), 1, cv2.LINE_AA)
            cvui.imshow(WINDOW_NAME, frame)
            plus = plus + 1
    # cv2.destroyAllWindows()
    cv2.destroyWindow(WINDOW_NAME)
    return [cursor.x, cursor.y]
Beispiel #29
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
Beispiel #30
0
    def run(self):
        WINDOW_NAME = "viewer"
        self._start()
        cvui.init(WINDOW_NAME)

        frame = np.zeros((960, 1280, 3), np.uint8)
        while True:
            frame[:] = (49, 52, 49)
            cvui.text(frame, 10, 10, 'See3CAM', 0.5)
            k = cv2.waitKey(10)
            if k == 27 or k == ord('q'):
                self._stopped = True
                break
            elif k == ord('s'):
                self._save_image()
            self._cvui_gui(frame)
            cvui.imshow(WINDOW_NAME, frame)
        cv2.destroyAllWindows()
Beispiel #31
0
def main():
	fruits = cv2.imread('fruits.jpg', cv2.IMREAD_COLOR)
	frame = np.zeros(fruits.shape, np.uint8)
	low_threshold = [50]
	high_threshold = [150]
	use_canny = [False]

	# Create a settings window using the EnhancedWindow class.
	settings = EnhancedWindow(10, 50, 270, 180, 'Settings')

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

	while (True):
		# Should we apply Canny edge?
		if use_canny[0]:
			# Yes, we should apply it.
			frame = cv2.cvtColor(fruits, cv2.COLOR_BGR2GRAY)
			frame = cv2.Canny(frame, low_threshold[0], high_threshold[0], 3)
			frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
		else: 
			# No, so just copy the original image to the displaying frame.
			frame[:] = fruits[:]

		# Render the settings window and its content, if it is not minimized.
		settings.begin(frame)
		if settings.isMinimized() == False:
			cvui.checkbox('Use Canny Edge', use_canny)
			cvui.trackbar(settings.width() - 20, low_threshold, 5, 150)
			cvui.trackbar(settings.width() - 20, high_threshold, 80, 300)
			cvui.space(20); # add 20px of empty space
			cvui.text('Drag and minimize this settings window', 0.4, 0xff0000)
		settings.end()

		# This function must be called *AFTER* all UI components. It does
		# all the behind the scenes magic to handle mouse clicks, etc.
		cvui.update()

		# Show everything on the screen
		cv2.imshow(WINDOW_NAME, frame)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
def main():
    lena = cv2.imread('lena.jpg', cv2.IMREAD_COLOR)
    frame = np.zeros(lena.shape, np.uint8)
    low_threshold = [50]
    high_threshold = [150]
    use_canny = [False]

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

    while (True):
        # Should we apply Canny edge?
        if use_canny[0]:
            # Yes, we should apply it.
            frame = cv2.cvtColor(lena, cv2.COLOR_BGR2GRAY)
            frame = cv2.Canny(frame, low_threshold[0], high_threshold[0], 3)
            frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
        else:
            # No, so just copy the original image to the displaying frame.
            frame[:] = lena[:]

        # Render the settings window to house the checkbox
        # and the trackbars below.
        cvui.window(frame, 10, 50, 180, 180, 'Settings')

        # Checkbox to enable/disable the use of Canny edge
        cvui.checkbox(frame, 15, 80, 'Use Canny Edge', use_canny)

        # Two trackbars to control the low and high threshold values
        # for the Canny edge algorithm.
        cvui.trackbar(frame, 15, 110, 165, low_threshold, 5, 150)
        cvui.trackbar(frame, 15, 180, 165, high_threshold, 80, 300)

        # This function must be called *AFTER* all UI components. It does
        # all the behind the scenes magic to handle mouse clicks, etc.
        cvui.update()

        # Show everything on the screen
        cv2.imshow(WINDOW_NAME, frame)

        # Check if ESC key was pressed
        if cv2.waitKey(20) == 27:
            break
Beispiel #33
0
def main():
	lena = cv2.imread('lena.jpg', cv2.IMREAD_COLOR)
	frame = np.zeros(lena.shape, np.uint8)
	low_threshold = [50]
	high_threshold = [150]
	use_canny = [False]

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

	while (True):
		# Should we apply Canny edge?
		if use_canny[0]:
			# Yes, we should apply it.
			frame = cv2.cvtColor(lena, cv2.COLOR_BGR2GRAY)
			frame = cv2.Canny(frame, low_threshold[0], high_threshold[0], 3)
			frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
		else: 
			# No, so just copy the original image to the displaying frame.
			frame[:] = lena[:]

		# Render the settings window to house the checkbox
		# and the trackbars below.
		cvui.window(frame, 10, 50, 180, 180, 'Settings')
		
		# Checkbox to enable/disable the use of Canny edge
		cvui.checkbox(frame, 15, 80, 'Use Canny Edge', use_canny)
		
		# Two trackbars to control the low and high threshold values
		# for the Canny edge algorithm.
		cvui.trackbar(frame, 15, 110, 165, low_threshold, 5, 150)
		cvui.trackbar(frame, 15, 180, 165, high_threshold, 80, 300)

		# This function must be called *AFTER* all UI components. It does
		# all the behind the scenes magic to handle mouse clicks, etc.
		cvui.update()

		# Show everything on the screen
		cv2.imshow(WINDOW_NAME, frame)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
Beispiel #34
0
def main():
	frame = np.zeros((600, 800, 3), np.uint8)

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

	# Load some data points from a file
	points = load('sparkline.csv')
	
	# Create less populated sets
	few_points = []
	no_points = []
	
	for i in range(0, 30):
		few_points.append(random.uniform(0., 300.0))
	
	while (True):
		# Fill the frame with a nice color
		frame[:] = (49, 52, 49)

		# Add 3 sparklines that are displaying the same data, but with
		# different width/height/colors.
		cvui.sparkline(frame, points, 0, 0, 800, 200);
		cvui.sparkline(frame, points, 0, 200, 800, 100, 0xff0000);
		cvui.sparkline(frame, points, 0, 300, 400, 100, 0x0000ff);
		
		# Add a sparkline with few points
		cvui.sparkline(frame, few_points, 10, 400, 790, 80, 0xff00ff);

		# Add a sparkline that has no data. In that case, cvui will
		# render it with a visual warning.
		cvui.sparkline(frame, no_points, 10, 500, 750, 100, 0x0000ff);

		# 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
Beispiel #35
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
def launchStuff():
    if globalVariables["mac"] != 1 and globalVariables["lin"] != 1:
        WINDOW_NAME = "Tracking in Progress"
        cvui.init(WINDOW_NAME)
        cv2.moveWindow(WINDOW_NAME, 0, 0)
        f = open("trace.txt", "r")
        if f.mode == 'r':
            contents = f.read()
        f.close()
        while not ("ZebraZoom Analysis finished for" in contents):
            f = open("trace.txt", "r")
            if f.mode == 'r':
                contents = f.read()
            f.close()
            frameCtrl = np.full((400, 500), 100).astype('uint8')
            contentList = contents.split("\n")
            for idx, txt in enumerate(contentList):
                cvui.text(frameCtrl, 4, 15 + idx * 20, txt)
            cvui.imshow(WINDOW_NAME, frameCtrl)
            cv2.waitKey(20)
        cv2.destroyAllWindows()
Beispiel #37
0
def findRectangularWellsArea(frame, videoPath, hyperparameters):
  
  frame2 = frame.copy()
  
  root = tk.Tk()
  horizontal = root.winfo_screenwidth()
  vertical   = root.winfo_screenheight()
  getRealValueCoefX = 1
  getRealValueCoefY = 1
  if len(frame2[0]) > horizontal or len(frame2) > vertical:
    getRealValueCoefX = len(frame2[0]) / int(horizontal*0.8)
    getRealValueCoefY = len(frame2) / int(vertical*0.8)
    frame2 = cv2.resize(frame2, (int(horizontal*0.8), int(vertical*0.8)))
  root.destroy()
  
  WINDOW_NAME = "Click on the top left of one of the wells"
  cvui.init(WINDOW_NAME)
  cv2.moveWindow(WINDOW_NAME, 0,0)
  cvui.imshow(WINDOW_NAME, frame2)
  while not(cvui.mouse(cvui.CLICK)):
    cursor = cvui.mouse()
    if cv2.waitKey(20) == 27:
      break
  topLeft = [cursor.x, cursor.y]
  cv2.destroyAllWindows()
  
  WINDOW_NAME = "Click on the bottom right of the same well"
  cvui.init(WINDOW_NAME)
  cv2.moveWindow(WINDOW_NAME, 0,0)
  cvui.imshow(WINDOW_NAME, frame2)
  while not(cvui.mouse(cvui.CLICK)):
    cursor = cvui.mouse()
    if cv2.waitKey(20) == 27:
      break
  bottomRight = [cursor.x, cursor.y]
  cv2.destroyAllWindows()  
  
  rectangularWellsArea = int(abs((topLeft[0] - bottomRight[0]) * getRealValueCoefX) * abs((topLeft[1] - bottomRight[1]) * getRealValueCoefY))
  
  return rectangularWellsArea
Beispiel #38
0
def main():
	# Init cvui. If you don't tell otherwise, cvui will create the required OpenCV
	# windows based on the list of names you provided.
	windows = [WINDOW1_NAME, WINDOW2_NAME, WINDOW3_NAME, WINDOW4_NAME]
	cvui.init(windows, 4)

	while (True):
		# The functions below will update a window and show them using cv2.imshow().
		# In that case, you must call the pair cvui.context(NAME)/cvui.update(NAME)
		# to render components and update the window.
		window(WINDOW1_NAME)
		window(WINDOW2_NAME)
		window(WINDOW3_NAME)
		
		# The function below will do the same as the funcitons above, however it will
		# use cvui.imshow() (cvui's version of cv2.imshow()), which will automatically
		# call cvui.update() for us.
		compact(WINDOW4_NAME)

		# Check if ESC key was pressed
		if cv2.waitKey(20) == 27:
			break
Beispiel #39
0
def rectangularWells(self, controller, nbwells, nbRowsOfWells, nbWellsPerRows):

    [pathToVideo, videoName, videoExt, configFile,
     argv] = getMainArguments(self)

    configFile["adjustRectangularWellsDetect"] = 1

    try:
        WINDOW_NAME = "Please Wait"
        cvui.init(WINDOW_NAME)
        cv2.moveWindow(WINDOW_NAME, 0, 0)
        r = cv2.waitKey(2)
        mainZZ(pathToVideo, videoName, videoExt, configFile, argv)
        cv2.destroyAllWindows()
    except ValueError:
        newhyperparameters = pickle.load(open('newhyperparameters', 'rb'))
        for index in newhyperparameters:
            configFile[index] = newhyperparameters[index]

    configFile["adjustRectangularWellsDetect"] = 0

    self.configFile = configFile

    chooseBeginningAndEndOfVideo(self, controller)
Beispiel #40
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
Beispiel #41
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
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
Beispiel #43
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
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
Beispiel #45
0
def main():
	intValue = [30]
	ucharValue = [30]
	charValue = [30]
	floatValue = [12.]
	doubleValue = [45.]
	doubleValue2 = [15.]
	doubleValue3 = [10.3]
	frame = np.zeros((770, 350, 3), np.uint8)

	# The width of all trackbars used in this example.
	width = 300

	# The x position of all trackbars used in this example
	x = 10

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

		# The trackbar component uses templates to guess the type of its arguments.
		# You have to be very explicit about the type of the value, the min and
		# the max params. For instance, if they are double, use 100.0 instead of 100.
		cvui.text(frame, x, 10, 'double, step 1.0 (default)')
		cvui.trackbar(frame, x, 40, width, doubleValue, 0., 100.)

		cvui.text(frame, x, 120, 'float, step 1.0 (default)')
		cvui.trackbar(frame, x, 150, width, floatValue, 10., 15.)

		# You can specify segments and custom labels. Segments are visual marks in
		# the trackbar scale. Internally the value for the trackbar is stored as
		# long double, so the custom labels must always format long double numbers, no
		# matter the type of the numbers being used for the trackbar. E.g. %.2Lf
		cvui.text(frame, x, 230, 'double, 4 segments, custom label %.2Lf')
		cvui.trackbar(frame, x, 260, width, doubleValue2, 0., 20., 4, '%.2Lf')

		# Again: you have to be very explicit about the value, the min and the max params.
		# Below is a uchar trackbar. Observe the uchar cast for the min, the max and 
		# the step parameters.
		cvui.text(frame, x, 340, 'uchar, custom label %.0Lf')
		cvui.trackbar(frame, x, 370, width, ucharValue, 0, 255, 0, '%.0Lf')

		# You can change the behavior of any tracker by using the options parameter.
		# Options are defined as a bitfield, so you can combine them.
		# E.g.
		#	TRACKBAR_DISCRETE							# value changes are discrete
		#  TRACKBAR_DISCRETE | TRACKBAR_HIDE_LABELS	# discrete changes and no labels
		cvui.text(frame, x, 450, 'double, step 0.1, option TRACKBAR_DISCRETE')
		cvui.trackbar(frame, x, 480, width, doubleValue3, 10., 10.5, 1, '%.1Lf', cvui.TRACKBAR_DISCRETE, 0.1)

		# More customizations using options.
		options = cvui.TRACKBAR_DISCRETE | cvui.TRACKBAR_HIDE_SEGMENT_LABELS
		cvui.text(frame, x, 560, 'int, 3 segments, DISCRETE | HIDE_SEGMENT_LABELS')
		cvui.trackbar(frame, x, 590, width, intValue, 10, 50, 3, '%.0Lf', options, 2)

		# Trackbar using char type.
		cvui.text(frame, x, 670, 'char, 2 segments, custom label %.0Lf')
		cvui.trackbar(frame, x, 700, width, charValue, -128, 127, 2, '%.0Lf')

		# 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
Beispiel #46
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
Beispiel #47
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)
Beispiel #48
0
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)
Beispiel #49
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
Beispiel #50
0
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