| | import os |
| | import cv2 |
| | import numpy as np |
| | import open3d as o3d |
| | |
| | |
| |
|
| | os.environ['__GL_THREADED_OPTIMIZATIONS'] = '1' |
| |
|
| | cord_list = [] |
| | with open('./cord.txt', 'r') as f: |
| | lines = f.readlines() |
| | for line in lines: |
| | m = line.split() |
| | x = int(m[0]) |
| | y = int(m[1]) |
| |
|
| | x = 1000 - x |
| | y = 1000 - y |
| |
|
| | cord_list.append([x, y]) |
| |
|
| |
|
| | |
| | output_folder = '/media/gyalex/Data/face_det_dataset/rgbd_data/rgbd' |
| | if not os.path.exists(output_folder): |
| | os.mkdir(output_folder) |
| |
|
| | for idx in range(32, 33): |
| | txt_file_path = '/media/gyalex/Data/face_det_dataset/rgbd_data/PointImage'+ str(idx) + '.txt' |
| | _, name = os.path.split(txt_file_path) |
| | print(txt_file_path) |
| |
|
| | with open(txt_file_path, 'r') as file: |
| | points = [] |
| | rgb_list = [] |
| | ori_rgb_list = [] |
| | normal_list = [] |
| |
|
| | |
| | for line in file: |
| | |
| | x, y, z, r, g, b, nx, ny, nz, w = line.split() |
| | |
| | x = float(x) |
| | y = float(y) |
| | z = float(z) |
| | r = float(r) |
| | g = float(g) |
| | b = float(b) |
| | nx = float(nx) |
| | ny = float(ny) |
| | nz = float(nz) |
| | |
| | points.append((x, y, z)) |
| | rgb_list.append((r/255.0, g/255.0 , b/255.0)) |
| | normal_list.append((nx, ny, nz)) |
| |
|
| | ori_r = int(r) |
| | ori_g = int(g) |
| | ori_b = int(b) |
| | ori_rgb_list.append((ori_r, ori_g , ori_b)) |
| |
|
| | np_points = np.asarray(points) |
| |
|
| | np_points_a = np_points |
| |
|
| | np_colors = np.asarray(rgb_list) |
| | np_normals = np.asarray(normal_list) |
| |
|
| | np_colors_ori = np.asarray(ori_rgb_list) |
| |
|
| | pcd = o3d.geometry.PointCloud() |
| | pcd.points = o3d.utility.Vector3dVector(np_points) |
| | pcd.colors = o3d.utility.Vector3dVector(np_colors) |
| | pcd.normals = o3d.utility.Vector3dVector(np_normals) |
| |
|
| | map_dict = {} |
| | |
| | image = np.ones((1000, 1000, 3),dtype=np.uint8)*255 |
| | for i in range(np.array(pcd.points).shape[0]): |
| | x = np.array(pcd.points)[i,0]+400 |
| | y = np.array(pcd.points)[i,1]+400 |
| |
|
| | image[int(x),int(y),:] = (np.array(pcd.colors)[i,:]*255).astype(np.uint8) |
| | image[int(x+1),int(y),:] = (np.array(pcd.colors)[i,:]*255).astype(np.uint8) |
| | image[int(x),int(y+1),:] = (np.array(pcd.colors)[i,:]*255).astype(np.uint8) |
| | image[int(x-1),int(y),:] = (np.array(pcd.colors)[i,:]*255).astype(np.uint8) |
| | image[int(x),int(y-1),:] = (np.array(pcd.colors)[i,:]*255).astype(np.uint8) |
| |
|
| | map_dict[str(int(x)) + '_' + str(int(y))] = i |
| | map_dict[str(int(x+1)) + '_' + str(int(y))] = i |
| | map_dict[str(int(x)) + '_' + str(int(y+1))] = i |
| | map_dict[str(int(x-1)) + '_' + str(int(y))] = i |
| | map_dict[str(int(x)) + '_' + str(int(y-1))] = i |
| |
|
| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| |
|
| | h_list = [] |
| | for m in cord_list: |
| | a, b = m[0], m[1] |
| | c = image[int(b),int(a),:][0] |
| |
|
| | flag = False |
| |
|
| | if image[int(b),int(a),:][1] != 255: |
| | h_list.append(str(int(b))+'_'+str(int(a))) |
| | flag = True |
| | else: |
| | if image[int(b)-2,int(a)-2,:][1] != 255: |
| | h_list.append(str(int(b)-2)+'_'+str(int(a)-2)) |
| | flag = True |
| | elif image[int(b)+2,int(a)+2,:][1] != 255: |
| | h_list.append(str(int(b)+2)+'_'+str(int(a)+2)) |
| | flag = True |
| | elif image[int(b),int(a)-3,:][1] != 255: |
| | h_list.append(str(int(b))+'_'+str(int(a)-3)) |
| | flag = True |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | with open('pid.txt', 'w') as f: |
| | for h in h_list: |
| | pid = map_dict[h] |
| | s = str(pid) + '\n' |
| | f.write(s) |
| |
|
| | np_colors[pid,:] = np.array([0, 255, 0]) |
| |
|
| | f.close() |
| |
|
| | pcd0 = o3d.geometry.PointCloud() |
| | pcd0.points = o3d.utility.Vector3dVector(np_points) |
| | pcd0.colors = o3d.utility.Vector3dVector(np_colors) |
| | pcd0.normals = o3d.utility.Vector3dVector(np_normals) |
| |
|
| | o3d.io.write_point_cloud('aa.ply', pcd0) |
| |
|
| |
|
| | mm = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) |
| | image3 = cv2.flip(mm, -1) |
| |
|
| | |
| |
|
| | with open('./cord.txt', 'r') as f: |
| | lines = f.readlines() |
| | for line in lines: |
| | m = line.split() |
| | x = int(m[0]) |
| | y = int(m[1]) |
| |
|
| | x = 1000 - x |
| | y = 1000 - y |
| |
|
| | cv2.circle(image, (x,y), 2, (0, 255, 0), -1) |
| |
|
| | idx = map_dict[str(x)+'_'+str(y)] |
| |
|
| | a = 0 |
| |
|
| | |
| | |
| |
|
| |
|
| | |
| | |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |