Yes! It works!
First of all I looked through the generated permutations list and verified there was a valid points permutation generated. Then I took its index and verified that the solvePnP result and therefore the projectedPoints were valid as well! So that was just two small bugs in the code:
- My ‘isCloseTo’ function was only verifying the X point coord, but not Y (
x1);
- I was validating the projectedPoints with the original ones, but not with permutation I was solving PnP for (
x2).
After fixing this two issues everything worked!
Thank you so much for your help, again! Here is a small demo on how it looks. The Z axis (blue) is flipping sometimes because the marker is flat i.e. you can rotate it 180 deg along Y axis and it will still be the same shape.