Python cv2 模块,WINDOW_AUTOSIZE 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用cv2.WINDOW_AUTOSIZE

项目:MultiObjectTracker    作者:alokwhitewolf    | 项目源码 | 文件源码
def run(im):
    im_disp = im.copy()
    window_name = "Draw line here."
    cv2.namedWindow(window_name,cv2.WINDOW_AUTOSIZE)
    cv2.moveWindow(window_name, 910, 0)

    print " Drag across the screen to set lines.\n Do it twice"
    print " After drawing the lines press 'r' to resume\n"

    l1 = np.empty((2, 2), np.uint32)
    l2 = np.empty((2, 2), np.uint32)

    list = [l1,l2]

    mouse_down = False
    def callback(event, x, y, flags, param):
        global trigger, mouse_down

        if trigger<2:
            if event == cv2.EVENT_LBUTTONDOWN:
                mouse_down = True
                list[trigger][0] = (x, y)

            if event == cv2.EVENT_LBUTTONUP and mouse_down:
                mouse_down = False
                list[trigger][1] = (x,y)
                cv2.line(im_disp, (list[trigger][0][0], list[trigger][0][1]),
                         (list[trigger][1][0], list[trigger][1][1]), (255, 0, 0), 2)
                trigger += 1
        else:
            pass
    cv2.setMouseCallback(window_name, callback)
    while True:
        cv2.imshow(window_name,im_disp)
        key = cv2.waitKey(10) & 0xFF

        if key == ord('r'):
            # Press key `q` to quit the program
            return list
            exit()
项目:fathom    作者:rdadolf    | 项目源码 | 文件源码
def __init__(self, rom_name, vis,frameskip=1,windowname='preview'):
    self.ale = ALEInterface()
    self.max_frames_per_episode = self.ale.getInt("max_num_frames_per_episode");
    self.ale.setInt("random_seed",123)
    self.ale.setInt("frame_skip",frameskip)
    romfile = str(ROM_PATH)+str(rom_name)
    if not os.path.exists(romfile):
      print 'No ROM file found at "'+romfile+'".\nAdjust ROM_PATH or double-check the filt exists.'
    self.ale.loadROM(romfile)
    self.legal_actions = self.ale.getMinimalActionSet()
    self.action_map = dict()
    self.windowname = windowname
    for i in range(len(self.legal_actions)):
      self.action_map[self.legal_actions[i]] = i

    # print(self.legal_actions)
    self.screen_width,self.screen_height = self.ale.getScreenDims()
    print("width/height: " +str(self.screen_width) + "/" + str(self.screen_height))
    self.vis = vis
    if vis:
      cv2.startWindowThread()
      cv2.namedWindow(self.windowname, flags=cv2.WINDOW_AUTOSIZE) # permit manual resizing
