美文网首页
百度人脸检测SDK-横屏无法检测问题

百度人脸检测SDK-横屏无法检测问题

作者: 天涯行空_78ce | 来源:发表于2019-02-27 10:07 被阅读0次

    首先吐槽下:公司人脸识别方案选了半天,发现百度的demo做的还是很全面的,只不过只支持竖屏,但是奈何实际需求是横屏用,折腾了好几天(其实就是百度了好几天),最终没找到解决办法,于是即将放弃之际,搜索了下setPreviewDegree这个方法,终于在简书上找到了一个大神的代码片段 如下https://www.jianshu.com/p/a0a39bacf5c6,试了试,终于可以喜上眉头了。

    进入正题:修改部分加粗 斜体吧

    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);

    }

    然后是 在FaceModule.java  的faceTrackerDecode方法中

    private FaceInfo[] faceTrackerDecode(byte[] imageData,int imageWidth,int imageHeight) {

    FaceInfo[] faces =null;

    if (mArgbData ==null ||

    (imageWidth * imageHeight) != (mImageWidth *mImageHeight)) {

    mArgbData =new int[imageWidth * imageHeight];

    mImageWidth = imageWidth;

    mImageHeight = imageHeight;

    }

    long startTime = System.nanoTime();

    if (FaceSDK.getAuthorityStatus() ==0) {

    FaceSDK.getARGBFromYUVimg(imageData,mArgbData,

    imageWidth, imageHeight,

    360 -mDegree,1);

    // rows=768-cols=432

                FaceTracker.ErrCode errorCode =mFaceTracker.faceVerification(

    mArgbData,

    imageWidth, imageHeight,

    FaceSDK.ImgType.ARGB,

    FaceTracker.ActionType.RECOGNIZE);

    mErrCode = errorCode.ordinal();

    faces =mFaceTracker.get_TrackedFaceInfo();

    long endingTime = System.nanoTime();

    Float fps =1000000000.0f / (endingTime - startTime +1);

    if (faces !=null && faces.length >0) {

    //                Log.e(TAG, "face decode fps " + fps + "-" + errorCode.name());

                    if (mErrCode == FaceTracker.ErrCode.OK.ordinal()) {

    mSaveFaceArgbData =mArgbData;

    }

    }else {

    //                Log.e(TAG, "face decode " + errorCode.name());

                }

    }

    return faces;

    }

    上面删除线的部分替换为

    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);

    就可以啦

    相关文章

      网友评论

          本文标题:百度人脸检测SDK-横屏无法检测问题

          本文链接:https://www.haomeiwen.com/subject/kcrxuqtx.html