예제 #1
0
 def mergeFrame(self):
     if self.father == None:
         print(self.FrameName)
         raise ValueError('%s : FatherNotFoundError' % (self.FrameName))
         return
     cvui.image(self.father.background, self.relx, self.rely,
                self.background)
예제 #2
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
예제 #3
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
예제 #4
0
def teach_step(posed='Images/yoga.jpg', Check=False):
    Estimator = TfPoseEstimator
    frame1 = np.zeros((768, 1024, 3), np.uint8)

    WINDOW1_NAME = 'Dance Dance Pose'
    cv2.namedWindow(WINDOW1_NAME)
    cvui.init(WINDOW1_NAME)

    inferred = infer(posed)
    original = cv2.imread(posed)

    #time.sleep(5)
    if original.shape[0] != 480 or original.shape[1] != 640:
        original = cv2.resize(original, (368, 368))

    if Check:
        cv2.imwrite('check.jpg', inferred)

    inferred = inferred - original
    #inferred=cv2.copyMakeBorder(inferred[:,int(np.nonzero(inferred)[1][0]/2):],0,0,0,int(np.nonzero(inferred)[1][0]/2),cv2.BORDER_REPLICATE)

    timeout = time.time() + 10
    capture = cv2.VideoCapture(0)
    counter = [time.time()]
    x = 1

    while True:
        cvui.context(WINDOW1_NAME)

        ret, frame = capture.read()

        gray = frame
        if gray.shape[0] != 4810 or gray.shape[1] != 640:
            gray = cv2.resize(gray, (368, 368))

        dst = cv2.addWeighted(inferred, 0.5, gray, 0.5, 0)
        frame1[:] = (49, 52, 49)
        cvui.beginRow(frame1, 10, 20, -1, -1, 30)

        cvui.image(dst)
        cvui.image(original)

        cvui.endRow()

        cvui.beginRow(frame1, 10, 400, -1, -1, 30)
        cvui.counter(frame1, 100, 410, counter, 0.1, '%.1f')
        counter = [timeout - time.time() for x in counter]
        cvui.text(frame1, 10, 410, "Tick tick")
        cvui.endRow()

        cvui.update(WINDOW1_NAME)
        cv2.imshow(WINDOW1_NAME, frame1)

        if cv2.waitKey(1) & 0xFF == ord('q') or time.time() > timeout:

            filename = 'captures/capture' + \
                      str(int(x)) + ".png"
            x = x + 1
            cv2.imwrite(filename, frame)
            break

    inferred_capture = infer(filename)
    original_inferred = cv2.imread(filename)

    if original_inferred.shape[0] != 4380 or original_inferred.shape[1] != 640:
        inferred_capture = cv2.resize(inferred_capture, (368, 368))
        original_inferred = cv2.resize(original_inferred, (368, 368))

    while True:
        final = cv2.addWeighted(inferred, 0.5, inferred_capture, 0.5, 0)
        cv2.imshow('final', final)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    diff_inferred = inferred_capture - original_inferred
    bw_inferred = cv2.cvtColor(diff_inferred, cv2.COLOR_BGR2GRAY)
    bw_inferred[bw_inferred >= 1] = 1
    bw_inferred[bw_inferred < 1] = 0

    bw_orig_inferred = cv2.cvtColor(inferred, cv2.COLOR_BGR2GRAY)
    bw_orig_inferred[bw_orig_inferred >= 1] = 1
    bw_orig_inferred[bw_orig_inferred < 1] = 0
    total = bw_orig_inferred == bw_inferred

    print('')
    print('')
    print('Overlap:' + str((1 - np.sum(total) / np.size(total)) * 10))
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
예제 #6
0
 def camera_frame_attach(self):
     cvui.image(self.mainframe, 0, 0, self.cam_frame)
