Persiefxy / Projector-correction

Correction of projector projection images for multi-projector fusion
3 stars 1 forks source link

关于griddata的问题 #2

Open lsj1111 opened 6 months ago

lsj1111 commented 6 months ago

One-to-one matching of projector image plane coordinates and projected image pixel coordinates

def get_martix(pro_all, real_all, pro_size):

Determine how points in the image plane of the projector are projected into the projected image by interpolation

grid_x = np.linspace(0, pro_size[0]-1, pro_size[0])
grid_y = np.linspace(0, pro_size[1]-1, pro_size[1])
grid_x, grid_y = np.meshgrid(grid_x, grid_y)
points_to_remap = np.column_stack((grid_x.flatten(), grid_y.flatten()))
remapped_points = griddata(pro_all,real_all, points_to_remap, method='nearest')
mapx = np.zeros([pro_size[1], pro_size[0]], dtype=float)
mapy = np.zeros([pro_size[1], pro_size[0]], dtype=float)
for idx, num in enumerate(remapped_points):
     mapx[idx // pro_size[0]][idx % pro_size[0]] = num[0]
     mapy[idx // pro_size[0]][idx % pro_size[0]] = num[1]
 mapx = np.float32(mapx)
 mapy = np.float32(mapy)
return mapx, mapy

我对这个函数有几个问题: 我看您在对齐投影图像平面坐标和投影像素坐标的关系时,总共只使用了15个点(生成了15个Aruco码)来插值计算1280*720个值,经过插值之后结果全为nan,想问一下您是怎么解决的

Persiefxy commented 6 months ago

您好,存在nan值是正常的,因为输入的图像由于投影仪的角度问题势必发生畸变,对于如下的输入图像 pic

经过匹配和cv2.remap后,最终被投影的结果可能是 0

图中的黑色部分就是nan

At 2024-04-01 17:03:40, "lsj1111" @.***> wrote:

One-to-one matching of projector image plane coordinates and projected image pixel coordinates

def get_martix(pro_all, real_all, pro_size):

Determine how points in the image plane of the projector are projected into the projected image by interpolation

grid_x = np.linspace(0, pro_size[0]-1, pro_size[0]) grid_y = np.linspace(0, pro_size[1]-1, pro_size[1]) grid_x, grid_y = np.meshgrid(grid_x, grid_y) points_to_remap = np.column_stack((grid_x.flatten(), grid_y.flatten())) remapped_points = griddata(pro_all,real_all, points_to_remap, method='nearest') mapx = np.zeros([pro_size[1], pro_size[0]], dtype=float) mapy = np.zeros([pro_size[1], pro_size[0]], dtype=float) for idx, num in enumerate(remapped_points): mapx[idx // pro_size[0]][idx % pro_size[0]] = num[0] mapy[idx // pro_size[0]][idx % pro_size[0]] = num[1] mapx = np.float32(mapx) mapy = np.float32(mapy) return mapx, mapy 我对这个函数有几个问题: 我看您在对齐投影图像平面坐标和投影像素坐标的关系时,总共只使用了15个点(生成了15个Aruco码)来插值计算1280*720个值,经过插值之后结果全为nan,想问一下您是怎么解决的

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

lsj1111 commented 6 months ago

但是当我使用上述代码时插出来的全是nan,导致因为可用的点不足而报错。 Traceback (most recent call last): File "test.py", line 100, in martrix = matching_test(args.gray_folder, args.ph_coordinate, parameters, pro_size, cam_size) File "test.py", line 57, in matching_test map_x, map_y = relation(anchors, cmr_match_pjt, ph_coordinate, prosize, camsize) File "C:\Users\17196\Desktop\项目\Projector-correction-main\Projector-correction-main\method\match.py", line 143, in relation pro_all, real_all = predict_unknow(pro, real) File "C:\Users\17196\Desktop\项目\Projector-correction-main\Projector-correction-main\method\match.py", line 85, in predictunknow M, = cv2.findHomography(real_know, pro_know) # transformation matrix cv2.error: OpenCV(4.8.1) D:\a\opencv-python\opencv-python\opencv\modules\calib3d\src\fundam.cpp:385: error: (-28:Unknown error code -28) The input arrays should have at least 4 corresponding point sets to calculate Homography in function 'cv::findHomography'