Python cv2 模块,startWindowThread() 实例源码

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

项目:Stereo-Pose-Machines    作者:ppwwyyxx    | 项目源码 | 文件源码
def dump_2dcoor():
    camera = libcpm.Camera()
    camera.setup()
    runner = get_parallel_runner('../data/cpm.npy')
    cv2.namedWindow('color')
    cv2.startWindowThread()
    cnt = 0
    while True:
        cnt += 1
        m1 = camera.get_for_py(0)
        m1 = np.array(m1, copy=False)
        m2 = camera.get_for_py(1)
        m2 = np.array(m2, copy=False)

        o1, o2 = runner(m1, m2)
        pts = []
        for k in range(14):
            pts.append((argmax_2d(o1[:,:,k]),
                argmax_2d(o2[:,:,k])))
        pts = np.asarray(pts)
        np.save('pts{}.npy'.format(cnt), pts)
        cv2.imwrite("frame{}.png".format(cnt), m1);
        if cnt == 10:
            break
项目:nelpy    作者:nelpy    | 项目源码 | 文件源码
def pick_corrs(images, n_pts_to_pick=4):
    data = [ [[], 0, False, False, False, image, "Image %d" % i, n_pts_to_pick]
            for i, image in enumerate(images)]

    for d in data:
        win_name = d[6]
        cv2.namedWindow(win_name)
        cv2.setMouseCallback(win_name, corr_picker_callback, d)
        cv2.startWindowThread()
        cv2.imshow(win_name, d[5])

    key = None
    while key != '\n' and key != '\r' and key != 'q':
        key = cv2.waitKey(33)
        key = chr(key & 255) if key >= 0 else None

    cv2.destroyAllWindows()

    if key == 'q':
        return None
    else:
        return [d[0] for d in data]
