Skip to content

Program data includes camera picture of program#38

Closed
maryrosecook wants to merge 1 commit intojanpaul123:masterfrom
maryrosecook:program-pictures
Closed

Program data includes camera picture of program#38
maryrosecook wants to merge 1 commit intojanpaul123:masterfrom
maryrosecook:program-pictures

Conversation

@maryrosecook
Copy link
Copy Markdown

  • Looking for help with handling rotated papers! It currently only handles unrotated papers.
  • The camera code stores picture data for each paper in the picture attribute of the program's entry in localStorage. (Alongside points and number.)
  • Paper programs written by users can access the picture for a program like this: papers[paperNumber].picture
  • Paper programs written by users can display a paper picture like this: ctx.putImageData(papers[paperNumber].picture, 0, 0).

* Only handles unrotated papers.
* The code for the camera browser window stores picture data for each paper in the `picture` attribute of the program's entry in localStorage. (Alongside `points` and `number`.)
* Paper programs written by users can access the picture for a program like this: `papers[paperNumber].picture`
* Paper programs written by users can display a paper picture like this: `ctx.putImageData(papers[paperNumber].picture, 0, 0)`.
@shaunlebron
Copy link
Copy Markdown
Contributor

For context, this is mary's demo video.

Thanks for doing this! I looked at this for a bit, and the method of cropping the ROI (region of interest) in OpenCV is restricted to an axis-aligned bounding box, so I'm guessing the picture of a rotated paper will always look something like this:

It might be easiest to provide users with a general utility function instead—to take a region from the camera image of the whole projection surface, and draw it to a target canvas context (paper or supporter):

drawFromCamera(
  ctx,       // canvas context to draw to
  srcRegion, // source coordinates from camera image of whole projection surface
  dstRegion  // destination coordinates to draw to
)
// NOTE: a "region" can be an array of 3 or 4 vertices (triangle or quad for now)

For example, the demo video could be achieved with something like:

const srcIds = [...]; // source animation papers
const dstId = ...; // draw animation to this paper

while (true) {
  for (let srcId of srcIds) {
    drawFromCamera(supporterCtx, papers[srcId].quadPoints, papers[dstId].quadPoints);
    supporterCtx.commit();
    await delay(250);
  }
}

For implementation, the hard work has already been done by patternPath, found in Three.js's canvas renderer. It seems to retrofit the simple canvas API with this arbitrary texture filling function that we need.

I'll try this out in an isolated environment to confirm if the implementation works as expected.

@maryrosecook
Copy link
Copy Markdown
Author

maryrosecook commented Apr 9, 2018

Sounds great! Definitely seems like a better approach. Thanks a lot!

@shaunlebron
Copy link
Copy Markdown
Contributor

Progress here. It looks like transforming triangles separately doesn't look good. So I'll try to copy the transform method used for each paper context to do proper perspective correction.

texture-transpose

@maryrosecook
Copy link
Copy Markdown
Author

maryrosecook commented Apr 10, 2018 via email

@shaunlebron
Copy link
Copy Markdown
Contributor

Works properly now. Will try to plug it in this weekend.

correct-transform

@janpaul123
Copy link
Copy Markdown
Owner

Very cool! Thanks both for your contributions. Looking forward to the final PR! 😄

@maryrosecook
Copy link
Copy Markdown
Author

maryrosecook commented Apr 11, 2018 via email

@shaunlebron shaunlebron mentioned this pull request Apr 13, 2018
@shaunlebron
Copy link
Copy Markdown
Contributor

Won't be able to get to it this weekend, so I left some breadcrumbs here: #41

@shaunlebron shaunlebron mentioned this pull request Apr 20, 2018
@janpaul123
Copy link
Copy Markdown
Owner

Superseded by #54. Thanks so much, very cool feature. 💯

@janpaul123 janpaul123 closed this Apr 29, 2018
@maryrosecook
Copy link
Copy Markdown
Author

So excited this feature is in PaperPrograms. Thanks so much for making it general purpose and high quality, @shaunlebron and @janpaul123 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants