当使用opencv为android在相机前面挥动手时的移动图像

时间:2013-11-07 00:37:49

标签: android opencv camera android-camera

我试图在我的应用程序中实现这样的功能 http://www.youtube.com/watch?v=QrXwJIco4w8

但似乎我真的不明白该怎么做..

似乎我必须使用运动跟踪和手部识别,也可以与前端摄像头进行通信,但大多数链接我发现只显示检测OUTSIDE对象而不是INSIDE对象(意味着设备内部)。

所以我想要的是如果在应用程序中有对象(如图像或任何东西),那么当我将手移到相机前面时,就像向左移动一样,那么图像位置也会向左移动。 使图像移动而不与触摸交互,而是使用相机(非接触式)

你能帮助我表明这样做吗?

感谢

1 个答案:

答案 0 :(得分:1)

我不知道相机,但我确实有另一个想法,使用波浪手势来改变图像等。 您可以在手机上使用接近传感器。但是你无法理解你是从左向右或从右向左移动你的手。所以,你可以这样:

在传感器上移动一次 - 从左到右 在传感器上移动两次 - 从右到左

您可以将接近传感器定义为:

public class ProximityNotifier implements SensorEventListener{

private final SensorManager mSensorManager;
private final Sensor mProximitySensor;
private final Sensor mAccelSensor;
private float mProximityMax = 0.0f;
private boolean mStartProxComparison;
public float mProximityValue = 0.0f;
private long lastBlockedTimestamp = 0;
private long gapPlayPause = 0;
private long gapNext = 0;
private static float mValue0 = 0.0f;
private static float mValue1 = 0.0f;
private ProximityNotifier.Callback cb = null;
private static final String TAG = "ProximityNotifier";

public ProximityNotifier(Context ctxt, ProximityNotifier.Callback cb, long gap1, long gap2) {

    this.cb = cb;
    this.gapPlayPause = gap1;
    this.gapNext = gap2;
    mSensorManager = (SensorManager)ctxt.getSystemService(Context.SENSOR_SERVICE);
    mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (null != mProximitySensor)
        mProximityMax = mProximitySensor.getMaximumRange();
    mProximityValue = mProximityMax;
    startProximityNotifier();
}



public interface Callback {
    void pageChange();        
}


public void startProximityNotifier() {
    if(null != mSensorManager) {
        if ((null != mProximitySensor) && (null != mAccelSensor)) {
            mSensorManager.registerListener(this, mProximitySensor, SensorManager.SENSOR_DELAY_UI);
            mSensorManager.registerListener(this, mAccelSensor, SensorManager.SENSOR_DELAY_UI);
            mStartProxComparison = true;
        }
        else
            mStartProxComparison = false;
    }
}

public void stopProximityNotifier() {
    if(null != mSensorManager) {
        if ((null != mProximitySensor) && (null != mAccelSensor)) {
            mSensorManager.unregisterListener(this, mProximitySensor);
            mSensorManager.unregisterListener(this, mAccelSensor);
        }
    }
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

public void onSensorChanged(SensorEvent sensorEvent) {

    if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mValue0 = sensorEvent.values[0];
        mValue1 = sensorEvent.values[1];
    }

    if ((sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY) &&  
            ((mValue0 < 2) && (mValue0 > -2)) &&
            ((mValue1 < 2) && (mValue1 > -2))) { 
        // check for a max -> 0 transition
        if((mStartProxComparison == true) && ((mProximityValue == mProximityMax) && (sensorEvent.values[0] == 0))) {
            lastBlockedTimestamp = SystemClock.uptimeMillis(); 
        } 

        else { 
            long now = SystemClock.uptimeMillis();
            if (lastBlockedTimestamp != 0) {
                /*if ((now - lastBlockedTimestamp) > gapPlayPause) {
                    if (cb != null) {
                        //cb.gesturePlayPause();
                    }
                }else*/ if ((now - lastBlockedTimestamp) > gapNext){
                    if (cb != null)
                        cb.pageChange();
                }
            }

            lastBlockedTimestamp = 0;
        }
        mProximityValue = sensorEvent.values[0];
    }

} 

}

在您的活动中,您可以声明并使用如下:

mProximityNotifier = new ProximityNotifier(this, this, 400, 200);

//Callback method for Proximity Sensor
    public void pageChange() {
        //call for image change
  }

希望它可以帮到你