Upload
Browse files- .gitattributes +2 -0
- 3DBiCar.py +74 -0
- README.md +0 -1
- readme.md +17 -0
- strictly.md +11 -0
- utils.py +112 -0
.gitattributes
CHANGED
@@ -56,3 +56,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
56 |
# Video files - compressed
|
57 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
58 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
56 |
# Video files - compressed
|
57 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
58 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
59 |
+
*.obj filter=lfs diff=lfs merge=lfs -text
|
60 |
+
*.mtl filter=lfs diff=lfs merge=lfs -text
|
3DBiCar.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
from torch.utils.data import Dataset, DataLoader
|
4 |
+
import numpy as np
|
5 |
+
import cv2
|
6 |
+
from PIL import Image
|
7 |
+
import json
|
8 |
+
import openmesh as om
|
9 |
+
import pdb
|
10 |
+
from utils import *
|
11 |
+
|
12 |
+
class BiCarDataset(Dataset):
|
13 |
+
def __init__(self, dataset_folder,input_size=512):
|
14 |
+
self.dataset_folder = dataset_folder
|
15 |
+
self.data_index_list = os.listdir(dataset_folder)
|
16 |
+
self.input_size = input_size
|
17 |
+
|
18 |
+
def __getitem__(self, index):
|
19 |
+
instance_index = self.data_index_list[index]
|
20 |
+
instance_folder = os.path.join(self.dataset_folder,instance_index)
|
21 |
+
input_kps= np.zeros(1)
|
22 |
+
# image/mask/annotation
|
23 |
+
#processed images and mask
|
24 |
+
#input_image = cv2.imread(os.path.join(instance_folder,'image','image_reshape512.jpeg'))
|
25 |
+
#input_mask = cv2.imread(os.path.join(instance_folder,'image','mask512.png'))
|
26 |
+
#processed image in dataloader
|
27 |
+
image = Image.open(os.path.join(instance_folder,'image','raw_image.jpeg')).convert('RGB')
|
28 |
+
polygon,kps,bbox = readjson(os.path.join(instance_folder,'image','annotation.json'))
|
29 |
+
mask = polygon2seg(image,polygon)
|
30 |
+
input_image,input_mask,input_kps = reshape_image_and_anno(image,mask,kps,bbox,self.input_size)
|
31 |
+
|
32 |
+
# this two function can be used to visualize
|
33 |
+
#utils.show_seg(nimage,nmask)
|
34 |
+
#utils.show_kps(nimage,nkps)
|
35 |
+
|
36 |
+
#params: shape and pose
|
37 |
+
beta = np.load(os.path.join(instance_folder,'params','beta.npy'))[:100]
|
38 |
+
theta = np.load(os.path.join(instance_folder,'params','pose.npy')).reshape(3,24)
|
39 |
+
|
40 |
+
#mesh: Here we only read points and uvmap of body only.
|
41 |
+
#Tbody: T-pose body; Pbody: Posed body.
|
42 |
+
tmesh = om.read_polymesh(os.path.join(instance_folder,'tpose','m.obj'))
|
43 |
+
tbody_points = tmesh.points()
|
44 |
+
tbody_uv = cv2.imread(os.path.join(instance_folder,'tpose','m.BMP'))
|
45 |
+
|
46 |
+
pmesh = om.read_polymesh(os.path.join(instance_folder,'pose','m.obj'))
|
47 |
+
pbody_points = pmesh.points()
|
48 |
+
pbody_uv = cv2.imread(os.path.join(instance_folder,'pose','m.BMP'))
|
49 |
+
|
50 |
+
|
51 |
+
return {'input_image':input_image,
|
52 |
+
'input_mask':input_mask,
|
53 |
+
'input_kps':input_kps,
|
54 |
+
#'json_annotation':annotation,
|
55 |
+
'beta':beta,
|
56 |
+
'theta':theta,
|
57 |
+
'Tbody_points':tbody_points,
|
58 |
+
'Tbody_uv':tbody_uv,
|
59 |
+
'Pbody_points':pbody_points,
|
60 |
+
'Pbody_uv':pbody_uv
|
61 |
+
}
|
62 |
+
|
63 |
+
def __len__(self):
|
64 |
+
return len(self.data_index_list)
|
65 |
+
|
66 |
+
dataset = BiCarDataset('./3DBiCar')
|
67 |
+
batch_size = 2
|
68 |
+
dataset.__getitem__(1)
|
69 |
+
dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True)
|
70 |
+
|
71 |
+
for batch in dataloader:
|
72 |
+
for item in batch:
|
73 |
+
print(item,batch[item].shape)
|
74 |
+
break
|
README.md
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
[RaBit: Parametric Modeling of 3D Biped Cartoon Characters with a Topological-consistent Dataset](https://gaplab.cuhk.edu.cn/projects/RaBit/)
|
|
|
|
readme.md
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Welcome to *3DBiCar*
|
2 |
+
|
3 |
+
Each folder in our dataset contains a character along with its associated data.
|
4 |
+
+ The `image` folder contains the original image and its corresponding 2D annotations, i.e., mask and 2D joints.
|
5 |
+
|
6 |
+
+ The `params` folder contains two ".npy" files, which include the beta and theta parameters related to *RaBit*.
|
7 |
+
|
8 |
+
+ The `pose` and `tpose` folders provides the model with rest pose and reference pose, respectively.
|
9 |
+
|
10 |
+
+ The `metadata.json` file provides meta information about each character, such as its category, image style, and the URL of the image source.
|
11 |
+
|
12 |
+
Note: Due to copyright issues, certain reference images of some instances cannot be released. As an alternative, we provide a rendered image for those instances. Please read "strictly.md" for copyright issue.
|
13 |
+
|
14 |
+
Update:
|
15 |
+
+ 3DBiCar.py is the dataloader to load the dataset.
|
16 |
+
|
17 |
+
+ utils.py is some function used in 3DBiCar.
|
strictly.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This dataset is strictly intended for research purposes and cannot be used for commercial use. If you use this dataset in your research, please consider the following BibTeX entry and give us a [star](https://github.com/zhongjinluo/RaBit)!
|
2 |
+
|
3 |
+
```
|
4 |
+
@inproceedings{luo2023rabit,
|
5 |
+
title={RaBit: Parametric Modeling of 3D Biped Cartoon Characters with a Topological-consistent Dataset},
|
6 |
+
author={Luo, Zhongjin and Cai, Shengcai and Dong, Jinguo and Ming, Ruibo and Qiu, Liangdong and Zhan, Xiaohang and Han, Xiaoguang},
|
7 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
8 |
+
year={2023}
|
9 |
+
}
|
10 |
+
```
|
11 |
+
|
utils.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
+
from PIL import Image, ImageDraw
|
5 |
+
|
6 |
+
|
7 |
+
def readjson(filename):
|
8 |
+
with open(filename, 'r', encoding='utf-8') as f:
|
9 |
+
data = json.load(f)
|
10 |
+
polygon=None
|
11 |
+
kps = np.ones((24,3))*-1 #x1,y1,status (-1:not exist. 0/1: covered or not)
|
12 |
+
for x in data['shapes']:
|
13 |
+
if x['shape_type']=='polygon':
|
14 |
+
polygon = x['points']
|
15 |
+
elif x['shape_type']=='point':
|
16 |
+
_,index,hidden = x['label'].split('-')
|
17 |
+
index = int(index.split('_')[-1])
|
18 |
+
hidden = int(hidden[-1]=='1')
|
19 |
+
kps[index] = np.array([x['points'][0][0],x['points'][0][1],hidden])
|
20 |
+
|
21 |
+
poly = np.array(polygon)
|
22 |
+
polymax = np.max(poly,axis=0).tolist()
|
23 |
+
polymin = np.min(poly,axis=0).tolist()
|
24 |
+
bbox = polymin+polymax #x1 y1 x2 y2
|
25 |
+
return polygon,kps,bbox
|
26 |
+
|
27 |
+
def polygon2seg(image,polygon):
|
28 |
+
for i in range(len(polygon)):
|
29 |
+
polygon[i] = tuple(polygon[i])
|
30 |
+
mask = Image.new('L', (image.width, image.height), 0)
|
31 |
+
ImageDraw.Draw(mask).polygon(polygon, outline=0, fill=1)
|
32 |
+
return np.array(mask)
|
33 |
+
|
34 |
+
def show_seg(image,mask):
|
35 |
+
image = np.array(image).copy()
|
36 |
+
mask = np.array(mask)
|
37 |
+
mask = mask[:,:,np.newaxis]
|
38 |
+
masked_image = image*mask
|
39 |
+
Image.fromarray(masked_image)
|
40 |
+
masked_image = Image.fromarray(masked_image)
|
41 |
+
masked_image.show()
|
42 |
+
return
|
43 |
+
|
44 |
+
def show_kps(image,kps):
|
45 |
+
image = np.array(image).copy()
|
46 |
+
for x,y,h in kps:
|
47 |
+
y,x,h = int(y),int(x),int(h)
|
48 |
+
if h==-1:
|
49 |
+
continue
|
50 |
+
point_size=2
|
51 |
+
if h==0:
|
52 |
+
point_color=(0,0,255)
|
53 |
+
else:
|
54 |
+
point_color=(0,255,0)
|
55 |
+
cv2.circle(image,(x,y),point_size,point_color,thickness=4)
|
56 |
+
pil_image = Image.fromarray(image)
|
57 |
+
pil_image.show()
|
58 |
+
return
|
59 |
+
|
60 |
+
def reshape_image_and_anno(image,mask,kps,bbox,size=512):
|
61 |
+
def move_kps(kps,move=None,ratio=None):
|
62 |
+
if move is not None:
|
63 |
+
for i in range(len(kps)):
|
64 |
+
if kps[i][2]!=-1:
|
65 |
+
kps[i][:2] += move
|
66 |
+
elif ratio is not None:
|
67 |
+
for i in range(len(kps)):
|
68 |
+
if kps[i][0]!=-1:
|
69 |
+
kps[i][:2] *= ratio
|
70 |
+
return kps
|
71 |
+
image = np.array(image)
|
72 |
+
mask = np.array(mask)
|
73 |
+
y1,x1,y2,x2 = bbox
|
74 |
+
image = image[x1:x2, y1:y2]
|
75 |
+
mask = mask[x1:x2,y1:y2]
|
76 |
+
kps = move_kps(kps,move=-np.array([y1,x1]))
|
77 |
+
|
78 |
+
#diff
|
79 |
+
dx = abs(x2-x1)
|
80 |
+
dy = abs(y2-y1)
|
81 |
+
dif = abs(dx-dy)
|
82 |
+
if dx>dy:
|
83 |
+
image = cv2.copyMakeBorder(image, 0, 0, int(dif//2), int(dif-dif//2), cv2.BORDER_CONSTANT, value=(255,255,255))
|
84 |
+
mask = cv2.copyMakeBorder(mask, 0, 0, int(dif//2), int(dif-dif//2), cv2.BORDER_CONSTANT, value=(255,255,255))
|
85 |
+
kps = move_kps(kps,move=np.array([int(dif//2),0]))
|
86 |
+
else:
|
87 |
+
image = cv2.copyMakeBorder(image, int(dif//2), int(dif-dif//2), 0, 0, cv2.BORDER_CONSTANT, value=(255,255,255))
|
88 |
+
mask = cv2.copyMakeBorder(mask, int(dif//2), int(dif-dif//2), 0, 0, cv2.BORDER_CONSTANT, value=(255,255,255))
|
89 |
+
kps = move_kps(kps,move=np.array([0,int(dif//2)]))
|
90 |
+
|
91 |
+
#ratio
|
92 |
+
ratio = size/max(dx,dy)
|
93 |
+
image = cv2.resize(image,(size,size))
|
94 |
+
mask = cv2.resize(mask,(size,size))
|
95 |
+
kps = move_kps(kps,ratio=ratio)
|
96 |
+
return image,mask,kps
|
97 |
+
|
98 |
+
"""
|
99 |
+
def __name__=='__main__':
|
100 |
+
image = Image.open("raw_image.jpeg").convert('RGB')
|
101 |
+
polygon,kps,bbox = readjson("annotation.json")
|
102 |
+
mask = polygon2seg(image,polygon)
|
103 |
+
# show_seg(image,mask)
|
104 |
+
# show_kps(image,kps)
|
105 |
+
|
106 |
+
size=512
|
107 |
+
nimage,nmask,nkps = reshape_image_and_anno(image,mask,kps,size)
|
108 |
+
show_seg(nimage,nmask)
|
109 |
+
show_kps(nimage,nkps)
|
110 |
+
|
111 |
+
|
112 |
+
"""
|