JotaBravo/spacecraft-uda

Any code to get Pose Estimation image?

Krysta1 opened this issue · 2 comments

Thanks for your nice work.
I have read your paper, but I could not find any code to generate Fig. 9 and Fig. 10 in this repo.
Could you please give me any hints? Thanks a lot.

Hi, sorry for the very late response.
``
The code is in MATLAB, and it is a bit ad-hoc to the keypoint structure we employ. If you use other keypoints, like the ones provided here you might need to change the code.

I've tried to simplify the code, because it uses many structures to automatically generate the code.

First of all, I rearranged the original keypoints to fit this "corners.mat" structure.

Next, for reach image, I obtain the image locations of the corners, based on the predicted (or ground-truth) quaternion and position.

corners1_im = world_to_image(corners1, data.cam, quat, pos);
corners2_im = world_to_image(corners2, data.cam, quat, pos);
corners3_im = world_to_image(corners3, data.cam, quat, pos);
corners4_im = world_to_image(corners4, data.cam, quat, pos);
corners5_im = world_to_image(corners5, data.cam, quat, pos);

where,

function [corners_im] = world_to_image(corners, cam ,quat, pos)
k  = cam.cameraMatrix;
dcm  = quat2dcm(quat);
pos_r  = dcm*pos;
corners_cam = dcm'*(corners+pos_r);
corners_im  = k*(corners_cam./corners_cam(3,:));
corners_im   = corners_im(1:2,:);
end

Finally, we plot it employing a imshow and overlaying lines of the corners


linestyle = '--';
linewidth= 5;
colorcode1 = '#64B5F6';
markersize = 8;


imshow(img)
hold on
plot(corners1_im(1,:),corners1_im(2,:),'Color',colorcode1,'LineStyle',linestyle,'LineWidth',linewidth,'Marker','o','MarkerFaceColor',colorcode1,'MarkerSize',markersize)
plot(corners2_im(1,:),corners2_im(2,:),'Color',colorcode1,'LineStyle',linestyle,'LineWidth',linewidth,'Marker','o','MarkerFaceColor',colorcode1,'MarkerSize',markersize)
plot(corners3_im(1,:),corners3_im(2,:),'Color',colorcode1,'LineStyle',linestyle,'LineWidth',linewidth,'Marker','o','MarkerFaceColor',colorcode1,'MarkerSize',markersize)
plot(corners4_im(1,:),corners4_im(2,:),'Color',colorcode1,'LineStyle',linestyle,'LineWidth',linewidth,'Marker','o','MarkerFaceColor',colorcode1,'MarkerSize',markersize)
plot(corners5_im(1,:),corners5_im(2,:),'Color',colorcode1,'LineStyle',linestyle,'LineWidth',linewidth,'Marker','o','MarkerFaceColor',colorcode1,'MarkerSize',markersize)

Hope it helps.

Btw, I'm planning to post a tutorial soon with some simple, base code for spacecraft pose estimation. I plan to include some easier to use code to plot images. So please stay tuned

Thank you very much for your response and share the code with me.