项目: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
项目:atari-human-checkpoint-replay    作者:ionelhosu    | 项目源码 | 文件源码
def __init__(self, rom_name, vis,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",4)
        self.ale.loadROM('roms/' + rom_name )
        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
        self.init_frame_number = 0

        # 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)
项目:Stereo-Pose-Machines    作者:ppwwyyxx    | 项目源码 | 文件源码
def stereo_cpm_viewer():
    camera = libcpm.Camera()
    camera.setup()
    runner = get_parallel_runner('../data/cpm.npy')
    cv2.namedWindow('color')
    cv2.startWindowThread()
    cnt = 0
    while True:
        cnt += 1
        m1 = camera.get_for_py(0)
        m1 = np.array(m1, copy=False)
        m2 = camera.get_for_py(1)
        m2 = np.array(m2, copy=False)

        m1s = cv2.resize(m1, (368,368))
        m2s = cv2.resize(m2, (368,368))

        o1, o2 = runner(m1s, m2s)

        #buf = dumps([m1, m2, o1, o2])
        #f = open('recording/{:03d}.npy'.format(cnt), 'w')
        #f.write(buf)
        #f.close()

        c1 = colorize(m1, o1[:,:,:-1].sum(axis=2))
        c2 = colorize(m2, o2[:,:,:-1].sum(axis=2))
        viz = np.concatenate((c1, c2), axis=1)
        cv2.imshow('color', viz / 255.0)
项目:spqrel_tools    作者:LCAS    | 项目源码 | 文件源码
def __init__(self,person_group_id='robocup_test', delete_group_first=False):

        self._api_key = 'be062e88698e4777ac6196623d7230dd'
        self._topic_timeout = 10 
        #startWindowThread()
        Key.set(self._api_key)

        self._person_group_id = person_group_id

        self._init_person_group(self._person_group_id,delete_group_first)
项目:Double-Deep-Q-Learning    作者:apoorv2904    | 项目源码 | 文件源码
def __init__(self,rom_name):
        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",4)
        self.ale.loadROM('game/' +rom_name)
        self.screen_width,self.screen_height = self.ale.getScreenDims()
        self.legal_actions = self.ale.getMinimalActionSet()
        self.action_map = dict()
        for i in range(len(self.legal_actions)):
            self.action_map[self.legal_actions[i]] = i
        #print len(self.legal_actions)
        self.windowname = rom_name
        cv2.startWindowThread()
        cv2.namedWindow(rom_name)
项目:batch-A3C_tensorflow    作者:gliese581gg    | 项目源码 | 文件源码
def __init__(self,worker_idx,params,net,session,queue,worker_summary_dict,Control,target_net = None):
        self.dead = False
        self.params = params
        self.idx = worker_idx
        #environment
        if self.params['rom'] == 'toy_way':self.env = env_way.env_way(self.params)
        else : self.env=env_atari.env_atari(self.params)
        self.img = self.env.reset()

        #build networks
        self.net = net
        self.sess = session
        self.global_frame = net['global_frame']
        self.frame_ph = net['global_frame_ph']
        self.gf_op = net['global_frame_op']
        self.lr_ph = net['lr_ph']
        self.summary_op = worker_summary_dict['op']
        self.summary_writer = worker_summary_dict['writer']
        self.queue = queue
        self.control = Control

        if self.params['net_type'] == 'AnDQN' : 
            self.target = target_net
            eps_type = np.random.choice(np.arange(len(self.params['eps_prob'])),size=1,replace=True,p=np.array(self.params['eps_prob']))[-1]
            self.eps_max = self.params['eps_max'][eps_type]
            self.eps_min = self.params['eps_min'][eps_type]
            self.eps_frame = self.params['eps_frame'][eps_type]

        else : self.target = net #In A3C, the target network is local network (for code sharing with DQN)

        if self.idx == 0 and self.params['show_0th_thread'] : 
            cv2.startWindowThread()
            cv2.namedWindow('Worker'+str(self.idx)+'_screen')
项目:ImageSteganography    作者:AhmedAtef07    | 项目源码 | 文件源码
def _preview_image(window_name, cv2_image, **kwargs):
    cv2.startWindowThread()
    cv2.namedWindow(window_name)
    cv2.imshow(window_name, cv2_image)
    cv2.waitKey()
    if not 'keep_open' in kwargs:
        cv2.destroyAllWindows()
项目:A3C_tensorflow    作者:gliese581gg    | 项目源码 | 文件源码
def __init__(self,worker_idx,params,net,session,eval_var,worker_summary_dict):
        self.dead = False
        self.params = params
        self.idx = worker_idx
        #environment
        if self.params['rom'] == 'toy_way':self.env = env_way.env_way(self.params)
        else : self.env=env_atari.env_atari(self.params)
        self.img = self.env.reset()

        #build networks
        self.train = net['train_ops'][self.idx]
        self.net = net['worker_nets'][self.idx]
        self.sess = session
        self.worker_copy = net['copy_ops'][self.idx]
        self.master=net['master_net']
        self.global_frame = net['global_frame']
        self.frame_ph = net['global_frame_ph']
        self.gf_op = net['global_frame_op']
        self.lr_ph = net['lr_ph']
        self.summary_op = worker_summary_dict['op']
        self.summary_writer = worker_summary_dict['writer']
        self.eval_var = eval_var
        if self.params['net_type'] == 'AnDQN' : 
            self.target = net['target_net']
            eps_type = np.random.choice(np.arange(len(self.params['eps_prob'])),size=1,replace=True,p=np.array(self.params['eps_prob']))[-1]
            self.eps_max = self.params['eps_max'][eps_type]
            self.eps_min = self.params['eps_min'][eps_type]
            self.eps_frame = self.params['eps_frame'][eps_type]

        else : self.target = net['worker_nets'][self.idx] #In A3C, the target network is local network (for code sharing with DQN)

        if self.idx == 0 and self.params['show_0th_thread'] : 
            cv2.startWindowThread()
            cv2.namedWindow('Worker'+str(self.idx)+'_screen')
项目:tensorflow-rl    作者:steveKapturowski    | 项目源码 | 文件源码
def __init__(self, rom_path, rom_name, visualize, actor_id, rseed, single_life_episodes = False):

        self.ale = ALEInterface()

        self.ale.setInt("random_seed", rseed * (actor_id +1))

        # For fuller control on explicit action repeat (>= ALE 0.5.0) 
        self.ale.setFloat("repeat_action_probability", 0.0)

        # Disable frame_skip and color_averaging
        # See: http://is.gd/tYzVpj
        self.ale.setInt("frame_skip", 1)
        self.ale.setBool("color_averaging", False)
        self.ale.loadROM(rom_path + "/" + rom_name + ".bin")
        self.legal_actions = self.ale.getMinimalActionSet()        
        self.screen_width,self.screen_height = self.ale.getScreenDims()
        #self.ale.setBool('display_screen', True)

        # Processed historcal frames that will be fed in to the network 
        # (i.e., four 84x84 images)
        self.screen_images_processed = np.zeros((IMG_SIZE_X, IMG_SIZE_Y, 
            NR_IMAGES)) 
        self.rgb_screen = np.zeros((self.screen_height,self.screen_width, 3), dtype=np.uint8)
        self.gray_screen = np.zeros((self.screen_height,self.screen_width,1), dtype=np.uint8)

        self.frame_pool = np.empty((2, self.screen_height, self.screen_width))
        self.current = 0
        self.lives = self.ale.lives()

        self.visualize = visualize
        self.visualize_processed = False
        self.windowname = rom_name + ' ' + str(actor_id)
        if self.visualize:
            logger.debug("Opening emulator window...")
            #from skimage import io
            #io.use_plugin('qt')
            cv2.startWindowThread()
            cv2.namedWindow(self.windowname)
            logger.debug("Emulator window opened")

        if self.visualize_processed:
            logger.debug("Opening processed frame window...")
            cv2.startWindowThread()
            logger.debug("Processed frame window opened")
            cv2.namedWindow(self.windowname + "_processed")

        self.single_life_episodes = single_life_episodes
项目:async-deep-rl    作者:traai    | 项目源码 | 文件源码
def __init__(self, rom_path, rom_name, visualize, actor_id, rseed, single_life_episodes = False):

        self.ale = ALEInterface()

        self.ale.setInt("random_seed", rseed * (actor_id +1))

        # For fuller control on explicit action repeat (>= ALE 0.5.0) 
        self.ale.setFloat("repeat_action_probability", 0.0)

        # Disable frame_skip and color_averaging
        # See: http://is.gd/tYzVpj
        self.ale.setInt("frame_skip", 1)
        self.ale.setBool("color_averaging", False)
        self.ale.loadROM(rom_path + "/" + rom_name + ".bin")
        self.legal_actions = self.ale.getMinimalActionSet()        
        self.screen_width,self.screen_height = self.ale.getScreenDims()
        #self.ale.setBool('display_screen', True)

        # Processed historcal frames that will be fed in to the network 
        # (i.e., four 84x84 images)
        self.screen_images_processed = np.zeros((IMG_SIZE_X, IMG_SIZE_Y, 
            NR_IMAGES)) 
        self.rgb_screen = np.zeros((self.screen_height,self.screen_width, 3), dtype=np.uint8)
        self.gray_screen = np.zeros((self.screen_height,self.screen_width,1), dtype=np.uint8)

        self.frame_pool = np.empty((2, self.screen_height, self.screen_width))
        self.current = 0
        self.lives = self.ale.lives()

        self.visualize = visualize
        self.visualize_processed = False
        self.windowname = rom_name + ' ' + str(actor_id)
        if self.visualize:
            logger.debug("Opening emulator window...")
            #from skimage import io
            #io.use_plugin('qt')
            cv2.startWindowThread()
            cv2.namedWindow(self.windowname)
            logger.debug("Emulator window opened")

        if self.visualize_processed:
            logger.debug("Opening processed frame window...")
            cv2.startWindowThread()
            logger.debug("Processed frame window opened")
            cv2.namedWindow(self.windowname + "_processed")

        self.single_life_episodes = single_life_episodes