예제 #7
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
예제 #8
0
def fizeau(frame, expr):
    curr_expr = expr
    experiments = [[False] for i in range(2)]

    fizeau_default = cv2.imread(resource_path("images/fizeau_default.png"), 3)
    fizeau_not_default = cv2.imread(resource_path("images/fizeau_not_default.png"), 3)
    fizeau_line = cv2.imread(resource_path("images/fizeau_line.png"), 3)
    fizeau_distance = cv2.imread(resource_path("images/fizeau_distance.png"), 3)
    fizeau_dot = cv2.imread(resource_path("images/fizeau_dot.png"), cv2.IMREAD_UNCHANGED)
    fizeau_dot_grey = cv2.imread(resource_path("images/fizeau_dot_grey.png"), cv2.IMREAD_UNCHANGED)
    fizeau_sprocket = cv2.imread(resource_path("images/fizeau_sprocket.png"), cv2.IMREAD_UNCHANGED)
    fizeau_metre = cv2.imread(resource_path("images/fizeau_metre.png"), cv2.IMREAD_UNCHANGED)
    fizeau_blank = cv2.imread(resource_path("images/fizeau_blank.png"), cv2.IMREAD_UNCHANGED)
    fizeau_darkstripes = cv2.imread(resource_path("images/fizeau_darkstripes.png"), cv2.IMREAD_UNCHANGED)
    fizeau_lightstripes = cv2.imread(resource_path("images/fizeau_lightstripes.png"), cv2.IMREAD_UNCHANGED)

    wheel_sprites_pos = get_120(fizeau_default, fizeau_sprocket)
    wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey)
    wheel_sprites_pos.rotate(30)
    wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey)
    wheel_sprites_pos.rotate(30)
    wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey)
    wheel_sprites_pos.rotate(30)
    wheel_sprites_pos = put_dots_pos(wheel_sprites_pos, fizeau_dot, fizeau_dot_grey)

    wheel_sprites_neg = get_120(fizeau_not_default, fizeau_sprocket)
    wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey)
    wheel_sprites_neg.rotate(30)
    wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey)
    wheel_sprites_neg.rotate(30)
    wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey)
    wheel_sprites_neg.rotate(30)
    wheel_sprites_neg = put_dots_neg(wheel_sprites_neg, fizeau_dot, fizeau_dot_grey)

    animation = 0
    frequency_tr = [6.0]

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

        #Animation window
        coord = get_coord(frequency_tr[0])
        if coord == 23:
            cvui.image(frame, 0, 0, wheel_sprites_neg[animation])
            cvui.text(frame, 33, 200, "Calculation of the speed of light", 0.5)
            cvui.text(frame, 34, 220, "distance ... s = {:,} m" .format(8633), 0.5)
            cvui.text(frame, 34, 240, "number of teeth in sprocket ... N = 720", 0.5)
            cvui.text(frame, 34, 260, "c=4*s*N*f=4*{:,}*{:,}*{:,}={:,} km/s"
                .format(8633, 7200, round(frequency_tr[0], 2), round((4 * 8633 * 7200 * frequency_tr[0])/1000, 2)), 0.5)
        else:
            cvui.image(frame, 0, 0, wheel_sprites_pos[animation])
            cvui.text(frame, 33, 200, "Calculation of the speed of light", 0.5)
            cvui.text(frame, 34, 220, "distance ... s = {:,} m" .format(8633), 0.5)
            cvui.text(frame, 34, 240, "number of teeth in sprocket ... N = 720", 0.5)
            cvui.text(frame, 34, 260, "c=4*s*N*f ... proper frequency wasn't found", 0.5)
        cvui.image(frame, 872, 499, fizeau_line)

        cvui.image(frame, 874, 687, fizeau_distance)
        animation += 1
        if animation == 120:
            animation = 0

        cvui.text(frame,   58, 660, "Light source")
        cvui.text(frame,  473, 660, "Semipermeable mirror")
        cvui.text(frame,  840, 660, "Sprocket")
        cvui.text(frame,  994, 673, "Distance")
        cvui.text(frame, 1145, 660, "Mirror")

        cvui.text(frame, 892, 277, "-> Light behind sprocket")
        img = get_graph(fizeau_metre, fizeau_blank, fizeau_darkstripes, fizeau_lightstripes, coord=0, crop_light=False)
        cvui.image(frame, 896, 298, img)
        cvui.text(frame, 892, 377, "<- Reflected light before sprocket")
        img = get_graph(fizeau_metre, fizeau_blank, fizeau_darkstripes, fizeau_lightstripes, coord=coord, crop_light=False)
        cvui.image(frame, 896, 397, img)
        cvui.text(frame, 434, 100, "Reflected light behind sprocket")
        img = get_graph(fizeau_metre, fizeau_blank, fizeau_darkstripes, fizeau_lightstripes, coord=coord, crop_light=True)
        cvui.image(frame, 434, 120, img)

        #Experiment settings window
        cvui.window(frame, 1033.5, 2, 243.5, 104, 'Experiment settings')
        
        cvui.trackbar(frame,  1030, 39, 249, frequency_tr, 0.01, 12.0577)
        cvui.rect(frame, 1035, 39, 240, 12, 0x313131, 0x313131)
        cvui.rect(frame, 1035, 74, 240, 25, 0x313131, 0x313131)
        cvui.text(frame, 1041, 32, "Frequency")
        cvui.text(frame, 1042, 82, "{:,} Hz".format(round(frequency_tr[0], 2)))

        #Experiments window
        cvui.window(frame, 2, 2, 155, 75, 'Experiments')

        cvui.checkbox(frame, 10, 30, "1638 - Galileo",   experiments[0])
        cvui.checkbox(frame, 10, 53, "1849 - Fizeau",    experiments[1])

        curr_expr = exp_type(curr_expr, experiments)
        experiments = [[False] for i in range(2)]
        experiments[curr_expr] = [True]

        cvui.update()

        cv2.imshow('Speed of Light Measurement', frame)

        if cv2.waitKey(20) == 27:
            return -1

        if curr_expr != expr:
            return curr_expr
