コード例 #1
0
def main():
    import sys
    # global variables
    global calibration_mode
    calibration_mode = False
    global target_pixel
    global target_lower, target_upper
    target_lower = (15, 153, 154)
    target_upper = (45, 293, 274)
    global image_hsv
    global gripper_start
    global timer, location_pub
    global location, location_pub, start_pub
    location = None
    global SERVICE_NAME
    SERVICE_NAME = "x7_colour_arm/pick_request"

    # initialize some basic openCV GUI elements
    # creates main window
    cv2.namedWindow("Transformed Camera Feed")
    # gui property buttons for turning on calibration mode and starting x7 grab
    cv2.createButton("Calibration Mode", toggle_colour_recalibration, None,
                     cv2.QT_CHECKBOX)
    cv2.createButton("Start", start_x7_gripper, None)

    # rospy publisher elements
    rospy.init_node("ball_camera")
    #location_pub = rospy.Publisher("/ball_2D_pose", geometry_msgs.msg.Pose, queue_size=1)
    #timer = rospy.Timer(rospy.Duration(1), update_ROS_location)

    # start detection loop. placed in a function for.. idk. future use
    ball_detection_driver_loop()
コード例 #2
0
    def select_images_formedian(self, feature_idex):
        # choose iamges to culculate the median feature.
        cv2.namedWindow('image selecting')
        cv2.createButton('yes', self.input_yes)
        cv2.createButton('no', self.pass_image)
        while self.i_select < 20:
            img_path = self.dataset_path + str(int(
                feature_idex[self.i_select]))
            try:
                img = cv2.imread(img_path)
                img = cv2.resize(img, (224, 224),
                                 interpolation=cv2.INTER_CUBIC)
                cv2.imshow('image selecting', img)
            except:
                array = np.ndarray((120, 500, 3), np.uint8)
                array[:, :, 0] = 0
                array[:, :, 1] = 0
                array[:, :, 2] = 100
                font = cv2.FONT_HERSHEY_SIMPLEX
                cv2.putText(array, "image wrong!", (10, 50), font, 1,
                            (255, 255, 255), 1)
                cv2.imshow('image selecting', array)

            k = cv2.waitKey(1) & 0xFF
            if k == ord('q'):
                break

        cv2.destroyAllWindows()
コード例 #3
0
ファイル: color.py プロジェクト: maiermic/robot-cameraman
 def open(self):
     cv2.namedWindow('Mask', cv2.WINDOW_NORMAL)
     self._create_trackbar('Min Contour Size (width + height)',
                           self.engine.minimum_contour_size,
                           self._update_minimum_contour_radius)
     self._setup_hsv_trackbars()
     create_attribute_checkbox('Single Object Detection', self.engine,
                               'is_single_object_detection')
     if (self._configuration_file is not None
             and self._configuration_file.exists()):
         cv2.createButton('Store Configuration', self._update_configuration)
         cv2.createButton('Reset Configuration', self._reset_configuration)
コード例 #4
0
 def __init__(self, window_height, cell_height):
     self.window_name = None
     self.simulation_height = window_height
     self.cell_height = cell_height
     self.simulation_parameters = None
     self.simulation = None
     self.previous_state = None
     self.paused: bool = True
     self.color_buffer = np.zeros(
         (self.simulation_height, self.simulation_height, 3))
     self.is_lit = False
     self.window_id_unique = "Forest Fire"
     cv2.namedWindow(self.window_id_unique, cv2.WINDOW_AUTOSIZE)
     cv2.createButton("Reset", self.setup, None, cv2.QT_PUSH_BUTTON, 1)
コード例 #5
0
ファイル: ui.py プロジェクト: maiermic/robot-cameraman
def create_attribute_checkbox(button_name: str, obj, attribute_name):
    """
    Create a checkbox and bind its value to the attribute of an object.
    If the checkbox is toggled, the attribute is updated.
    However, the checkbox is not updated, if the attribute is changed otherwise.

    :param button_name:
    :param obj:
    :param attribute_name:
    :return:
    """
    def on_change(value, _user_data):
        is_enabled = value == 1
        setattr(obj, attribute_name, is_enabled)
        state = 'enabled' if is_enabled else 'disabled'
        logger.debug(f'{button_name}: {state}')

    cv2.createButton(button_name, on_change, None, cv2.QT_CHECKBOX,
                     1 if getattr(obj, attribute_name) else 0)
