本文整理汇总了Python中cv2.cv2.resize方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.resize方法的具体用法?Python cv2.resize怎么用?Python cv2.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2.cv2
的用法示例。
在下文中一共展示了cv2.resize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next_batch
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import resize [as 别名]
def next_batch(self, batch_size):
"""
:param batch_size:
:return:
"""
start = self.__batch_counter * batch_size
end = (self.__batch_counter + 1) * batch_size
self.__batch_counter += 1
imagenames_slice = self._epoch_imagenames[start:end]
labels_slice = self._epoch_labels[start:end]
images_slice = [cv2.resize(cv2.imread(tmp, cv2.IMREAD_UNCHANGED),(config.cfg.TRAIN.width,32)) for tmp in imagenames_slice]
images_slice = np.array(images_slice)
images_slice = self.normalize_images(images_slice, self.__normalization)
# if overflow restart from the beginning
if images_slice.shape[0] != batch_size and self.__batch_counter > 1:
# self._start_new_epoch()
# return self.next_batch(batch_size)
return images_slice, labels_slice, imagenames_slice
else:
return images_slice, labels_slice, imagenames_slice
示例2: __init__
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import resize [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))
示例3: execute
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import resize [as 别名]
def execute(self,data,batch_size):
sess=self.output['sess']
x=self.output['x']
y_=self.output['y_']
decoder = data_utils.TextFeatureIO()
ret=[]
for i in range(batch_size):
image = Image.open(data[i])
image = cv2.cvtColor(np.asarray(image),cv2.COLOR_RGB2BGR)
image = cv2.resize(image, (config.cfg.TRAIN.width, 32))
image = np.expand_dims(image, axis=0).astype(np.float32)
preds = sess.run(y_, feed_dict={x:image})
preds = decoder.writer.sparse_tensor_to_str(preds[0])[0]+'\n'
ret.append(preds)
return ret
示例4: execute
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import resize [as 别名]
def execute(self,data,batch_size):
sess=self.output['sess']
x=self.output['x']
y=self.output['y']
decoder = data_utils.TextFeatureIO()
ret=[]
for i in range(batch_size):
image = Image.open(data[i])
image = cv2.cvtColor(np.asarray(image),cv2.COLOR_RGB2BGR)
image = cv2.resize(image, (100, 32))
image = np.expand_dims(image, axis=0).astype(np.float32)
preds = sess.run(decodes, feed_dict={x:image})
preds = decoder.writer.sparse_tensor_to_str(preds[0])[0]+'\n'
ret.append(preds)
return ret
示例5: next_batch
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import resize [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
示例6: next_batch
# 需要导入模块: from cv2 import cv2 [as 别名]
# 或者: from cv2.cv2 import resize [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