예제 #9
0
def demo(source=None, height=240):
    """
    method creates window, that shows, what is happening with image,
    when is analyzed by algorithm
    """
    if not source:
        cap = cv2.VideoCapture(0)
    else:
        cap = cv2.VideoCapture(source)

    fgbg = cv2.createBackgroundSubtractorMOG2()
    ret, image = cap.read()

    image = imutils.resize(image, height=height)

    if image.shape[0] > image.shape[1]:
        width = image.shape[0]
    else:
        width = image.shape[1]

    frame = np.zeros(((height + 27) * 2 - 2, (width + 7) * 4 - 5, 3), np.uint8)
    cvui.init('Motion Detection')

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

        ret, image = cap.read()

        if type(image).__module__ != np.__name__:
            break

        map_ = fgbg.apply(image)
        image, op_1, op_2, op_3, op_4, op_5, op_6, op_7, cnt = find_bbox(
            image, map_, verbose=False)

        #To BGR
        op_1 = cv2.cvtColor(op_1, cv2.COLOR_GRAY2BGR)
        op_2 = cv2.cvtColor(op_2, cv2.COLOR_GRAY2BGR)
        op_3 = cv2.cvtColor(op_3, cv2.COLOR_GRAY2BGR)
        op_4 = cv2.cvtColor(op_4, cv2.COLOR_GRAY2BGR)
        op_5 = cv2.cvtColor(op_5, cv2.COLOR_GRAY2BGR)
        op_6 = cv2.cvtColor(op_6, cv2.COLOR_GRAY2BGR)
        op_7 = cv2.cvtColor(op_7, cv2.COLOR_GRAY2BGR)

        #Resize
        image = imutils.resize(image, height=height)
        op_1 = imutils.resize(op_1, height=height)
        op_2 = imutils.resize(op_2, height=height)
        op_3 = imutils.resize(op_3, height=height)
        op_4 = imutils.resize(op_4, height=height)
        op_5 = imutils.resize(op_5, height=height)
        op_6 = imutils.resize(op_6, height=height)
        op_7 = imutils.resize(op_7, height=height)

        #Window
        cvui.window(frame, 2, 2, width + 3, 263, 'Motion Detection')
        cvui.image(frame, 4, 24, image)

        cvui.window(frame, (width + 3) + 4, 2, width + 3, 263,
                    'operation_1 - MOG2')
        cvui.image(frame, (width + 3) + 4 + 2, 24, op_1)

        cvui.window(frame, ((width + 3) + 2) * 2 + 2, 2, width + 3, 263,
                    'operation_2 - medianBlur')
        cvui.image(frame, ((width + 3) + 4) * 2, 24, op_2)

        cvui.window(frame, ((width + 3) + 2) * 3 + 2, 2, width + 3, 263,
                    'operation_3 - threshold')
        cvui.image(frame, ((width + 3) + 4) * 3 - 2, 24, op_3)

        cvui.window(frame, 2, 265 + 2, width + 3, 263,
                    'operation_4 - medianBlur')
        cvui.image(frame, 4, 265 + 24, op_4)

        cvui.window(frame, (width + 3) + 4, 265 + 2, width + 3, 263,
                    'operation_5 - distanceTransform, threshold')
        cvui.image(frame, (width + 3) + 4 + 2, 265 + 24, op_5)

        cvui.window(frame, ((width + 3) + 2) * 2 + 2, 265 + 2, width + 3, 263,
                    'operation_6 - medianBlur')
        cvui.image(frame, ((width + 3) + 4) * 2, 265 + 24, op_6)

        cvui.window(frame, ((width + 3) + 2) * 3 + 2, 265 + 2, width + 3, 263,
                    'operation_7 - morphologyEx')
        cvui.image(frame, ((width + 3) + 4) * 3 - 2, 265 + 24, op_7)

        cvui.update()
        cv2.imshow('Motion Detection', frame)

        if cv2.waitKey(20) == 27:
            return -1