コード例 #6
0
ファイル: grabcut.py プロジェクト: BalajSaleem/GrabCut-OpenCV
    def run(self):
        self.load()
        self.reset()

        # Input and output windows
        cv.namedWindow('output')
        cv.namedWindow('input')
        cv.createButton("Mark Background", self.mark_bg, None,
                        cv.QT_PUSH_BUTTON, 1)
        cv.createButton("Mark Foreground", self.mark_fg, None,
                        cv.QT_PUSH_BUTTON, 1)
        cv.createButton("Segment", self.segment, None, cv.QT_PUSH_BUTTON, 1)
        cv.createButton("Reset", self.reset, None, cv.QT_PUSH_BUTTON, 1)
        cv.createButton("Save", self.save, None, cv.QT_PUSH_BUTTON, 1)
        cv.createTrackbar('brush thickness', 'input', 3, 10,
                          self.change_thickness)
        cv.setMouseCallback('input', self.onmouse)
        cv.moveWindow('input', self.input.shape[1] + 10, 90)

        print('Draw a rectangle around the object using middle mouse button')
        print('Press ctrl+P for other image segmentation options')

        while True:
            cv.imshow('output', self.output)
            cv.imshow('input', self.input)
            k = cv.waitKey(1)

            # Key bindings
            if k == 27 or k == ord('q'): break  # exit
            elif k == ord('0'): self.value = self.DRAW_BG
            elif k == ord('1'): self.value = self.DRAW_FG
            elif k == ord('2'): self.value = self.DRAW_PR_BG
            elif k == ord('3'): self.value = self.DRAW_PR_FG
            elif k == ord('s'): self.save()
            elif k == ord('r'): self.reset()
            elif k == ord('n'): self.segment()
            #else: continue

            self.alpha = np.where((self.mask == 1) + (self.mask == 3), 255,
                                  0).astype('uint8')
            img = cv.bitwise_and(self.copy, self.copy, mask=self.alpha)
            self.output = self.crop_to_alpha(img)
コード例 #7
0
    def start_window_rendering(self):

        # Create a black image, a window
        self.h = int(960 / 2.0)
        self.w = int(2400 / 2.0)
        self.img = np.zeros((self.h, self.w, 3), np.uint8)
        font = cv2.FONT_HERSHEY_SIMPLEX
        position = (0, self.h - 25)
        fontScale = 1.0
        fontColor = (128, 128, 128)
        lineType = 1

        self.window_name = 'InteractiveWindow'
        cv2.namedWindow(self.window_name)

        # create trackbars for color change
        x = lambda x: None
        cv2.createTrackbar('strong_coherence_threshold*10 (0-7)',
                           self.window_name, 59, 70, x)
        cv2.createTrackbar('weak_coherence_threshold*10 (0-4)',
                           self.window_name, 30, 40, x)
        cv2.createTrackbar('merge', self.window_name, 44, 60, x)
        cv2.createTrackbar('event_length*10', self.window_name, 40, 60, x)
        cv2.createButton("Generate", self.onChangeSend, None,
                         cv2.QT_PUSH_BUTTON, 1)

        #self.onChangeSend(x=None,y=None) # toggle once at start
        text = " Set up the desired parameters, then press Ctrl+P and click 'Generate'."
        cv2.putText(self.img, text, position, font, fontScale, fontColor,
                    lineType)

        while (1):
            # also keep another inf. loop

            cv2.imshow(self.window_name, self.img)
            k = cv2.waitKey(1) & 0xFF
            if k == 27:
                break

        cv2.destroyAllWindows()
