Skip to content

Commit 119c06f

Browse files
ipa: rpi: controller: Autofocus CAF/PDAF stability tweak
When in Continuous AF mode using PDAF, only move the lens when phase has had the same sign for at least 4 frames. This reduces lens wobble in e.g. noisy conditions. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
1 parent d6c9705 commit 119c06f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ipa/rpi/controller/rpi/af.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ Af::Af(Controller *controller)
181181
ftarget_(-1.0),
182182
fsmooth_(-1.0),
183183
prevContrast_(0.0),
184+
prevPhase_(0.0),
184185
skipCount_(0),
185186
stepCount_(0),
186187
dropCount_(0),
188+
sameSignCount_(0),
187189
scanMaxContrast_(0.0),
188190
scanMinContrast_(1.0e9),
189191
scanData_(),
@@ -513,6 +515,13 @@ void Af::doAF(double contrast, double phase, double conf)
513515
return;
514516
}
515517

518+
/* Count frames for which PDAF phase has had same sign */
519+
if (phase * prevPhase_ <= 0.0)
520+
sameSignCount_ = 0;
521+
else
522+
sameSignCount_++;
523+
prevPhase_ = phase;
524+
516525
if (scanState_ == ScanState::Pdaf) {
517526
/*
518527
* Use PDAF closed-loop control whenever available, in both CAF
@@ -522,7 +531,8 @@ void Af::doAF(double contrast, double phase, double conf)
522531
* scan only after a number of frames with low PDAF confidence.
523532
*/
524533
if (conf > (dropCount_ ? 1.0 : 0.25) * cfg_.confEpsilon) {
525-
doPDAF(phase, conf);
534+
if (mode_ == AfModeAuto || sameSignCount_ >= 3)
535+
doPDAF(phase, conf);
526536
if (stepCount_ > 0)
527537
stepCount_--;
528538
else if (mode_ != AfModeContinuous)

src/ipa/rpi/controller/rpi/af.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ class Af : public AfAlgorithm
158158
bool initted_;
159159
double ftarget_, fsmooth_;
160160
double prevContrast_;
161+
double prevPhase_;
161162
unsigned skipCount_, stepCount_, dropCount_;
163+
unsigned sameSignCount_;
162164
unsigned scanMaxIndex_;
163165
double scanMaxContrast_, scanMinContrast_;
164166
std::vector<ScanRecord> scanData_;

0 commit comments

Comments
 (0)