项目:pynephoscope    作者:neXyon    | 项目源码 | 文件源码
def __init__(self, files):
        if len(files) < 2:
            raise Exception('Need at least two files to compare.')

        self.image_window = 'Image'
        self.threshold_window = 'Threshold'
        self.difference_window = 'Difference'
        self.files = files
        self.tb_threshold = 'Threshold'
        self.tb_image = 'Image'
        self.current_image = 0

        self.image1 = None
        self.image2 = None
        self.difference = None
        self.threshold = 25
        self.gray = None

        cv2.namedWindow(self.image_window, cv2.WINDOW_AUTOSIZE)
        cv2.namedWindow(self.difference_window, cv2.WINDOW_AUTOSIZE)
        cv2.namedWindow(self.threshold_window, cv2.WINDOW_AUTOSIZE)
        cv2.createTrackbar(self.tb_image, self.difference_window, 0, len(self.files) - 2, self.selectImage)
        cv2.createTrackbar(self.tb_threshold, self.threshold_window, self.threshold, 255, self.renderThreshold)
        self.render()
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
def drawingDemo():
    img = emptyImage()

    # ??2?????
    drawLine(img, (10, 10), (200, 200), (0, 0, 255), 2)

    # ???-1???????????????
    drawCircle(img, (300, 100), 80, (0, 255, 0), -1)

    # ????????
    drawRectangle(img, (10, 210), (210, 350), (100, 100, 0), -1)
    drawRectangle(img, (10, 210), (210, 350), (255, 0, 0), 3)

    # ?????
    drawElipse(img, (450, 100), (30, 80), 0, 0, 360, (0, 100, 100), -1)

    # ???????
    pts = np.array([[(250, 240), (270, 280), (350, 320), (500, 300), (450, 230), (350, 210)]], dtype=np.int32)
    drawPolylines(img, pts, True, (255, 100, 100), 5)

    # ???????
    drawText(img, 'OpenCV', (20, 450), font_types[0], 4, (200, 200, 200), 2)

    cv2.namedWindow('DrawingDemo', cv2.WINDOW_AUTOSIZE)
    cv2.imshow('DrawingDemo', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
项目:Smart-Surveillance-System-using-Raspberry-Pi    作者:OmkarPathak    | 项目源码 | 文件源码
def add_person(people_folder, shape):
    """ Funtion to add pictures of a person
    """
    person_name = input('What is the name of the new person: ').lower()
    folder = people_folder + person_name
    if not os.path.exists(folder):
        input("I will now take 20 pictures. Press ENTER when ready.")
        os.mkdir(folder)
        video = VideoCamera()
        detector = FaceDetector('face_recognition_system/frontal_face.xml')
        counter = 1
        timer = 0
        cv2.namedWindow('Video Feed', cv2.WINDOW_AUTOSIZE)
        cv2.namedWindow('Saved Face', cv2.WINDOW_NORMAL)
        while counter < 21:
            frame = video.get_frame()
            face_coord = detector.detect(frame)
            if len(face_coord):
                frame, face_img = get_images(frame, face_coord, shape)
                # save a face every second, we start from an offset '5' because
                # the first frame of the camera gets very high intensity
                # readings.
                if timer % 100 == 5:
                    cv2.imwrite(folder + '/' + str(counter) + '.jpg',
                                face_img[0])
                    print ('Images Saved:' + str(counter))
                    counter += 1
                    cv2.imshow('Saved Face', face_img[0])

            cv2.imshow('Video Feed', frame)
            cv2.waitKey(50)
            timer += 5
    else:
        print ("This name already exists.")
        sys.exit()
项目:pynephoscope    作者:neXyon    | 项目源码 | 文件源码
def __init__(self):
        if len(sys.argv) < 2:
            print('Usage: calibration <directory> [<filename>]')
            print('The supplied directory should contain the calibration images.')
            sys.exit(1)

        size = 640

        self.path = sys.argv[1]
        self.image_window = 'Image Calibration'
        self.sky_window = 'Sky Calibration'
        self.tb_image_switch = 'image'
        self.tb_max_mag = 'maximum magnitude'
        self.save_file_name = 'data'
        self.selected_star = None
        self.selected_color = (0, 0, 255)
        self.marked_color = (0, 255, 0)
        self.circle_radius = 5
        self.max_mag = 4
        self.renderer = SkyRenderer(size)

        try:
            self.calibrator = Calibrator(SkyCameraFile.glob(self.path), EarthLocation(lat=Configuration.latitude, lon=Configuration.longitude, height=Configuration.elevation))
        except Exception as e:
            print(e.message)
            sys.exit(2)

        if len(sys.argv) > 2:
            self.save_file_name = sys.argv[2]
            if os.path.exists(self.save_file_name):
                self.calibrator.load(self.save_file_name)

        cv2.namedWindow(self.image_window, cv2.WINDOW_AUTOSIZE)
        cv2.namedWindow(self.sky_window, cv2.WINDOW_AUTOSIZE)

        self.selectImage(0)

        cv2.setMouseCallback(self.image_window, self.imageMouseCallback)
        cv2.setMouseCallback(self.sky_window, self.skyMouseCallback)
        cv2.createTrackbar(self.tb_image_switch, self.image_window, 0, len(self.calibrator.files) - 1, self.selectImage)
        cv2.createTrackbar(self.tb_max_mag, self.sky_window, self.max_mag, 6, self.setMaxMag)
项目:Character_Segmentation    作者:dishank-b    | 项目源码 | 文件源码
def showimages():
    cv2.namedWindow('Source Image', cv2.WINDOW_AUTOSIZE)
    cv2.namedWindow('Threshold Image', cv2.WINDOW_AUTOSIZE)
    cv2.namedWindow('Binary Image', cv2.WINDOW_AUTOSIZE)
    # cv2.namedWindow('Contour Image', cv2.WINDOW_NORMAL)
    # cv2.namedWindow('noise_remove Image', cv2.WINDOW_NORMAL)

    cv2.imshow("Source Image", src_img)
    cv2.imshow("Binary Image", bin_img)
    cv2.imshow("Threshold Image", final_thr)
    # cv2.imshow("Contour Image", final_contr)
    # cv2.imshow('noise_remove Image', noise_remove)

    # plt.show()
项目:remho    作者:teamresistance    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()
        LOG.info('DisplayObserver initialized.')
        cv2.namedWindow("Window", cv2.WINDOW_AUTOSIZE)
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
def find_blob() :
    radius = 0
    # Load input image
    _, bgr_image = img.read()

    orig_image = bgr_image

    bgr_image = cv2.medianBlur(bgr_image, 3)

    # Convert input image to HSV
    hsv_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2HSV)

    # Threshold the HSV image, keep only the red pixels
    lower_red_hue_range = cv2.inRange(hsv_image, (0, 100, 100), (10, 255, 255))
    upper_red_hue_range = cv2.inRange(hsv_image, (160, 100, 100), (179, 255, 255))
    # Combine the above two images
    red_hue_image = cv2.addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0)

    red_hue_image = cv2.GaussianBlur(red_hue_image, (9, 9), 2, 2)

    # Use the Hough transform to detect circles in the combined threshold image
    circles = cv2.HoughCircles(red_hue_image, cv.CV_HOUGH_GRADIENT, 1, 120, 100, 20, 10, 0);

    # Loop over all detected circles and outline them on the original image
    all_r = np.array([])
    if circles is not None:
        for i in circles[0]:

            all_r = np.append(all_r, int(round(i[2])))
        closest_ball = all_r.argmax()
        center=(int(round(circles[0][closest_ball][0])), int(round(circles[0][closest_ball][1])))
        radius=int(round(circles[0][closest_ball][2]))
        if draw_circle_enable:
            cv2.circle(orig_image, center, radius, (0, 255, 0), 5);

    # Show images
    if show_image_enable:
        cv2.namedWindow("Threshold lower image", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Threshold lower image", lower_red_hue_range)
        cv2.namedWindow("Threshold upper image", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Threshold upper image", upper_red_hue_range)
        cv2.namedWindow("Combined threshold images", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Combined threshold images", red_hue_image)
        cv2.namedWindow("Detected red circles on the input image", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Detected red circles on the input image", orig_image)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        return (0, 0), 0
    if radius > 3:
        return center, radius;
    else:
        return (0, 0), 0