コード例 #8
0
    def run(self):
        # Create the control panel.
        cv2.namedWindow('Control Panel')
        cv2.createTrackbar('threshold1', 'Control Panel', 0, 255,
                           self.slider_callback)  # change the maximum to whatever you like
        cv2.createTrackbar('threshold2', 'Control Panel', 0, 255,
                           self.slider_callback)  # change the maximum to whatever you like
        cv2.createTrackbar('apertureSize', 'Control Panel', 0, 2, self.slider_callback)
        cv2.createTrackbar('L1/L2', 'Control Panel', 0, 1, self.slider_callback)
        cv2.createButton('Save Points', self.save_points)

        while True:
            # get threshold value from trackbar
            th1 = cv2.getTrackbarPos('threshold1', 'Control Panel')
            th2 = cv2.getTrackbarPos('threshold2', 'Control Panel')

            # aperture size can only be 3,5, or 7
            apSize = cv2.getTrackbarPos('apertureSize', 'Control Panel') * 2 + 3

            # true or false for the norm flag
            norm_flag = cv2.getTrackbarPos('L1/L2', 'Control Panel') == 1

            # print out the values
            print('')
            print('threshold1: {}'.format(th1))
            print('threshold2: {}'.format(th2))
            print('apertureSize: {}'.format(apSize))
            print('L2gradient: {}'.format(norm_flag))

            img_resized = cv2.resize(self.img, (int(self.img.shape[1] / 2), int(self.img.shape[0] / 2)))
            self.edges = cv2.Canny(img_resized, th1, th2, apertureSize=apSize, L2gradient=norm_flag)
            cv2.imshow('Image', self.edges)

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        cv2.destroyAllWindows()
コード例 #9
0
ファイル: opencv.py プロジェクト: PierreA-Drac/TabletAR
    pass


if __name__ == '__main__':
    import sys

    wname = 'TAR Project'

    fname = 'opencv.png'
    im = cv.imread(cv.samples.findFile(fname))
    if im is None:
        print('Failed to load image file:', fname)
        sys.exit(1)

    cv.imshow(wname, im)
    cv.displayOverlay(
        wname, 'Cliquez sur un bouton pour interagir avec l\'application.', 0)
    cv.displayStatusBar(wname,
                        'On peut placer des informations et trackbars ici.', 0)
    cv.createTrackbar("Trackbar exemple", wname, 128, 255, callback_trackbar)
    cv.createTrackbar("Trackbar exemple", "", 128, 255, callback_trackbar)
    cv.createButton("Bouton", callback_button, wname, 0)

    while True:
        k = cv.waitKey(0)
        if k == 27:
            print('ESC')
            cv.destroyAllWindows()
            break
    cv.destroyAllWindows()
コード例 #10
0
# For Buffer Zone config
cv.createTrackbar("Buffer Zone 1", "Game Panel", 0, 3,
                  lambda x: bufferzone(x, 0))
cv.createTrackbar("Buffer Zone 2", "Game Panel", 0, 3,
                  lambda x: bufferzone(x, 1))
cv.createTrackbar("Buffer Zone 3", "Game Panel", 0, 3,
                  lambda x: bufferzone(x, 2))
cv.setTrackbarPos("Buffer Zone 1", "Game Panel", 3)
cv.setTrackbarPos("Buffer Zone 2", "Game Panel", 3)
cv.setTrackbarPos("Buffer Zone 3", "Game Panel", 3)
cv.setTrackbarPos("Self Blood", "Game Panel", Blackboard.myrobot.blood)
cv.setTrackbarPos("Self Bullet", "Game Panel", Blackboard.myrobot.bullet)
cv.setTrackbarPos("Target Blood", "Game Panel", Blackboard.enemy.blood)
cv.setTrackbarPos("Target Bullet", "Game Panel", Blackboard.enemy.bullet)

cv.createButton('Start', lambda x, y: StrPublisher(x, "START", game_startop))
cv.createButton('Stop', lambda x, y: StrPublisher(x, "STOP", game_startop))
cv.setMouseCallback(
    'Game Panel', lambda a1, a2, a3, a4, a5: draw_target(
        a1, a2, a3, a4, a5, target_pose, map_display, map_display2))
