in renderer/viewer2D.py [0:0]
def Vis_Densepose(inputImg, coco_annot):
inputImg = __ValidateNumpyImg(inputImg)
import sys
sys.path.append('/home/hjoo/data/DensePose/detectron/utils/')
import densepose_methods as dp_utils
DP = dp_utils.DensePoseMethods()
if('dp_x' not in coco_annot.keys()):
print("## Warning: No Densepose coco_annotation")
return inputImg
bbr = np.round(coco_annot['bbox']) #[leftTop_x,leftTop_y,width,height]
Point_x = np.array(coco_annot['dp_x'])/ 255. * bbr[2] + bbr[0] # Strech the points to current box. from 255x255 -> [bboxWidth,bboxheight]
Point_y = np.array(coco_annot['dp_y'])/ 255. * bbr[3] + bbr[1] # Strech the points to current box.
# part_seg_index = np.array(coco_annot['dp_I']) # part segment info
#coco_annot['dp_I']: indexing
# Torso Back: 1
# Torso front: 2
# RHand: 3
# LHand: 4
# LFoot: 5
# RFoot: 6
# R_upperLeg_back 7
# L_upperLeg_back 8
# R_upperLeg_front 9
# L_upperLeg_front 10
# R_lowerLeg_back 11
# L_lowerLeg_back 12
# R_lowerLeg_front 13
# L_lowerLeg_front 14
# L_upperArm_front 15
# R_upperArm_front 16
# L_upperArm_back 17
# R_upperArm_back 18
# L_lowerArm_back 19
# R_lowerArm_back 20
# L_lowerArm_front 21
# R_lowerArm_front 22
# RFace: 23
# LFace: 24
#Found BBoxes for rhand, lhand, and face using DensePose Data
RHandIdx = [i for i,x in enumerate(coco_annot['dp_I']) if x == DP_partIdx['RHand'] ] #3.0]
if len(RHandIdx)>0:
minX = min(Point_x[RHandIdx])
maxX = max(Point_x[RHandIdx])
minY = min(Point_y[RHandIdx])
maxY = max(Point_y[RHandIdx])
RhandBBox = [minX, minY, maxX-minX, maxY-minY]
else:
RhandBBox = [-1,-1,-1,-1]
LHandIdx = [i for i,x in enumerate(coco_annot['dp_I']) if x == DP_partIdx['LHand'] ]#4.0]
if len(LHandIdx)>0:
minX = min(Point_x[LHandIdx])
maxX = max(Point_x[LHandIdx])
minY = min(Point_y[LHandIdx])
maxY = max(Point_y[LHandIdx])
LhandBBox = [minX, minY, maxX-minX, maxY-minY]
else:
LhandBBox = [-1,-1,-1,-1]
FaceIdx = [i for i,x in enumerate(coco_annot['dp_I']) if x == DP_partIdx['RFace'] or x == DP_partIdx['LFace'] ] #23.0 or x == 24.0]
if len(FaceIdx)>0:
minX = min(Point_x[FaceIdx])
maxX = max(Point_x[FaceIdx])
minY = min(Point_y[FaceIdx])
maxY = max(Point_y[FaceIdx])
FaceBBox = [minX, minY, maxX-minX, maxY-minY]
else:
FaceBBox = [-1,-1,-1,-1]
# #U,V,I -> Adam vertex (Todo: should be reverified)
# adamVerIdx_vec = np.zeros(len(coco_annot['dp_I']))
# for i, (ii,uu,vv) in enumerate(zip(coco_annot['dp_I'],coco_annot['dp_U'],coco_annot['dp_V'])):
# vertexId = DP.IUV2VertexId(ii,uu,vv)
# adamVerIdx_vec[i] = vertexId
# #draw biggest bbox
# pt1 = ( int(bbr[0]),int(bbr[1]) )
# pt2 = (int(bbr[0] + bbr[2]),int(bbr[1] + bbr[3]) )
# cv2.rectangle(inputImg, pt1, pt2,(0,0,0),1)
#draw RHand bbox
pt1 = ( int(RhandBBox[0]),int(RhandBBox[1]) )
pt2 = (int(RhandBBox[0] + RhandBBox[2]),int(RhandBBox[1] + RhandBBox[3]) )
cv2.rectangle(inputImg, pt1, pt2,(0,0,255),2)
#draw lHand bbox
pt1 = ( int(LhandBBox[0]),int(LhandBBox[1]) )
pt2 = (int(LhandBBox[0] + LhandBBox[2]),int(LhandBBox[1] + LhandBBox[3]) )
cv2.rectangle(inputImg, pt1, pt2,(0,255,0),2)
#draw Face bbox
pt1 = ( int(FaceBBox[0]),int(FaceBBox[1]) )
pt2 = (int(FaceBBox[0] + FaceBBox[2]),int(FaceBBox[1] + FaceBBox[3]) )
cv2.rectangle(inputImg, pt1, pt2,(255,0,0),2)
# Draw Densepose Keypoints
tempColorIdx = np.array(coco_annot['dp_I'])/ 24 *255
#tempColorIdx = np.array(coco_annot['dp_U']) *255
#tempColorIdx = np.array(coco_annot['dp_V']) *255
tempColorIdx = np.uint8(tempColorIdx)
tempColorIdx = cv2.applyColorMap(tempColorIdx, cv2.COLORMAP_JET)
for cnt, pt in enumerate(zip(Point_x,Point_y,tempColorIdx, coco_annot['dp_I'])):
# if pt[3] != DP_partIdx['Torso_Front']: #Uncomment this if you want to draw specific part
# continue
#tempColorIdx = coco_annot['dp_I']
tempColor = pt[2][0].astype(np.int32).tolist()
cv2.circle(inputImg,(int(pt[0]),int(pt[1])), 5,tempColor, -1)
return inputImg