我已经开始在 Android Studio 中编写应用程序,并从这里下载了 Moverio SDK 和示例:https ://tech.moverio.epson.com/en/bt-35e/developers_guide/developing_android_apps.html#ac2-3-2
简而言之,我可以设置眼镜分辨率和文档中描述的所有其他内容:使用 SurfaceView 我可以在设备上看到来自眼镜相机的视频预览。
我需要做的是在加载带有 AR javascript 库的 html 页面的 WebView 中使用眼镜相机。
我尝试了一种简单的方法来使用 ionic 并且一切都很好,除了我无法设置相机分辨率..
这是我的代码,我希望有人可以帮助我。谢谢
//SetupActivity.java
package io.ionic.starter;
import android.os.Bundle;
import android.os.Handler;
import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.TextView;
import android.webkit.WebView;
import com.epson.moverio.hardware.camera.CameraDevice;
import com.epson.moverio.hardware.camera.CameraManager;
import com.epson.moverio.hardware.camera.CameraProperty;
import com.epson.moverio.hardware.camera.CaptureDataCallback;
import com.epson.moverio.hardware.camera.CaptureStateCallback;
import com.epson.moverio.util.PermissionHelper;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
public class SetupActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
private final String TAG = this.getClass().getSimpleName();
private CameraManager mCameraManager = null;
private CameraDevice mCameraDevice = null;
private SurfaceView mSurfaceView = null;
private PermissionHelper mPermissionHelper = null;
private TextView mTextView_captureRate = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mPermissionHelper = new PermissionHelper(this);
mCameraManager = new CameraManager(this);
}
private CaptureStateCallback mCaptureStateCallback = null;
private CaptureDataCallback mCaptureDataCallback = null;
private TimerTask mTimerTask = new TimerTask(){
@Override
public void run() {
mHandler.post( new Runnable() {
public void run() {
if(null != mTextView_captureRate) mTextView_captureRate.setText(String.valueOf(mFps) + "[fps]");
else ;
}
});
}
};
private Timer mTimer = null;
private Handler mHandler = new Handler();
private float mFps = 0;
private final Handler handler = new Handler();
@Override
protected void onStart() {
super.onStart();
mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
mTimer = new Timer(true);
mTimer.schedule( mTimerTask, 1000, 1000);
//mTextView_captureRate = (TextView) findViewById(R.id.textView_rate);
String launchUrl = "";
WebView Webv = null;
try {
mCaptureStateCallback = new CaptureStateCallback() {
@Override
public void onCaptureStarted() {
mCameraDevice.startPreview();
}
@Override
public void onCaptureStopped() {
}
@Override
public void onPreviewStarted() {
//setContentView(R.layout.activity_testo);
// Load and use views afterwards
}
@Override
public void onPreviewStopped() {
}
@Override
public void onRecordStarted() {
}
@Override
public void onRecordStopped() {
}
@Override
public void onPictureCompleted() {
}
};
mCameraDevice = mCameraManager.open(mCaptureStateCallback, null, mSurfaceView.getHolder());
CameraProperty property = mCameraDevice.getProperty();
property.setExposureMode(CameraProperty.EXPOSURE_MODE_MANUAL);
property.setExposureStep(5);
property.setCaptureSize(1920, 1080);
property.setCaptureFps(30);
mCameraDevice.setProperty(property);
//mCameraDevice.startCapture();
mCameraDevice.startCapture();
TextView sample = (TextView)findViewById(R.id.textView3);
if(null != mCameraDevice){
if(null != property){
String str = "";
str += "Size : " + property.getCaptureSize()[0] + "x" + property.getCaptureSize()[1] + " / " + property.getCaptureFps() + " [fps] ";
str += "Exposure : " + (property.getExposureMode().equals(CameraProperty.EXPOSURE_MODE_AUTO) ? property.getExposureMode() + "(" + property.getExposureStep() + ")" : property.getExposureStep()) + " ";
str += "Brightness : " + property.getBrightness() + " ";
str += "Sharpness : " + property.getSharpness() + " ";
//str += "Whitebalance : " + (property.getWhiteBalanceMode().equals(CameraProperty.WHITE_BALANCE_MODE_AUTO) ? property.getWhiteBalanceMode() + "(" + property.getWhiteBalanceTemperature() + ")" : property.getWhiteBalanceTemperature()) + "\n";
//str += "PowerLineFrequency : " + property.getPowerLineFrequencyControlMode() + "\n";
str += "CaptureDataFormat : " + property.getCaptureDataFormat() + "\n";
sample.setText(str);
}
else {
sample.setText("null");
}
}
//sample.setText("Hello");
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onRestart() {
super.onRestart();
if(null != mCameraDevice) {
mCameraDevice.stopCapture();
} else;
}
@Override
protected void onStop(){
super.onStop();
if(null != mCameraDevice) {
mCameraDevice.stopCapture();
} else ;
}
@Override
protected void onDestroy() {
super.onDestroy();
if(null != mCameraDevice) {
mCameraDevice.stopCapture();
mCameraManager.close(mCameraDevice);
} else;
mTimer.cancel();
mTimer = null;
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
mPermissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
这是xml
<!---activity_setup.xml-->
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SetupActivity">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="965dp"
android:layout_height="541dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.161" />
<TextView
android:id="@+id/textView3"
android:layout_width="943dp"
android:layout_height="75dp"
android:text="Prova"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.157"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>