我是靠谱客的博主 舒服板凳,最近开发中收集的这篇文章主要介绍对焦过程不拍照的实现---mtk,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

        之前用户经常有反馈手机拍照模糊,但我们自己根据用户的场景测试发现拍照并不会像用户说的那样拍照模糊,经过反复测试对比等,发现很可能是用户不太留意对焦的问题,拿出手机随机拍照,不会等对焦结束或者对焦清晰后再拍照.为了解决这个问题,想到让用户在对焦过程中不拍照,等对焦完成后再响应用户的拍照动作,因为对焦时间很短,所以并不会给用户感觉拍照有明显的延迟,但会明显减少用户拍照模糊的情况.通过查看代码和log,最终在camera app实现了这个功能,如下就是修改.


autofocus拍照时的判断:

    public void doSnap() {
        Log.i(TAG, "[doSnap]mInitialized =" + mInitialized + " mState=" + mState);
        if (!mInitialized) {
            return;
        }
        // M:
        if (!mListener.readyToCapture()) {
            Log.i(TAG, "[doSnap]readyToCapture is false,return.");
            // In Smile shot mode, enter smile shot processing state
            return;
        }
        // If the user has half-pressed the shutter and focus is completed, we
        // can take the photo right away. If the focus mode is infinity, we can
        // also take the photo.
        if (!needAutoFocusCall() || (mState == STATE_SUCCESS || mState == STATE_FAIL)) {
            capture();
        } else if (mState == STATE_FOCUSING || mAutoFocusMoving==true) {//added by maleijie 20151012 for focusing cap
            // Half pressing the shutter (i.e. the focus button event) will
            // already have requested AF for us, so just request capture on
            // focus here.
//added by ma 20151012 for focusing cap
Log.i(TAG, "[ma]mAutoFocusMoving =" + mAutoFocusMoving);
if(mAutoFocusMoving){ 
mIsNeedCap=mIsNeedCap+1;
if(mIsNeedCap>=2) {
Log.i(TAG, "[ma]mIsNeedCap >= 2,start capture..");
//mIsNeedCap=0; 
capture();
}
}

            else mState = STATE_FOCUSING_SNAP_ON_FINISH;
//mState = STATE_FOCUSING_SNAP_ON_FINISH;
//add end
        } else if (mState == STATE_IDLE) {
            // We didn't do focus. This can happen if the user press focus key
            // while the snapshot is still in progress. The user probably wants
            // the next snapshot as soon as possible, so we just do a snapshot
            // without focusing again.
            capture();
            
        }
    }

对焦时af move的回调:

    public void onAutoFocusMoving(boolean moving) {
        Log.i(TAG, "onAutoFocusMoving = " + moving);
        MMProfileManager.triggerContinueAutoFocus();
        // Ignore if the camera has detected some faces.
        if ((getFrameview() != null && getFrameview().faceExists())) {
            return;
        }
        
        // Ignore if we have requested autofocus. This method only handles
        // continuous autofocus.
        if (mState != STATE_IDLE && mState != STATE_UNKNOWN) {
            Log.i(TAG, "[onAutoFocusMoving]return,mState = " + mState);
            return;
        }
        
        // if current focus mode is INFINISTY, then don't show AF box
        if (Parameters.FOCUS_MODE_INFINITY.equals(getCurrentFocusMode(mContext))) {
            Log.i(TAG, "[onAutoFocusMoving]return,current focus mode is INFINISTY.");
            return;
        }
        mListener.setFocusParameters();
        if (moving) {
//added by ma 20151012 for focusing cap
mAutoFocusMoving=true;
//add end

            mFocusIndicatorRotateLayout.showStart();
        } else {
//added by ma 20151012 for focusing cap
mAutoFocusMoving=false;
if(mIsNeedCap==1) {
Log.i(TAG, "[ma]mIsNeedCap true,start capture..");
mIsNeedCap=0;
capture();
}else{
if(mIsNeedCap!=0){
Log.i(TAG, "[ma]mIsNeedCap "+mIsNeedCap+">=2,mAutoFocusMoving is false,cancel capture..");
mIsNeedCap=0;
}
}
//add end

            mFocusIndicatorRotateLayout.showSuccess(true);
        }
    }



touch af时,对焦不拍照:

  private void onShutterButtonClick() {
     boolean isEnoughSpace = mIFileSaver.isEnoughSpace();
     Log.i(TAG, "[onShutterButtonClick]isEnoughSpace = " + isEnoughSpace + ",mCameraClosed = "
              + mCameraClosed + ",mCurrentState = " + getModeState());
       // Do not take the picture if there is not enough storage.
       if (!isEnoughSpace || mCameraClosed || (ModeState.STATE_IDLE != getModeState() 
&& ModeState.STATE_FOCUSING != getModeState())) {
          Log.w(TAG, "[onShutterButtonClick]return.");//added by ma 20151012 for focusing cap
         return;
       }
       Log.i(TAG,
        "[CMCC Performance test][Camera][Camera] camera capture start ["
                     + System.currentTimeMillis() + "]");
       if (mIFocusManager != null) {
           mIFocusManager.focusAndCapture();
       }
 }

备注:

相机对焦过程不拍照的功能在识别到人脸后反复拍照出现不能拍照的情况:
本来马达动和不动都会上报消息给上层,但人脸识别的时候拍照,概率性马达不动的消息不会上报给上层,导致上层一直认为马达一直在动
按一般情况,马达动的时间很短.,用户在马达动的过程中,不会遇到两次拍照, 检测到两次在马达动的过程中拍照,就认为出现这个情况,这时就会马上拍照,此后每次点击都会拍照.

优化对焦框:---一个是对焦框大小,一个是对焦框动画播放时间, 主要考虑是,对焦动画干脆利落会对用户的体验很好,感觉对焦很快很准的感受.

packages / apps / Camera / src / com / android / camera / ui / FocusIndicatorRotateLayout.java



最后

以上就是舒服板凳为你收集整理的对焦过程不拍照的实现---mtk的全部内容,希望文章能够帮你解决对焦过程不拍照的实现---mtk所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部