私はiPhoneカメラアプリを書いています。ユーザーが写真を撮ろうとしているときに、iPhoneが揺れているかどうかを確認し、揺れがなくなるまで待ってから電話をキャプチャしたいと思います。
どうすればいいですか?
私はiPhoneカメラアプリを書いています。ユーザーが写真を撮ろうとしているときに、iPhoneが揺れているかどうかを確認し、揺れがなくなるまで待ってから電話をキャプチャしたいと思います。
どうすればいいですか?
Anit-shake 機能は非常に複雑な機能です。いくつかの強力なブレ検出/除去アルゴリズムと、iPhone のジャイロスコープの組み合わせだと思います。
iPhone で動きを検出する方法を調べることから始めて、それでどのような結果が得られるかを確認してください。それだけでは不十分な場合は、シフト/ぼかし方向検出アルゴリズムの調査を開始します。これは些細な問題ではありませんが、十分な時間があればおそらく達成できる問題です。それが役立つことを願っています!
// Ensures the shake is strong enough on at least two axes before declaring it a shake.
// "Strong enough" means "greater than a client-supplied threshold" in G's.
static BOOL L0AccelerationIsShaking(UIAcceleration* last, UIAcceleration* current, double threshold) {
double
deltaX = fabs(last.x - current.x),
deltaY = fabs(last.y - current.y),
deltaZ = fabs(last.z - current.z);
return
(deltaX > threshold && deltaY > threshold) ||
(deltaX > threshold && deltaZ > threshold) ||
(deltaY > threshold && deltaZ > threshold);
}
@interface L0AppDelegate : NSObject <UIApplicationDelegate> {
BOOL histeresisExcited;
UIAcceleration* lastAcceleration;
}
@property(retain) UIAcceleration* lastAcceleration;
@end
@implementation L0AppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[UIAccelerometer sharedAccelerometer].delegate = self;
}
- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
if (self.lastAcceleration) {
if (!histeresisExcited && L0AccelerationIsShaking(self.lastAcceleration, acceleration, 0.7)) {
histeresisExcited = YES;
/* SHAKE DETECTED. DO HERE WHAT YOU WANT. */
} else if (histeresisExcited && !L0AccelerationIsShaking(self.lastAcceleration, acceleration, 0.2)) {
histeresisExcited = NO;
}
}
self.lastAcceleration = acceleration;
}
// and proper @synthesize and -dealloc boilerplate code
@end
私はそれをグーグルで調べて、誰かがiPhoneを振ったときをどのように検出しますか?で見つけました。