コード例 #1
0
 bounding_box = {
     'cam_00_10_30': bbox1,
     'cam_01_10_30': bbox2,
     'cam_02_10_30': bbox3,
     'cam_03_10_30': bbox4
 }
 img_paths = os.listdir(params['test_img_directory'])
 for img_path in img_paths:
     img = cv2.imread(os.path.join(params['test_img_directory'], img_path))
     bbox = bounding_box[img_path[0:12]]
     size = max((bbox[2] - bbox[0]), (bbox[3] - bbox[1]))
     img_crop = np.copy(img)[bbox[1]:bbox[1] + size, bbox[0]:bbox[0] + size]
     img_resize = cv2.resize(img_crop, (256, 256))
     #test_img = cv2.cvtColor(test_img, cv2.COLOR_BGR2RGB)
     if predictJoints:
         predictions = model.predictJoints(img_resize, mode='gpu')
         print(' Predict on {}'.format(img_path))
         print(
             np.add(
                 np.asarray(predictions) * (bbox[1] - bbox[0]) / 256,
                 np.array([bbox[0], bbox[2]])))
         show_prections(img_resize, predictions,
                        img_path[0:-4] + '_pred' + img_path[-4:])
     else:
         # output heatmap = 1*64 x 64 x outputDim
         out_heatmap = np.squeeze(model.predictHM(img_resize))
         for i in range(out_heatmap.shape[2]):
             joint_hm = np.asarray(cv2.resize(255 * out_heatmap[:, :, i],
                                              (256, 256)),
                                   dtype=np.uint8)
             joint_hm = cv2.applyColorMap(joint_hm, cv2.COLORMAP_JET)
コード例 #2
0
		keypt = (int(coord[0]), int(coord[1]))
		text_loc = (keypt[0]+5, keypt[1]+7)
		cv2.circle(img, keypt, 3, RED, -1)
		cv2.putText(img, str(i), text_loc, cv2.FONT_HERSHEY_DUPLEX, 0.5, RED, 1, cv2.LINE_AA)

	np.savetxt(a.output_dir+filename[:-4]+'_pred.csv', 
	predictions , delimiter=",", fmt='%i')
	# print(a.output_dir+filename+'_pred.csv')

	cv2.imwrite(a.output_dir+filename[:-4]+'_pred.png',img)
	# cv2.imshow('img', img)
	# cv2.waitKey(0)

if __name__ == '__main__':
	print('--Parsing Config File')
	params = process_config('config.cfg')


	from os import listdir
	ImageFileNames=listdir(a.input_dir)

	model = Inference(model=a.checkpoint)

	for i in range(len(ImageFileNames)):
	    #ImageName = a.input_dir+'/'+ImageFileNames[i]

		img = cv2.imread(os.path.join( a.input_dir, ImageFileNames[i]))

		test_img=img	
		predictions = model.predictJoints(test_img, mode='gpu')
		show_prections(test_img, predictions,ImageFileNames[i])