예제 #10
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)
예제 #11
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
                fail_detact = 0
                # pyautogui.press('1')

            # print('aaaa', start, fish_button, fail_detact)
            if cvui.button(frame, 400, 350, "Stop"):
                start = 0
                fish_button = 1
            # if cvui.button(frame, 300, 80, "&Quit"):
            #     break
            # # cvui.window(frame, 150, 10, 130, 90, str(num))
            #

            printScreen = cv2.resize(printScreen, None, fx=0.7, fy=0.7)
            printScreen = cv2.cvtColor(printScreen, cv2.COLOR_RGB2BGR)
            printScreen = cv2.cvtColor(printScreen, cv2.COLOR_BGR2RGB)
            cvui.image(frame, 20, 20, printScreen)

        if cvui.button(frame, 400, 400, "Select window"):
            if run_button == 0:
                run_button = 1

            if run_button == 1:
                run_button = 0
                titlee = program_list[0]

        if run_button2 == 0:
            cvui.text(frame, 10, 305, "Capture Area")
            cvui.text(frame, 10, 355, "Min Max")

            cvui.text(frame, 100, 285, "Starting")
            cvui.counter(frame, 100, 300, Starting, 10)
예제 #13
0
def galileo(frame, expr):
    curr_expr = expr
    experiments = [[False] for i in range(2)]

    restart = True
    distance_tr = [1.1]

    galileo_default = cv2.imread(resource_path("images/galileo_default.png"),
                                 3)
    galileo_yellow_dot = cv2.imread(
        resource_path("images/galileo_yellow_dot.png"), 3)
    galileo_fire = cv2.imread(resource_path("images/galileo_fire.png"), 3)

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

        if restart:
            animation = 0
            animate = False
            galileo_coord_bottom = 385
            galileo_coord_top = 985
            first_graph_f = False
            second_graph_f = False
            first_graph = False
            second_graph = False
            first_delay = 0
            second_delay = 0
            delay = 0
            speed_of_light = 299792
            half = False
            first_after_half = 0
            first_after_end = 0
            restart = False
            static_distance = False

        if not first_graph_f:
            first_graph, lag = get_graph()
            first_delay = lag
            first_graph_f = True
        if not second_graph_f:
            second_graph, lag = get_graph()
            second_delay = lag
            second_graph_f = True

        #Animation window
        cvui.image(frame, 0, 0, galileo_default)

        if animate:
            galileo_coord_bottom = 368
            galileo_coord_top = 968
            cvui.image(frame, 314, 393, galileo_fire)
            if animation < 21:
                for _ in range(animation + 1):
                    cvui.image(frame, galileo_coord_bottom, 400,
                               galileo_yellow_dot)
                    galileo_coord_bottom = galileo_coord_bottom + 30
            else:
                for _ in range(21):
                    cvui.image(frame, galileo_coord_bottom, 400,
                               galileo_yellow_dot)
                    galileo_coord_bottom = galileo_coord_bottom + 30

            if animation >= 21 and animation < 42:
                cvui.image(frame, 960, 200, first_graph)
                cvui.text(frame, 1045, 186, "Reaction delay", 0.4)
                cvui.text(frame, 1079, 278, str(int(first_delay)) + "ms", 0.4)

                cvui.image(frame, 1036, 390, galileo_fire)
                for _ in range(animation + 1 - 21):
                    cvui.image(frame, galileo_coord_top, 375,
                               galileo_yellow_dot)
                    galileo_coord_top = galileo_coord_top - 30
            elif animation == 42:
                if first_after_end != 0:
                    if (timer() - first_after_end) > (second_delay / 1000):
                        first_after_end = 0
                        cvui.image(frame, 131, 205, second_graph)
                        cvui.text(frame, 216, 191, "Reaction delay", 0.4)
                        cvui.text(frame, 248, 285,
                                  str(int(second_delay)) + "ms", 0.4)
                        delay = static_distance / speed_of_light + (
                            first_delay / 1000) + (second_delay / 1000)
                else:
                    cvui.image(frame, 131, 205, second_graph)
                    cvui.text(frame, 216, 191, "Reaction delay", 0.4)
                    cvui.text(frame, 248, 285,
                              str(int(second_delay)) + "ms", 0.4)

                cvui.image(frame, 1036, 390, galileo_fire)
                for _ in range(21):
                    cvui.image(frame, galileo_coord_top, 375,
                               galileo_yellow_dot)
                    galileo_coord_top = galileo_coord_top - 30

            if animation < 42:
                act_time = timer() - start_time
                whole_distance = static_distance
                if half:
                    traveled_distance = (act_time -
                                         (first_delay / 1000)) * speed_of_light
                else:
                    traveled_distance = act_time * speed_of_light
                piece_of_distance = whole_distance / 21
                traveled_parts = traveled_distance / piece_of_distance
                if first_after_half != 0:
                    if (timer() - first_after_half) > (first_delay / 1000):
                        first_after_half = 0
                else:
                    if not half:
                        if traveled_parts >= 21:
                            animation = 20
                            half = True
                            first_after_half = timer()
                        else:
                            animation = int(traveled_parts)
                    else:
                        if traveled_parts >= 42:
                            animation = 42
                            first_after_end = timer()
                        else:
                            animation = int(traveled_parts)
            else:
                cvui.image(frame, 960, 200, first_graph)
                cvui.text(frame, 1045, 186, "Reaction delay", 0.4)
                cvui.text(frame, 1079, 278, str(int(first_delay)) + "ms", 0.4)
                if delay != 0:
                    cvui.text(frame, 640, 320, "Total time", 0.5)
                    cvui.text(frame, 660, 343, str(round(delay, 2)) + "s", 0.5)
                    cvui.text(frame, 345, 60,
                              "Calculation of the speed of light", 0.5)
                    cvui.text(
                        frame, 345, 80,
                        "distance between mountains ... s = {:,} km".format(
                            static_distance / 2), 0.5)
                    cvui.text(frame, 345, 100,
                              "average human reaction time ... d = 250 ms",
                              0.5)
                    cvui.text(
                        frame, 345, 120,
                        "c=(2*s)/(t-2*d)=(2*{:,})/({}-2*0.25)={:,} km/s".
                        format(
                            static_distance / 2, str(round(delay, 2)),
                            round(
                                static_distance / (round(delay, 2) - 2 * 0.25),
                                2)), 0.5)

        if delay == 0:
            cvui.text(frame, 345, 60, "Calculation of the speed of light", 0.5)
            if static_distance:
                cvui.text(
                    frame, 345, 80,
                    "distance between mountains ... s = {:,} km".format(
                        static_distance / 2), 0.5)
            else:
                cvui.text(
                    frame, 345, 80,
                    "distance between mountains ... s = {:,} km".format(
                        round((distance_tr[0])**8, 0)), 0.5)
            cvui.text(frame, 345, 100,
                      "average human reaction time ... d = 250 ms", 0.5)
            cvui.text(frame, 345, 120,
                      "c=(2*s)/(t-2*d) ... total time wasn't measured", 0.5)

        #Experiment settings window
        cvui.window(frame, 1033.5, 2, 243.5, 133, 'Experiment settings')

        cvui.trackbar(frame, 1030, 39, 249, distance_tr, 1.1, 10.0)
        cvui.rect(frame, 1035, 39, 240, 12, 0x313131, 0x313131)
        cvui.rect(frame, 1035, 74, 240, 25, 0x313131, 0x313131)
        cvui.text(frame, 1041, 32, "Distance")
        cvui.text(frame, 1042, 82,
                  "{:,} km".format(round((distance_tr[0])**8, 0)))
        if cvui.button(frame, 1040, 102, "Measure time"):
            if not animate:
                static_distance = round((distance_tr[0])**8, 0) * 2
            animate = True
            start_time = timer()
        if cvui.button(frame, 1161, 102, "Clear"):
            restart = True

        #Experiments window
        cvui.window(frame, 2, 2, 155, 75, 'Experiments')

        cvui.checkbox(frame, 10, 30, "1638 - Galileo", experiments[0])
        cvui.checkbox(frame, 10, 53, "1849 - Fizeau", experiments[1])

        curr_expr = exp_type(curr_expr, experiments)
        experiments = [[False] for i in range(2)]
        experiments[curr_expr] = [True]

        cvui.update()

        cv2.imshow('Speed of Light Measurement', frame)

        if cv2.waitKey(20) == 27:
            return -1

        if curr_expr != expr:
            return curr_expr