map = cv.imread('icra2020.pgm')
map_display = map.copy()
map_display2 = map.copy()
blackboard = Blackboard()
referee = RefereeSystem()
'''
def Main(data):
    
    cv.imshow('Game Panel',map_display2)
    referee.Update()
    draw_self(map_display2)
コード例 #11
0
    # smaller_grid[height//2][width//2 + 1] = 1

    # smaller_grid[height//2][width//2 + -1] = 1
    # smaller_grid[height//2][width//2 + 0] = 1
    # smaller_grid[height//2][width//2 + 1] = 1
    # smaller_grid[height//2 - 1][width//2 + -1] = 1
    # smaller_grid[height//2 -2 ][width//2 + 0] = 1

    cv2.namedWindow("Game of Life")

    if not full_screen_flag:
        cv2.moveWindow("Game of Life",
                       screen.winfo_screenwidth() // 2 - width * res // 2,
                       screen.winfo_screenheight() // 2 - height * res // 2)

    cv2.createButton("Freeze", freeze, None, cv2.QT_PUSH_BUTTON, 1)
    cv2.setMouseCallback('Game of Life', mouse_click)

    while 1:
        show_grid = cv2.resize(smaller_grid, (width * res, height * res),
                               interpolation=cv2.INTER_NEAREST)
        cv2.imshow('Game of Life', show_grid)

        if not freeze_flag:
            smaller_grid = update_grid(smaller_grid)
        else:
            if mouseY and mouseX:
                smaller_grid[mouseY // res][mouseX // res] = 1
                mouseX = None
                mouseY = None
コード例 #12
0
feature_matrix_pca, feature_mean = pca(feature_matrix)

distances_to_mean_withpca = []
distances_to_mean_withoutpca = []
distances_to_mean_withteaching = []
distances_to_mean_withtsne = []

# choose pictures for mean feature calculation
if 1:
    selected_images = []
    selected_images_pca = []
    selected_images_tsne = []
    selected_idexes = []
    i_select = 0
    cv2.namedWindow('teaching')
    cv2.createButton('yes', input_yes)
    cv2.createButton('no', pass_image)
    while i_select < 20:
        img_path = "/home/ipb38admin/yuanli/Create_Dataset/cat_tennis/" + str(
            int(feature_idex[i_select]))
        try:
            img = cv2.imread(img_path)
            img = cv2.resize(img, (224, 224), interpolation=cv2.INTER_CUBIC)
            cv2.imshow('teaching', img)
        except:
            array = np.ndarray((120, 500, 3), np.uint8)
            array[:, :, 0] = 0
            array[:, :, 1] = 0
            array[:, :, 2] = 100
            font = cv2.FONT_HERSHEY_SIMPLEX
            cv2.putText(array, "image wrong!", (10, 50), font, 1,
コード例 #13
0
    return x + w // 2, y + h // 2


def clear(_, __):
    global myPoints
    myPoints = []


capture = cv.VideoCapture(0)
capture.set(cv.CAP_PROP_FRAME_WIDTH, 480)
capture.set(cv.CAP_PROP_FRAME_HEIGHT, 320)
capture.set(cv.CAP_PROP_BRIGHTNESS, 1000)

cv.namedWindow('contours')
cv.createButton('clear', clear, myPoints, cv.QT_NEW_BUTTONBAR)

while True:
    ret, frame = capture.read()
    img = cv.resize(cv.flip(frame, 1), (400, 320))
    imgContour = img.copy()
    findColor(img, myColors)

    if len(myPoints) != 0:
        for point in myPoints:
            cv.circle(imgContour, point, 10, (0, 0, 255), thickness=cv.FILLED)

    # cv.imshow('Video', img)
    cv.imshow('contours', imgContour)

    if cv.waitKey(1) & 0xFF == ord('d'):
コード例 #14
0
ファイル: quantify.py プロジェクト: lemonad/cv-hockey-shot
    def setup(self, video_filename, data_filename):
        """Setup settings, videodata and testdata."""
        print("Reading videodata from {0}".format(data_filename))
        try:
            stream = open(data_filename, "r")
            data = yaml.load(stream)
        except FileNotFoundError:
            print("Not found. Using defaults.")
            data = []

        if 'app_settings' in data:
            self.settings = AppSettings(data['app_settings'])

        if 'video_data' in data:
            self.videodata = VideoData(data['video_data'])

        if 'test_data' in data:
            self.testdata = TestData(data['test_data'])

        print("done")
        self.dirty_flag = False

        print("Getting metadata from movie file.")
        rotation = subprocess.check_output([
            "ffprobe", "-loglevel", "error", "-select_streams", "v:0",
            "-show_entries", "stream_tags=rotate", "-of", "default=nw=1:nk=1",
            video_filename
        ])
        if rotation:
            rotation90 = VideoData.rotation_to_rotation90(int(rotation))
            if (self.videodata.rotation90
                    and rotation90 != self.videodata.rotation90):
                print("Rotation from video (%d) does not match stored "
                      "rotation (%d)." %
                      (rotation90, self.videodata.rotation90))
                return False
            self.videodata.set_rotation90(rotation90)
        print("done")

        self.canvas_detector = CanvasDetector(self.stencil_filename)

        # Setup output window.
        cv2.namedWindow(
            "image",
            cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_EXPANDED | cv2.WINDOW_KEEPRATIO)
        cv2.moveWindow('image', 0, 0)
        cv2.resizeWindow('image', 1440, 1024)
        cv2.createTrackbar("track1", "image", 0, 255, self.trackbar_changed)
        cv2.displayOverlay("image",
                           "Press 1-5 and click to set target position", 4000)

        cv2.createButton("Crop (top-left)", self.upper_left_crop_button, 0,
                         cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("Crop (bottom-right)", self.bottom_right_crop_button,
                         0, cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("Accept goal corners",
                         self.accept_goal_corners_pressed, 0,
                         cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("Canny ", self.toggle_canny_button, 0,
                         cv2.QT_CHECKBOX, False)
        cv2.createButton("Homography ", self.toggle_homography_button, 0,
                         cv2.QT_CHECKBOX, False)

        cv2.createButton("⚫️ Mark hit", self.mark_hit_pressed, 0,
                         cv2.QT_PUSH_BUTTON | cv2.QT_NEW_BUTTONBAR, False)
        cv2.createButton("🚫 Miss", self.toggle_miss_pressed, 0,
                         cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("➰ Bounce", self.toggle_bounce_pressed, 0,
                         cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("←", self.move_hit_button, 0, cv2.QT_PUSH_BUTTON,
                         False)
        cv2.createButton("↓", self.move_hit_button, 2, cv2.QT_PUSH_BUTTON,
                         False)
        cv2.createButton("↑", self.move_hit_button, 1, cv2.QT_PUSH_BUTTON,
                         False)
        cv2.createButton("→", self.move_hit_button, 3, cv2.QT_PUSH_BUTTON,
                         False)

        cv2.createButton("Hit example", self.is_keyframe_button,
                         KeyFrame.HIT_EXAMPLE,
                         cv2.QT_PUSH_BUTTON | cv2.QT_NEW_BUTTONBAR, False)
        cv2.createButton("Not hit example", self.is_keyframe_button,
                         KeyFrame.NOT_HIT_EXAMPLE, cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("Ambiguous example", self.is_keyframe_button,
                         KeyFrame.AMBIGUOUS_EXAMPLE, cv2.QT_PUSH_BUTTON, False)
        cv2.createButton("No example", self.is_keyframe_button,
                         KeyFrame.NOT_KEYFRAME, cv2.QT_PUSH_BUTTON, False)
        return True
コード例 #15
0
    right_vert_final_x = int(left_pad + 2 * tic_tac_dimension + 2 * bar_width)
    right_vert_final_y = int(top_pad + bar_length)
    '''start and end coordinates for the top horizontal bar'''
    top_hor_init_x = int(left_pad)
    top_hor_init_y = int(top_pad + tic_tac_dimension)
    top_hor_final_x = int(left_pad + bar_length)
    top_hor_final_y = int(top_pad + tic_tac_dimension + bar_width)
    '''start and endcoordinates for the bottom horizontal bar'''
    bottom_hor_init_x = int(left_pad)
    bottom_hor_init_y = int(top_pad + 2 * tic_tac_dimension + bar_width)
    bottom_hor_final_x = int(left_pad + bar_length)
    bottom_hor_final_y = int(top_pad + 2 * tic_tac_dimension + 2 * bar_width)
    ''' creating the display image array'''

    cv.namedWindow('image')
    cv.createButton("Exit Game", switch, 'image', cv.QT_PUSH_BUTTON,
                    1)  # when this button is hit it breaks the loop
    cv.createButton("Reset Board", reset_the_board, 'image', cv.QT_PUSH_BUTTON,
                    0)  # resets the board
    cv.setMouseCallback('image', interact)
    '''drawing the bars of the the tic-tac-toe gameBoard'''
    # drawing the left vertical bar
    cv.rectangle(img, (left_vert_init_x, left_vert_init_y),
                 (left_vert_final_x, left_vert_final_y), bar_color, -1)
    # drawing the right vertical bar
    cv.rectangle(img, (right_vert_init_x, right_vert_init_y),
                 (right_vert_final_x, right_vert_final_y), bar_color, -1)
    # drawing the top horizontal bar
    cv.rectangle(img, (top_hor_init_x, top_hor_init_y),
                 (top_hor_final_x, top_hor_final_y), bar_color, -1)
    # drawing the bottom horizontal bar
    cv.rectangle(img, (bottom_hor_init_x, bottom_hor_init_y),
コード例 #16
0
ファイル: camera.py プロジェクト: monash-wsrn/ebug2014-ros
cv2.createTrackbar(u'Exposure', u'Blob Camera', 157, 1024,
                   lambda x: nrf.set_camera_exposure(x))

# Analogue gain (best to keep at 0 and adjust exposure)
cv2.createTrackbar(u'Analogue gain', u'Blob Camera', 0, 255,
                   lambda x: nrf.set_camera_gain(x))

# White balance: gain adjustment for blue channel
cv2.createTrackbar(u'Blue gain', u'Blob Camera', 115, 255,
                   lambda x: nrf.set_camera_blue_gain(x))

# White balance: gain adjustment for red channel
cv2.createTrackbar(u'Red gain', u'Blob Camera', 121, 255,
                   lambda x: nrf.set_camera_red_gain(x))

cv2.createButton('Button', lambda x: nrf.set_camera_red_gain(x))

nrf.camera_write_reg(0x13, 0)  # disable AEC, AGC, and AWB

ts = 0
frame_no = 0
frame_blobs = []
colours = [(0, 0, 255), (0, 255, 0), (255, 0, 0), (255, 0, 255)]
frame_times = list(izip(xrange(10), xrange(10)))
while True:
    try:
        k = cv2.waitKey(1)
        if unichr(k & 0xff) == u'q': break
        prev_ts = ts
        ts, blobs = nrf.get_blobs()
        if ts != prev_ts:
コード例 #17
0
ファイル: main.py プロジェクト: legokor/GepiLatasDemo
def populate_toolbars():
    for name, args in BUTTONS.items():
        cv2.createButton(name, **args)
    for name, args in TRACKBARS.items():
        cv2.createTrackbar(name, WINDOW_NAME, *args)
コード例 #18
0
def f():
    #empty function
    cv2.createButton('Button', f)
コード例 #19
0

def button(state, param):
    print(state, param)


win = cv.namedWindow('window', flags=cv.WINDOW_GUI_EXPANDED)
img = np.zeros((100, 500, 3), np.uint8)
cv.imshow('window', img)
cv.createTrackbar('x', 'window', 50, 100, trackbar)
cv.setTrackbarMin('x', 'window', -100)

# These trackbars are created on the properties window
cv.createTrackbar('y', '', 50, 100, trackbar)
cv.createTrackbar('z', '', 50, 100, trackbar)
cv.createButton('Button', button, 0)
cv.createButton('Button1', button, 0)
cv.createButton('Button2', button, 0, cv.QT_RADIOBOX)
cv.createButton('Button3', button, 0, cv.QT_CHECKBOX)
cv.setWindowTitle('window', 'New title')

# retval	=	cv.selectROI(img)

while True:
    k = cv.waitKey(10)
    if k == ord('k'):
        break
    elif k == ord('p'):
        print('hello')

cv.destroyAllWindows()
コード例 #20
0
# cv.imshow('ret', ret)

# for x in pts:
#     cv.circle(img,tuple(x), 5, (0,255,0), thickness=cv.FILLED)


def clear(_, __):
    print('clear')
    global pts, img, imgCopy
    pts = []
    cv.destroyWindow('ret')
    img = cv.resize(cv.imread('imgs/book3.jpg'), (320, 480))


cv.namedWindow('img')
cv.createButton('clear', clear, None, cv.QT_NEW_BUTTONBAR)
cv.setMouseCallback('img', mouseEvent)

while True:

    if len(pts) == 4:
        width, height = (208, 350)
        # width, height = pts[1][0] - pts[0][0], pts[2][1] - pts[0][1]
        pts = [[29, 85], [237, 84], [24, 434], [243, 445]]
        pts2 = [[0, 0], [width, 0], [0, height], [width, height]]
        matrix = cv.getPerspectiveTransform(np.float32(pts), np.float32(pts2))
        ret = cv.warpPerspective(imgCopy, matrix, (width, height))
        cv.imshow('ret', ret)

    for x in pts:
        cv.circle(img, tuple(x), 5, (0, 255, 0), thickness=cv.FILLED)
コード例 #21
0
# Name your window
root_wind = 'main';
cv.namedWindow(root_wind)

def on_hello(*args):
	print('hello', 		args)
def on_bye(*args):
	print('bye', 		args)
def on_check(*args):
	print('checkbox', 	args)
def on_radio(*args):
	print('radio',		args)

# simple button
cv.createButton('hello', 	on_hello)
# userData
cv.createButton('bye1', 	on_bye, [1, 'string'])
cv.createButton('bye2', 	on_bye, [[2,3], 'qwerty'])
cv.createButton('bye3', 	on_bye, [2,3,4,5,6])

# checkbox
cv.createButton('checkox1', on_check, [40, 50], 	1, 0)
cv.createButton('checkox2', on_check, [40, 50], 	1, 1)
# radio
cv.createButton('r1', 		on_radio, 1, 			2, 0)
cv.createButton('r2', 		on_radio, [2], 			2, 1)
cv.createButton('r3', 		on_radio, [3, 'hello'], 2, 0)


# Create a black image
コード例 #22
0

# Create a black image, a window
img = np.zeros((300, 512, 3), np.uint8)
cv2.namedWindow('image')

# create trackbars for color change
cv2.createTrackbar('R', 'image', 0, 255, nothing)
cv2.createTrackbar('G', 'image', 0, 255, nothing)
cv2.createTrackbar('B', 'image', 0, 255, nothing)

# create switch for ON/OFF functionality
switch = '0 : OFF \n1 : ON'
cv2.createTrackbar(switch, 'image', 0, 1, nothing)

cv2.createButton(switch, callbackButton, userData=0, buttonType=cv2.QT_RADIOBOX, initialButtonState=False)


while 1:
    cv2.imshow('image', img)
    k = cv2.waitKey(1) & 0xFF
    if k == ord('q'):
        break

    # get current positions of four trackbars
    r = cv2.getTrackbarPos('R', 'image')
    g = cv2.getTrackbarPos('G', 'image')
    b = cv2.getTrackbarPos('B', 'image')
    s = cv2.getTrackbarPos(switch, 'image')

    if s == 0:
コード例 #23
0
ファイル: laplgauss.py プロジェクト: ecalasans/opencv_estudos
    if state == 1:
        if status_mix == 1:
            im_result = cv.filter2D(im_result, None, laplacian)
        else:
            pass
        canvas[:, 0:320, :] = eiffel
        canvas[:, 321:641, :] = im_result

        cv.imshow('Canvas', canvas)
    else:
        canvas[:, 0:320, :] = eiffel
        canvas[:, 321:641, :] = eiffel

        cv.imshow('Canvas', canvas)

cv.createButton("Normal", imagemNormal, 0, cv.QT_RADIOBOX, 1)
cv.createButton("Media", aplicaMedia, 1, cv.QT_RADIOBOX, 0)
cv.createButton("Gaussiano", aplicaGaussiano, 2, cv.QT_RADIOBOX, 0)
cv.createButton("Horizontal", aplicaHorizontal, 3, cv.QT_RADIOBOX, 0)
cv.createButton("Vertical", aplicaVertical, 4, cv.QT_RADIOBOX, 0)
cv.createButton("Laplaciano", aplicaLaplaciano, 5, cv.QT_RADIOBOX, 0)
cv.createButton("Boost", aplicaBoost, 6, cv.QT_RADIOBOX, 0)
cv.createButton("Mixar com o Laplaciano", mixLaplaciano, 1,
                cv.QT_CHECKBOX, 0)

canvas[:, 0:320, :] = eiffel
canvas[:, 321:641, :] = eiffel

cv.imshow('Canvas', canvas)
cv.waitKey(0)
cv.destroyAllWindows()