當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.CV_LOAD_IMAGE_COLOR屬性代碼示例

本文整理匯總了Python中cv2.CV_LOAD_IMAGE_COLOR屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.CV_LOAD_IMAGE_COLOR屬性的具體用法?Python cv2.CV_LOAD_IMAGE_COLOR怎麽用?Python cv2.CV_LOAD_IMAGE_COLOR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.CV_LOAD_IMAGE_COLOR屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_img

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def read_img(image_path):
  img = cv2.imread(image_path, cv2.CV_LOAD_IMAGE_COLOR)
  return img 
開發者ID:deepinsight,項目名稱:insightface,代碼行數:5,代碼來源:gen_megaface.py

示例2: read_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def read_image(img_path, **kwargs):
  mode = kwargs.get('mode', 'rgb')
  layout = kwargs.get('layout', 'HWC')
  if mode=='gray':
    img = cv2.imread(img_path, cv2.CV_LOAD_IMAGE_GRAYSCALE)
  else:
    img = cv2.imread(img_path, cv2.CV_LOAD_IMAGE_COLOR)
    if mode=='rgb':
      #print('to rgb')
      img = img[...,::-1]
    if layout=='CHW':
      img = np.transpose(img, (2,0,1))
  return img 
開發者ID:deepinsight,項目名稱:insightface,代碼行數:15,代碼來源:face_preprocess.py

示例3: get_captcha

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def get_captcha(captcha_str):
    nparr = np.fromstring(captcha_str, np.uint8)
    ptcha = cv2.imdecode(nparr, cv2.CV_LOAD_IMAGE_COLOR)
    captcha.shape = -1,
    captcha = (captcha[::3].astype(np.int) + captcha[1::3].astype(np.int) + captcha[2::3].astype(np.int)) / 3
    captcha = (255 - captcha).astype(np.uint8)
    return captcha 
開發者ID:leonhx,項目名稱:njucaptcha,代碼行數:9,代碼來源:recognizer.py

示例4: get_word_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def get_word_image(self, gray_scale=True):
        col_type = None
        if gray_scale:
            col_type = cv2.CV_LOAD_IMAGE_GRAYSCALE
        else:
            col_type = cv2.CV_LOAD_IMAGE_COLOR
        
        # load the image
        ul = self.bounding_box['upperLeft']
        wh = self.bounding_box['widthHeight']
        img = cv2.imread(self.image_path, col_type)
        if not np.all(self.bounding_box['widthHeight'] == -1):
            img = img[ul[1]:ul[1]+wh[1], ul[0]:ul[0]+wh[0]]
        return img 
開發者ID:ssudholt,項目名稱:phocnet,代碼行數:16,代碼來源:word_container.py

示例5: _load_cv2

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def _load_cv2(img, grayscale=None):
    """
    TODO
    """
    # load images if given filename, or convert as needed to opencv
    # Alpha layer just causes failures at this point, so flatten to RGB.
    # RGBA: load with -1 * cv2.CV_LOAD_IMAGE_COLOR to preserve alpha
    # to matchTemplate, need template and image to be the same wrt having alpha

    if grayscale is None:
        grayscale = GRAYSCALE_DEFAULT
    if isinstance(img, (str, unicode)):
        # The function imread loads an image from the specified file and
        # returns it. If the image cannot be read (because of missing
        # file, improper permissions, unsupported or invalid format),
        # the function returns an empty matrix
        # http://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/reading_and_writing_images.html
        if grayscale:
            img_cv = cv2.imread(img, LOAD_GRAYSCALE)
        else:
            img_cv = cv2.imread(img, LOAD_COLOR)
        if img_cv is None:
            raise IOError("Failed to read %s because file is missing, "
                          "has improper permissions, or is an "
                          "unsupported or invalid format" % img)
    elif isinstance(img, numpy.ndarray):
        # don't try to convert an already-gray image to gray
        if grayscale and len(img.shape) == 3:  # and img.shape[2] == 3:
            img_cv = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        else:
            img_cv = img
    elif hasattr(img, 'convert'):
        # assume its a PIL.Image, convert to cv format
        img_array = numpy.array(img.convert('RGB'))
        img_cv = img_array[:, :, ::-1].copy()  # -1 does RGB -> BGR
        if grayscale:
            img_cv = cv2.cvtColor(img_cv, cv2.COLOR_BGR2GRAY)
    else:
        raise TypeError('expected an image filename, OpenCV numpy array, or PIL image')
    return img_cv 