예제 #14
0
            new_points = []
            new_epoints = []

            #print(objects)
            # redraw points and label using objects
            for savedPoints in savedPointsCol:
                #print(len(savedPoints[1]) - 1)
                for i in range(len(savedPoints[1]) - 1):
                    cv2.line(v_frame, (savedPoints[1][i][0] * video_size_x,
                                       savedPoints[1][i][1] * video_size_y),
                             (savedPoints[1][i + 1][0] * video_size_x,
                              savedPoints[1][i + 1][1] * video_size_y),
                             (0, 255, 0), draw_line_width)

            #save data into config file
            with open('config.txt', 'w') as outfile:
                json.dump(data, outfile)

    cvui.image(frame, 10, 10, v_frame)
    cvui.update()

    cv2.imshow(WINDOW_NAME, frame)

    key = cv2.waitKey(20)

    rawCapture.truncate(0)
    if key == ord("q"):
        break
    elif key != -1:
        new_stringLabel.append(chr(key))
예제 #15
0
            algorithm = 1
            algorithm_0 = [False]
            algorithm_1 = [True]
            state = 0
            state_count = len(steps_1)
        elif algorithm == 1 and algorithm_0[0] and algorithm_1[0]:
            algorithm = 0
            algorithm_0 = [True]
            algorithm_1 = [False]
            state = 0
            state_count = len(steps_0)

        if (cvui.button(frame, 555, 40, "Previous")):
            # render previous image
            if state > 0:
                state -= 1
        if (cvui.button(frame, 650, 40, "Next")):
            # render next image
            if state < (state_count - 1):
                state += 1

        if algorithm == 0:
            cvui.image(frame, 310, 100, steps_0[state])
        elif algorithm == 1:
            cvui.image(frame, 310, 100, steps_1[state])

        cvui.imshow(WINDOW_NAME, frame)

        if cv2.waitKey(20) == 27:
            break
예제 #16
0
파일: cutout.py 프로젝트: briantccj/opencv
import cvui
import os

path = os.path.abspath(os.path.dirname(__file__))
src = cv2.imread(path + "/image/1.jpg")
hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)

cvui.init("opencv")
frame = np.zeros((800, 800, 3), np.uint8)
floatValue_min = [20.]
floatValue_max = [30.]
h_min = [20.]
h_max = [140.]
while True:
    frame[:] = (49, 52, 49)

    cvui.trackbar(frame, 10, 60, 300, h_min, 0, 179)
    cvui.trackbar(frame, 320, 60, 300, h_max, 0, 179)

    lower_blue = np.array([h_min[0], 90, 90])
    upper_blue = np.array([h_max[0], 255, 255])

    mask = cv2.inRange(hsv, lower_blue, upper_blue)
    mask = ~mask
    dest = cv2.bitwise_and(src, src, mask=mask)
    cvui.image(frame, 20, 120, dest)

    cvui.update()
    cv2.imshow("opencv", frame)
    cv2.waitKey(20)
예제 #17
0
파일: row-column.py 프로젝트: Dovyski/cvui
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