Shane Da Silva
Shane Da Silva

Reputation: 268

Save pixel position on dynamically resized image

So here is the goal of my application: Using a webcam, the user will position to points on the video of themselves. Once positioned correctly that video will save out a jpg and the coordinated of those two points will be saved relative to the size of the image.

So this image and the image data associated with it will be used in multiple situations and also in different sizes. So my question is: what would be the best method to resize these images but also keep the points coordinates relevant and accurate?

Thanks all

Upvotes: 3

Views: 1115

Answers (1)

Mike Cialowicz
Mike Cialowicz

Reputation: 10030

Seems like you can just scale the point coordinates by the same amount that your image is scaled. If your original image is 100 x 100, your coordinate point is in the center at (50,50), and you scale your image by half, you just scale the x and y of your coordinate point by 0.5 also (your new point would be 25,25).

Here's a more complicated example:

  • Original image = 640x480
  • Coordinate point = (200,120)
  • Image scaled by 0.35
  • New image size = 640 * 0.35 x 480 * 0.35 = 224x168
  • New coordinate point = 200 * 0.35, 120 * 0.35 = (70,42)

Upvotes: 6

Related Questions