本文整理汇总了Python中cv2.cv2.IMREAD_COLOR属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.IMREAD_COLOR属性的具体用法?Python cv2.IMREAD_COLOR怎么用?Python cv2.IMREAD_COLOR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2.cv2
的用法示例。
在下文中一共展示了cv2.IMREAD_COLOR属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import IMREAD_COLOR [as 别名]
def __init__(self, path, viewer=None, green_screen=False, factor=0.84):
self.path = path
self.img = cv2.imread(self.path, cv2.IMREAD_COLOR)
if green_screen:
self.img = cv2.medianBlur(self.img, 5)
divFactor = 1 / (self.img.shape[1] / 640)
print(self.img.shape)
print('Resizing with factor', divFactor)
self.img = cv2.resize(self.img, (0, 0), fx=divFactor, fy=divFactor)
cv2.imwrite("/tmp/resized.png", self.img)
remove_background("/tmp/resized.png", factor=factor)
self.img_bw = cv2.imread("/tmp/green_background_removed.png", cv2.IMREAD_GRAYSCALE)
# rescale self.img and self.img_bw to 640
else:
self.img_bw = cv2.imread(self.path, cv2.IMREAD_GRAYSCALE)
self.viewer = viewer
self.green_ = green_screen
self.kernel_ = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
示例2: next_batch
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import IMREAD_COLOR [as 别名]
def next_batch(self, batch_size):
"""
:param batch_size:
:return:
"""
assert self._label_gt_pts.shape[0] == self._label_image_path.shape[0]
idx_start = batch_size * self._next_batch_loop_count
idx_end = batch_size * self._next_batch_loop_count + batch_size
if idx_end > self._label_image_path.shape[0]:
self._random_dataset()
self._next_batch_loop_count = 0
return self.next_batch(batch_size)
else:
gt_img_list = self._label_image_path[idx_start:idx_end]
gt_pts_list = self._label_gt_pts[idx_start:idx_end]
gt_imgs = []
for gt_img_path in gt_img_list:
img = cv2.imread(gt_img_path, cv2.IMREAD_COLOR)
img = cv2.resize(img, (128, 64), interpolation=cv2.INTER_LINEAR)
gt_imgs.append(img)
self._next_batch_loop_count += 1
return gt_imgs, gt_pts_list
示例3: next_batch
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import IMREAD_COLOR [as 别名]
def next_batch(self, batch_size):
"""
:param batch_size:
:return:
"""
assert len(self._gt_label_list) == len(self._gt_img_list)
idx_start = batch_size * self._next_batch_loop_count
idx_end = batch_size * self._next_batch_loop_count + batch_size
if idx_end > len(self._gt_label_list):
self._random_dataset()
self._next_batch_loop_count = 0
return self.next_batch(batch_size)
else:
gt_img_list = self._gt_img_list[idx_start:idx_end]
gt_label_list = self._gt_label_list[idx_start:idx_end]
gt_imgs = []
gt_labels = []
for gt_img_path in gt_img_list:
gt_imgs.append(cv2.imread(gt_img_path, cv2.IMREAD_COLOR))
for gt_label_path in gt_label_list:
label_img = cv2.imread(gt_label_path, cv2.IMREAD_COLOR)
label_binary = np.zeros([label_img.shape[0], label_img.shape[1]], dtype=np.uint8)
idx = np.where((label_img[:, :, :] == [255, 255, 255]).all(axis=2))
label_binary[idx] = 1
gt_labels.append(label_binary)
self._next_batch_loop_count += 1
return gt_imgs, gt_labels
示例4: ensemble_image
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import IMREAD_COLOR [as 别名]
def ensemble_image(params):
file, dirs, ensembling_dir, strategy = params
images = []
for dir in dirs:
file_path = os.path.join(dir, file)
images.append(cv2.imread(file_path, cv2.IMREAD_COLOR))
images = np.array(images)
if strategy == 'average':
ensembled = average_strategy(images)
elif strategy == 'hard_voting':
ensembled = hard_voting(images)
else:
raise ValueError('Unknown ensembling strategy')
cv2.imwrite(os.path.join(ensembling_dir, file), ensembled)
示例5: next_batch
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import IMREAD_COLOR [as 别名]
def next_batch(self, batch_size):
"""
:param batch_size:
:return:
"""
assert len(self._gt_label_binary_list) == len(self._gt_label_instance_list) \
== len(self._gt_img_list)
idx_start = batch_size * self._next_batch_loop_count
idx_end = batch_size * self._next_batch_loop_count + batch_size
if idx_start == 0 and idx_end > len(self._gt_label_binary_list):
raise ValueError('Batch size不能大于样本的总数量')
if idx_end > len(self._gt_label_binary_list):
self._random_dataset()
self._next_batch_loop_count = 0
return self.next_batch(batch_size)
else:
gt_img_list = self._gt_img_list[idx_start:idx_end]
gt_label_binary_list = self._gt_label_binary_list[idx_start:idx_end]
gt_label_instance_list = self._gt_label_instance_list[idx_start:idx_end]
gt_imgs = []
gt_labels_binary = []
gt_labels_instance = []
for gt_img_path in gt_img_list:
gt_img = cv2.imread(gt_img_path, cv2.IMREAD_COLOR)
gt_img = cv2.resize(gt_img, (CFG.TRAIN.IMG_WIDTH, CFG.TRAIN.IMG_HEIGHT))
gt_imgs.append(gt_img)
for gt_label_path in gt_label_binary_list:
label_img = cv2.imread(gt_label_path, cv2.IMREAD_GRAYSCALE)
label_img = label_img / 255
label_binary = cv2.resize(label_img, (CFG.TRAIN.IMG_WIDTH, CFG.TRAIN.IMG_HEIGHT), interpolation=cv2.INTER_NEAREST)
label_binary = np.expand_dims(label_binary, axis=-1)
gt_labels_binary.append(label_binary)
for gt_label_path in gt_label_instance_list:
label_img = cv2.imread(gt_label_path, cv2.IMREAD_UNCHANGED)
label_img = cv2.resize(label_img, (CFG.TRAIN.IMG_WIDTH, CFG.TRAIN.IMG_HEIGHT), interpolation=cv2.INTER_NEAREST)
gt_labels_instance.append(label_img)
self._next_batch_loop_count += 1
return gt_imgs, gt_labels_binary, gt_labels_instance