我正在尝试将图像转换为分类,但是找不到灵魂。
实际代码将转换一张图片,而不是整个文件夹。是否有任何想从文件夹“ images”中读取所有图像并将其转换为具有骨骼结构的文件夹“ output”的想法?
非常感谢。
亚历山大
import logging
import time
import os
import cv2
import numpy as np
from tf_pose.estimator import TfPoseEstimator
from tf_pose.networks import get_graph_path, model_wh
import scripts.label_image as label_img
import scripts.label_image_scene as label_img_scene
logger = logging.getLogger('Pose_Action_and_Scene_Understanding')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
fps_time = 0
address = os.getcwd()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='tf-classification')
parser.add_argument('--image', type=str, required=True)
parser.add_argument('--show-process', type=bool, default=False,
help='for debug purpose, if enabled, speed for inference is dropped.')
args = parser.parse_args()
logger.debug('initialization %s : %s' % ('mobilenet_thin', get_graph_path('mobilenet_thin')))
e = TfPoseEstimator(get_graph_path('mobilenet_thin'), target_size=(432, 368))
image = cv2.imread(args.image)
logger.info('cam image=%dx%d' % (image.shape[1], image.shape[0]))
logger.debug('+image processing+')
logger.debug('+postprocessing+')
start_time = time.time()
humans = e.inference(image, upsample_size=4.0)
img = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)
logger.debug('+classification+')
# Getting only the skeletal structure (with white background) of the actual image
image = np.zeros(image.shape,dtype=np.uint8)
image.fill(255)
image = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)
cv2.imwrite('show1.png',image)
cv2.imshow('tf-classification', image)
cv2.waitKey(0)
logger.debug('+finished+')
cv2.destroyAllWindows()
答案 0 :(得分:0)
根据数据的组织方式,可以使用ImageDataGenerator扩展图像。然后使用.flow或.flow_from_directory将转换后的图像保存到您指定的目录中。文档为here.