作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的应用程序中实现
http://www.youtube.com/watch?v=QrXwJIco4w8
但似乎我真的不知道该怎么做。
似乎我必须使用运动跟踪和手识别,还必须与前端摄像头进行通信,但是大多数情况下,我发现仅显示检测外部对象而不是内部对象(意味着设备内部)的链接。
所以我想要的是,如果应用程序中有对象(例如图像或其他任何东西),那么当我将我的手移到摄像机前像向左移动时,图像位置也会向左移动。
使图像移动而不与触摸进行交互,而是使用相机(非触摸)
您能帮我示范一下吗?
谢谢
最佳答案
我不了解相机,但我确实有使用波浪手势更改图像等的另一种想法。
您可以在手机上使用接近传感器。但是它无法理解您是从左到右还是从右到左移动了手。因此,您可以拥有以下内容:
在传感器上移动一次-从左到右
在传感器上移动两次-从右到左
您可以定义接近传感器,如下所示:
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
}
关于android - 使用适用于Android的OpenCV在摄像机前挥手时移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19825815/
我是一名优秀的程序员,十分优秀!