1

I need to check if the phone is moving too fast while capturing a series of images ( like the panorama option in Google Camera).

I have tried this:

public void onSensorChanged(SensorEvent event) {
    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];

    //System.out.println("X: "+ x + ", Y: " +y);

    if (!mInitialized) {
        mLastX = x;
        mLastY = y;
        mLastZ = z;
        mInitialized = true;
    }else{
        float deltaX = Math.abs(mLastX - x);
        float deltaY = Math.abs(mLastY - y);
        float deltaZ = Math.abs(mLastZ - z);
        if (deltaX < NOISE) deltaX = (float)0.0;
        if (deltaY < NOISE) deltaY = (float)0.0;
        if (deltaZ < NOISE) deltaZ = (float)0.0;
        mLastX = x;
        mLastY = y;
        mLastZ = z;

        if (deltaX > deltaY) {
            //Log.e("TEST","HORIZONTAL "+deltaX + " :X, " +deltaY +" :Y");
            //horizontal
        } else if (deltaY > deltaX) {
            //vertical
           // didShake = true;
           //Log.e("TEST","TOO MUCH "+deltaX + " :X, " +deltaY +" :Y");
        } else {

        }
    }
}

Where NOISE is a threshold I keep experimenting with.

Now, this gets triggered only when there is a sudden jerk (Copied from a shake listener tutorial). This is not exactly what I want. If I move the phone too fast without a sudden jerk, then this does not get triggered.

I have gone through this:

finding speed of device movement

which led me to this:

http://maephv.blogspot.in/2011/10/android-computing-speed-and-distance.html

But this looks like its calculating speed of the device like GPS. I only need to detect if the phone is being waved around too fast.

Community
  • 1
  • 1
Nick Isaacs
  • 172
  • 11
  • How is "being waved around too fast" different than "a sudden jerk", practically speaking? – Doug Stevenson Feb 19 '16 at 07:13
  • Sudden jerks are also useful to me. Suppose I move the phone in a smooth motion without sudden acceleration but I move it too fast. I need to detect that. The speed at which the phone is being moved horizontally. – Nick Isaacs Feb 19 '16 at 08:54
  • You might want to be more specific in your problem description exactly what you're trying to capture with all these different kinds of movements. – Doug Stevenson Feb 19 '16 at 16:19
  • Ive already mentioned that. Very first line says I need some thing like in the panorama option of google camera. When the device moves too fast it shows a warning – Nick Isaacs Feb 19 '16 at 16:22
  • Well, panorama wants you to *be still* at various points to shoot accurately. You don't keep the camera moving much at all while it shoots. So it really sounds like you want to know the opposite -- not when the device is moving quickly, but when the device has been still for long enough to shoot confidently. So *any* movement, jerky or fast, is bad for this application, and it doesn't matter which one. – Doug Stevenson Feb 19 '16 at 17:11
  • Thats not the way google camera works. Once you start you move the phone sideways till u press stop. While moving if you go too fast, it tells you to slow down. I want to know how it detects that – Nick Isaacs Feb 19 '16 at 17:35
  • As far as I can tell, it's just stitching together individual photos at the points where you're asked to stop. It's not constantly "filming" as you move, but telling you where to position the camera so it can stitch effectively. So it's less interested in your speed at any given moment (though it will suggest that you slow down) but ultimately taking shots at preferred angles. – Doug Stevenson Feb 19 '16 at 21:06
  • I get that but it does track how fast the phone moves – Nick Isaacs Feb 19 '16 at 21:35
  • Not necessarily. It could merely track that the accelerometer is saying the the device is being moved faster than some threshold required for quality shots. Exactly how fast isn't the the issue. It's not giving you a readout of the exact speed of the device, just that it's "too fast". – Doug Stevenson Feb 20 '16 at 00:08
  • Thats exactly what im looking for! I dont need to use thr exact speed. Just something to flash a "too fast" warning – Nick Isaacs Feb 20 '16 at 04:23
  • Honestly, I'd just experiment with the values until it "feels" right for your needs. I needed something similar in another app and basically just did trial and error and lots of logging. It looks like you were already on that track with the code you showed, but I'd pay more attention to the instantaneous values rather than deltas. – Doug Stevenson Feb 20 '16 at 04:37

0 Answers0