android - 相机预览在后台 Android 上运行
问题描述
我有一个使用 Java 中的 Firebase ML kit Detector 检测眼睛的应用程序,但我希望相机预览在后台运行并检测眼睛的位置而不显示在我的屏幕上。
xml文件在下面提到。我已将可见性更改为不可见或消失,但没有成功。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible">
<com.example.eyetrackerdemo.CameraSourcePreview
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.eyetrackerdemo.GraphicOverlay
android:id="@+id/barcodeOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.example.eyetrackerdemo.CameraSourcePreview>
</LinearLayout>
你知道我应该遵循什么实现。此外,我想录制在后台运行的视频并将其保存在设备中。
解决方案
一种可能的方法是在布局中使用相机视图,但不在可见屏幕中使用。喜欢,
<LinearLayout
1...
2...
android:layout_height="match_parent"
3.<org.opencv.android.JavaCameraView
android:id="@+id/myCameraView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:show_fps="false" />
</LinearLayout>
注意第二个小部件中的android:layout_height="match_parent"。这使第二个小部件能够覆盖剩余屏幕,并且不会为相机视图提供任何空间。
推荐阅读
- matlab - 通过 COM 端口在 MATLAB 中获取十进制数据
- regex - 如果比较两列
- jquery - 如何在邮递员中自动读取 json 或 csv 文件
- azure - 如何通过 Azure CLI“导入应用服务证书”(不上传 PFX)
- rust - 使用 rust 的 openssl 库加密/解密大文本
- python - 如何在 Python 类中添加像 union 和 intersect 这样的集合理解?
- javascript - 在chartJS中使图例列表可滚动
- batch-file - 如果第一个文件名字符是数字,则 BAT 文件 Windows 解析
- ios - Swift iOS 13,使用移动网络时未获取 APNS 设备令牌(4g/3g)
- c++ - 用 C++ 打印直方图