提问人:eun_n 提问时间:7/23/2023 更新时间:7/23/2023 访问量:38
如果 cameraX 的 videoCapture 和 ImageAnlaysis 一起使用,预览会变得很奇怪。我该怎么办?& 如何在视频帧上绘图?
If cameraX's videoCapture and ImageAnlaysis are used together, the preview becomes strange. What should I do? & How can I draw on a video frame?
问:
- 当 cameraX 的 videoCapture 和 ImageAnlaysis 一起使用时,预览会旋转 90 度,图库中录制的视频会比实际长度长。为什么会这样?
private fun bindUseCase() {
if (cameraProvider == null) {
return
}
if (analysisUseCase != null) {
cameraProvider!!.unbind(analysisUseCase)
}
if (imageProcessor != null) {
imageProcessor!!.stop()
}
if (!PreferenceUtils.isCameraLiveViewportEnabled(this.context)) {
return
}
if (previewUseCase != null) {
cameraProvider!!.unbind(previewUseCase)
}
val previewBuilder = Preview.Builder()
previewUseCase = previewBuilder.build()
previewUseCase!!.setSurfaceProvider(previewView!!.surfaceProvider)
val recorder = Recorder.Builder()
.setQualitySelector(QualitySelector.from(Quality.HIGHEST))
.build()
videoCapture = VideoCapture.withOutput(recorder)
imageProcessor =
try {
Log.i(TAG, "Using Face Detector Processor")
val faceDetectorOptions = FaceDetectorOptions.Builder()
.setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_ALL)
.enableTracking()
.build()
FaceDetectorProcessor(this.context, faceDetectorOptions)
} catch (e: Exception) {
Log.e(TAG,"imageProcessor",e)
return
}
val builder = ImageAnalysis.Builder()
analysisUseCase = builder.build()
needUpdateGraphicOverlayImageSourceInfo = true
analysisUseCase?.setAnalyzer(
// imageProcessor.processImageProxy will use another thread to run the detection underneath,
// thus we can just runs the analyzer itself on main thread.
ContextCompat.getMainExecutor(this.context),
ImageAnalysis.Analyzer { imageProxy: ImageProxy ->
if (needUpdateGraphicOverlayImageSourceInfo) {
val isImageFlipped = lensFacing == CameraSelector.LENS_FACING_FRONT
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
if (rotationDegrees == 0 || rotationDegrees == 180) {
graphicOverlay!!.setImageSourceInfo(imageProxy.width, imageProxy.height, isImageFlipped)
} else {
graphicOverlay!!.setImageSourceInfo(imageProxy.height, imageProxy.width, isImageFlipped)
}
needUpdateGraphicOverlayImageSourceInfo = false
}
try {
imageProcessor!!.processImageProxy(imageProxy, graphicOverlay)
} catch (e: MlKitException) {
Log.e(TAG, "Failed to process image. Error: " + e.localizedMessage)
}
}
)
Log.d(TAG,"$cameraProvider, $cameraSelector, $analysisUseCase, $imageProcessor,$previewUseCase")
cameraProvider!!.bindToLifecycle(this, cameraSelector!!,analysisUseCase,videoCapture,previewUseCase)
}
如果从上面的代码中减去“analysisUseCase”,预览和录制时间就会正常出来。
2. 我想在视频帧上绘制人脸识别的结果。目前,它仅在预览中绘制,但我希望将结果记录在一起。我该怎么办?
答: 暂无答案
评论