• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating an CGAffineTransform From Sample Points
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating an CGAffineTransform From Sample Points


  • Subject: Re: Creating an CGAffineTransform From Sample Points
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 17 Feb 2008 22:54:46 -0800

On Feb 17, 2008, at 20:47, Bridger Maxwell wrote:

Hello, I have a few questions on CGAffineTransform. I would like to
construct one to represent a calibration from x y values from a camera to x
y values on a screen. If I were to take coordinate point pairs from each
space, (i.e. (x1,y1) = (x2,y2)), how man pairs of sample points would be
needed to create a CGAffineTransform matrix? I have read three, but I don't
know if this is correct. I would like to make a function that takes a few
coordinate point pairs from the input space and output space, and then makes
a CGAffineTransform from those. Does anyone know of an existing way to do
this? I have been searching around and can't find anything.

The math part isn't too hard. From the Quartz 2D programming guide:

x2 = a * x1 + c * y1 + tx
y2 = b * x1 + d * y1 + ty

and you're looking for a, b, c, d, tx and ty to put into the CGAffineTransform.

The easy way is to sample [i.e. find the screen coordinates for] the [camera] origin (x1 = 0, y1 = 0) and plug the numbers into these equations, and you'll be able to read off the values for tx and ty.

Then sample (x1 = something non-zero, y1 = 0) and plug those and tx and ty into the equations, and you'll be able to read off the values for a and b.

Then sample (x1 = 0, y1 = something else non-zero) and similarly read off the values for c and d.

It's a bit more work if you can't choose to sample these particular points. You still need 3 points, and they're going to give you a total of 6 linear equations in 6 variables (a, b, c, d, tx and ty). Solving those equations is not especially difficult, just messy and error- prone to write out by hand. You might want to find yourself a math library that does it for you.

All of this assumes that the transformation really is affine (no warping, no variation of the transformation in different parts of the image) and invertible.

Lastly, you have to make sure your calculations are numerically stable. Roughly, if any of a, b, c or d turn out to be very small or very large, the behavior of the CGAffineTransform across the entire range of image coordinates might be unsatisfactory.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Creating an CGAffineTransform From Sample Points
      • From: glenn andreas <email@hidden>
References: 
 >Creating an CGAffineTransform From Sample Points (From: "Bridger Maxwell" <email@hidden>)

  • Prev by Date: Line Spacing: NSTextField ~10% > NSTextView for same font
  • Next by Date: Re: How to detect focus on an NSTextField
  • Previous by thread: Creating an CGAffineTransform From Sample Points
  • Next by thread: Re: Creating an CGAffineTransform From Sample Points
  • Index(es):
    • Date
    • Thread