关于百度新版活体离线检测SDK无法横屏检测
FaceDetectActivity 中onPreviewFrame(byte[] data, Camera camera)
获得视频帧数据,mPreviewDegree为当前的横竖屏角度
```
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (mIsCompletion) {
return;
}
//saveImageBitmap(BitmapUtils.getYUVBitmap(data,camera));
Log.i(TAG,"data22222 = "+data+"----data.lenght="+data.length);
if (mIDetectStrategy ==null &&mFaceDetectRoundView !=null &&mFaceDetectRoundView.getRound() >0) {
mIDetectStrategy = FaceSDKManager.getInstance().getDetectStrategyModule();
//设置预览图片的旋转角度
mIDetectStrategy.setPreviewDegree(360-mPreviewDegree);
mIDetectStrategy.setDetectStrategySoundEnable(mIsEnableSound);
Rect detectRect = FaceDetectRoundView.getPreviewDetectRect(mDisplayWidth,mPreviewWidth , mPreviewHight);
mIDetectStrategy.setDetectStrategyConfig(mPreviewRect, detectRect, this);
}
if (mIDetectStrategy !=null) {
mIDetectStrategy.detectStrategy(data);
}
}
```
为了解决横屏无法检测问题,增加以下核心代码
在FaceModule.java 的faceTrackerDecode方法
,增加以下代码,横屏状态下,调换宽高
// 旋转了0度000000000000000000。高宽需要替换,横屏状态调换宽高
```
if (mDegree %180 ==0) {
int temp = imageWidth;
imageWidth = imageHeight;
imageHeight = temp;
}
==================================================
int argb = FaceSDK.getARGBFromYUVimg(imageData, mArgbData,
imageWidth, imageHeight,
mDegree, 0);
Log.i(TAG,"argb="+argb);
// 旋转了0度000000000000000000。高宽需要替换,横屏状态调换宽高
if (mDegree %180 ==0) {
int temp = imageWidth;
imageWidth = imageHeight;
imageHeight = temp;
}
// rows=768-cols=432
FaceTracker.ErrCode errorCode =mFaceTracker.faceVerification(
mArgbData,
imageWidth, imageHeight,
FaceSDK.ImgType.ARGB,
FaceTracker.ActionType.RECOGNIZE);
```
横屏检测ok,谢谢
觉得有用的话,就请小菜喝杯奶茶吧
网友评论