I'm a bit late to the party, but I'm not sure if this has been addressed. Forgive me if it has. You'll need to check both width and height. Width a width of 960px, the subject could be 960x540 -- meaning 540p 16:9, or 960x720 -- meaning 720p 4:3.
So, common resolutions, detected in order:
Height <= 230 = N/A
Height <= 486 && Width < 640 = SD
Height <= 486 = 480i/p (SD)
(Height == 540 && Width >= 720) || (Height < 540 && Width == 960) = 540i/p (HRHD)
Height <= 576 = 576i/p (SD)
Width <= 1280 = 720i/p (HD)
Width > 1280 = 1080i/p (Full HD)
Only flaw I can think of is that this will detect cropped widescreen 576p as 480p, but I mean, why on Earth would anyone do that?
This will also accomodate those older 2.76:1 films. Although Abel Gance's Napoleon (4.00:1) is still out of luck. You could also throw in a couple of extra clauses for 2K and 4K resolution, if you want to be super cool.