I'm trying to generate three channel IUV image from detectrone2 densepose as: IUV image needed But instead, I receive this image: Final UV map I've used the code from Is there a way to obtain IUV map from image in tensorflow? and modified it to the following code:
from PIL import Image
import pickle
import numpy as np
import copy
from sys import argv
import sys
sys.path.append("/home/haiho/detectron2/projects/DensePose")
pklpath = '/home/haiho/Dropbox/vid2vid_folder/pose_datase/train/densepose-pkl/frame0.pkl'
with open(pklpath, "rb") as hFile:
dp_frame = pickle.load(hFile)[0]
if len(dp_frame['scores']) == 0:
print(f'{pklpath} does not contain persons')
exit(0)
instance_id = 0
bbox = np.array(dp_frame['pred_boxes_XYXY'][instance_id])
result = dp_frame['pred_densepose'][instance_id]
uv = np.array(result.uv.detach().cpu()*255, dtype=np.uint8)
labels = np.array(result.labels.detach().cpu(),dtype=np.uint8)
# 2=Labels
c,h,w = uv.shape
x1, y1, x2, y2 = round(bbox[0]), round(bbox[1]), round(bbox[0]+w), round(bbox[1]+h)
print(x1, y1, x2, y2)
canvas_size = (1080, 1920, 3)
canvas = np.zeros(canvas_size, dtype=np.uint8)
iuv = np.stack((uv[1,:,:], uv[0,:,:], labels))
iuv = np.transpose(iuv, (1,2,0))
canvas[y1:y2, x1:x2, :] = iuv
print('hay')
Image.fromarray(canvas).save('output1.jpg')