開發者ID:asweigart,項目名稱:pyscreeze,代碼行數:42,代碼來源:__init__.py

示例6: fetch_cvimage_from_url

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def fetch_cvimage_from_url(url, maxsize=10 * 1024 * 1024):
    req = requests.get(url, timeout=5, stream=True)
    content = ''
    for chunk in req.iter_content(2048):
        content += chunk
        if len(content) > maxsize:
            req.close()
            raise ValueError('Response too large')
    img_array = np.asarray(bytearray(content), dtype=np.uint8)
    cv2_img_flag = cv2.CV_LOAD_IMAGE_COLOR
    image = cv2.imdecode(img_array, cv2_img_flag)
    return image 
開發者ID:AntreasAntoniou,項目名稱:DeepClassificationBot,代碼行數:14,代碼來源:classifiers.py

示例7: H5ToVideo

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def H5ToVideo(fpath, frames_to_read=None):
    """Read frames from the h5 file.
    Args:
        fpath (str): Filename of h5 file
        frames_to_read (list or None): List of frames to read. None => all frames
    """
    res = []
    with h5py.File(fpath, 'r') as fin:
        nframes = len(fin['frames'])
        if frames_to_read is None:
            frames_to_read = range(nframes)
        grp = fin['frames']
        for fid in frames_to_read:
            res.append(cv2.imdecode(grp[str(fid)].value, cv2.CV_LOAD_IMAGE_COLOR))
    return np.transpose(np.stack(res), (0, 3, 1, 2)) 
開發者ID:facebookresearch,項目名稱:DetectAndTrack,代碼行數:17,代碼來源:video_io.py

示例8: StringArrayElementToFrame

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def StringArrayElementToFrame(string_array, i):
    return cv2.imdecode(np.fromstring(
        string_array[i].tostring(), np.uint8), cv2.CV_LOAD_IMAGE_COLOR) 
開發者ID:facebookresearch,項目名稱:DetectAndTrack,代碼行數:5,代碼來源:video_io.py

示例9: save_images

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_LOAD_IMAGE_COLOR [as 別名]
def save_images(image_path, image_type, data_path, data_name, num_workers):
	"""
	Process all of the image to a numpy array, then store them to a file.
	--------------------
	Arguments:
		image_path (str): path points to images.
		image_type (str): "train", "val", "trainval", or "test".
		data_path (str): path points to the location which stores images.
		data_name (str): name of stored file.
		num_workers (int): number of threads used to load images.
	"""
	dataset = h5py.File(os.path.join(data_path, "%s_%s.h5" % (data_name, image_type)), "w")

	q = queue.Queue()
	images_idx = {}
	images_path = []
	lock = Lock()
	for data in folder_map[image_type]:
		folder = os.path.join(image_path, data)
		images_path.extend(glob.glob(folder+"/*"))
	pattern = re.compile(r"_([0-9]+).jpg")

	for i, img_path in enumerate(images_path):
		assert len(pattern.findall(img_path)) == 1, "More than one index found in an image path!"
		idx = int(pattern.findall(img_path)[0])
		images_idx[idx] = i
		q.put((i, img_path))
	assert len(images_idx) == len(images_path), "Duplicated indices are found!"
	images = dataset.create_dataset("images", (len(images_path), 448, 448, 3), dtype=np.uint8)

	def _worker():
		while True:
			i, img_path = q.get()
			if i is None:
				break
			img = cv2.cvtColor((cv2.resize(cv2.imread(img_path, cv2.CV_LOAD_IMAGE_COLOR), (448, 448))), 
				cv2.COLOR_BGR2RGB)

			with lock:
				if i % 1000 == 0:
					print("processing %i/%i" % (i, len(images_path)))
				images[i] = img
			q.task_done()

	for _ in range(num_workers):
		thread = Thread(target=_worker)
		thread.daemon = True
		thread.start()
	q.join()

	print("Terminating threads...")
	for _ in range(2*num_workers):
		q.put((None, None))

	torch.save(images_idx, os.path.join(data_path, "%s_%s.pt" % (data_name, image_type)))
	dataset.close()
	print("Finish saving images...") 
開發者ID:cvlab-tohoku,項目名稱:Dense-CoAttention-Network,代碼行數:59,代碼來源:load_img.py


注:本文中的cv2.CV_LOAD_IMAGE_COLOR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。