Expose marker data#53
Conversation
I was wanting something like this too. Might make sense to attach a projection matrix to each canvas returned by |
| } | ||
|
|
||
| export function sign(value) { | ||
| return value < 0 ? -1 : value > 0 ? 1 : 0; |
There was a problem hiding this comment.
Ah thanks, didn't know about that
janpaul123
left a comment
There was a problem hiding this comment.
Minor comment, looks good overall. Thanks for this! Let me know when I should merge this.
|
|
||
| let angle = Math.atan2(sideB.y, sideB.x) - Math.atan2(sideA.y, sideA.x); | ||
|
|
||
| if (sign(sideB.y) === -1 && sign(sideA.y) === 1) { |
There was a problem hiding this comment.
if(sideB.y < 0 && sideA.y > 0)?
- Don't assume all points which are not part of a shape are markers => otherwise paper points of partially covered corners will be exposed as markers - Save size of dots when calibrating page, bigger dots are recognized as markers
|
I need some help with transforming the point to local coordinates. I don't really understand how the matrix calculations work. I thought I could do it like this: const projectionMatrix = forwardProjectionMatrixForPoints(program.points)
const relativePosition = projectPoint(marker.position, projectionMatrix)Both marker.position and program.points are the original coordinates from detectProgram (value range between 0 and 1). I expected to get a transformed position relative to the top left of the paper (value range between 0 and 1) but this doesn't work. |
|
I learned about it mainly from the figure below in this paper, and experimented with it in this notebook:
The forward projection (case 1 above) maps unit-square coords to those inside the given quad corners. For example, it maps In context, if you take a local coord inside the paper's canvas, divide it by the canvas size, then project it with the result of This marker problem requires the inverse (case 2 above). Luckily, the paper describes that the inverse of a projection mapping is itself a projection mapping, and it can be created by taking the adjugate: const forward = forwardProjectionMatrixForPoints(program.points);
const inverse = forward.adjugate();
let relativePosition = projectPoint(marker.position, inverse);
relativePosition = mult(relativePosition, {x: canvas.width, y: canvas.height}); // rescaleAnd actually, you can avoid that rescaling part by multiplying it with a "canvas size" matrix, though I can never remember the right order (sorta like case 3 above). Example is here though: paperprograms/client/projector/Program.js Lines 179 to 181 in c4eeb5a |
|
@paulsonnentag would you like me to merge this PR and then follow up with local coordinates in a second PR (after you figure out the matrix stuff) or want to do it all at once? |
|
I would like to finish the local coordinates first and also update the documentation |
81948b0 to
ba5a830
Compare
Thanks to @shaunlebron for helping out with the transformation matrix
ba5a830 to
3b507b1
Compare
|
@janpaul123 ready to merge |
|
So cool. Can't wait to try this out soon! |

This pull request changes two things:
paperNumberproperty to markersI haven't implemented the local position conversion, because I realized that it's possible that a paper has multiple canvases with different sizes. I think it's better to have a utility function to convert global coordinates to local coordinates. I want to wait until #44 is merged which restructures
paper.jsto allow imports.