41. 3A Developer User Guide¶
41.1. AFstatistical informationUsage Instructions¶
41.1.1. Overview¶
automaticfocusisthroughanalysisimage featureobtaintocurrentlyimageclearvalueFV(Focus Value), byinimagethe moreclearFVthe morelarge, becausethisthroughthroughratioforeachposition clearvaluecanfindoutputFVvaluecurve mostheightpoint, thispositionthat isisfocuspoint, findoutputfocuspointafterusepersonthenControlfocusmotortomostoptimalpositioncompleteautomaticfocus.
currentlyAFtotalprovidefourfilterandbrightnessmessageinformation, respectivelyishorizontaldirectionH1, H2, verticalhistogramtoV1, wherehorizontaldirectionwillfirstthroughthroughonelowpassfilterafteragainrespectivelythroughthroughtwoheightpassfilterusingobtaintoH1,H2 value, verticalhistogramtothenonlythroughthroughheightpassfilter,
currentlyAFonlysupportbayerdomain statistical information
41.1.2. Input Image Cropping¶
AFsupportforInput Image Cropping,
usercanthroughstCropin X, Y, W, HtodeterminescurrentlyAF systemstatisticalregion,
detailscanReference ISP_STATISTICS_CFG_S
usingobtainobtainrelatedstructureinformation
41.1.3. Bayer-Domain Configuration¶
numberdatainenterAFmodulebeforehavetwoformbeforeprocessingcanuse
usepersoncanselectwhetherneed tothroughthroughgamma, falsesuch asneed to words, needEnablegammaandenteradaptwhen gammacurve
usepersoncanselectwhetheropenenableprefilteringprocessingusingeliminatesalt-and-peppernoiseforsystemstatisticalvalue affects
41.1.4. Suppressing the Effect of Light Sources on FV Values¶
inimageintoolhavepointlight source case, infocusblurwhenwillbecauseislighthalodiffusionaffectstoFVvalue, andsendgenerateimageblurFVvaluebutincreaselarge condition, issuppressthiscurrentimage, increase u16HlCnt tosystemstatisticalwindowinheightbrightnesspoint values, usepersoncanAdjust u16HighLumaThtodeterminesheightbrightpoint threshold, whenblurwhenwindowin brightpointquantityincrease, clearwhenwindowin brightpointnumbermostless, usercanusethisinformationtodeterminemostadaptcombine focuspoint
41.1.5. Precautions for Statistical Information Configuration¶
type |
Description |
|---|---|
blocklargesmall |
maximum 7 * 15 |
systemstatisticalmoduleworkoperationdomain |
RAW |
Bayersystemstatisticalparameternumberwhetherreduceremoveblackelectricalflat |
alreadyreduceremove |
41.1.6. Obtaining FV Values¶
whenimage mostafteronepixelthroughafterthentakeobtainstatistical information,
usepersoncanthrough CVI_ISP_GetVDTimeOut usingsynchronousobtainobtainsystemstatisticalvalue,
canReference33.1.8 flow
41.1.7. Calculating FV Values¶
oneblockcantakeobtain systemstatisticalvaluehavethreekind, respectivelyis Horizontalfirstgroupfilterobtainto H0, Horizontalsecondgroupfilterobtainto H1, Vertical filterobtainto V0, wewilleachblock FVvaluenamednameisFVn, iseachsystemstatisticalvalueSetown weight, respectivelyisW0 / W1 / W2, thenFVn valueis
andmostfinal FVvaluealsoneed toiseachblock FVaddonweight, falsesetthenblock weightisWn, mostfinalFV valuethenis:
41.1.8. Reference Code for FV Calculation¶
ISP_AF_STATISTICS_S afStat;
CVI_U32 row, col;
CVI_S32 s32Ret = CVI_SUCCESS;
CVI_U64 stsValue = 0;
VI_PIPE ViPipe = 0;
ISP_VD_TYPE_E enIspVDType = ISP_VD_FE_START;
CVI_CHAR input[10];
ISP_STATISTICS_CFG_S stsCfg;
ISP_PUB_ATTR_S stPubAttr;
struct timeval t1, t2;
// AF weighting table
static int AFWeight[15][17] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
// Get current statistic and related size setting.
s32Ret = CVI_ISP_GetStatisticsConfig(ViPipe, &stsCfg);
s32Ret |= CVI_ISP_GetPubAttr(ViPipe, &stPubAttr);
if (s32Ret != CVI_SUCCESS) {
CVI_TRACE_LOG(CVI_DBG_ERR, "Get Statistic info fail with %#x!\n", s32Ret);
return s32Ret;
}
// Config AF Enable.
stsCfg.stFocusCfg.stConfig.bEnable = 1;
// Config low pass filter.
stsCfg.stFocusCfg.stConfig.u8HFltShift = 0;
stsCfg.stFocusCfg.stConfig.s8HVFltLpCoeff[0] = 0;
stsCfg.stFocusCfg.stConfig.s8HVFltLpCoeff[1] = 1;
stsCfg.stFocusCfg.stConfig.s8HVFltLpCoeff[2] = 2;
stsCfg.stFocusCfg.stConfig.s8HVFltLpCoeff[3] = 3;
stsCfg.stFocusCfg.stConfig.s8HVFltLpCoeff[4] = 4;
// Config gamma enable.
stsCfg.stFocusCfg.stConfig.stRawCfg.PreGammaEn = 0;
// Config pre NR enable.
stsCfg.stFocusCfg.stConfig.stPreFltCfg.PreFltEn = 1;
// Config H & V window.
stsCfg.stFocusCfg.stConfig.u16Hwnd = 17;
stsCfg.stFocusCfg.stConfig.u16Vwnd = 15;
// Config crop related setting. Has some limitation
stsCfg.stFocusCfg.stConfig.stCrop.bEnable = 1;
stsCfg.stFocusCfg.stConfig.stCrop.u16X = 8;
stsCfg.stFocusCfg.stConfig.stCrop.u16Y = 2;
stsCfg.stFocusCfg.stConfig.stCrop.u16W = stPubAttr.stWndRect.u32Width - 8 * 2;
stsCfg.stFocusCfg.stConfig.stCrop.u16H = stPubAttr.stWndRect.u32Height - 2 * 2;
// Config first horizontal high pass filter.
stsCfg.stFocusCfg.stHParam_FIR0.s8HFltHpCoeff[0] = 0;
stsCfg.stFocusCfg.stHParam_FIR0.s8HFltHpCoeff[1] = -3;
stsCfg.stFocusCfg.stHParam_FIR0.s8HFltHpCoeff[2] = 0;
stsCfg.stFocusCfg.stHParam_FIR0.s8HFltHpCoeff[3] = -10;
stsCfg.stFocusCfg.stHParam_FIR0.s8HFltHpCoeff[4] = 0;
// Config 2nd horizontal high pass filter.
stsCfg.stFocusCfg.stHParam_FIR1.s8HFltHpCoeff[0] = 0;
stsCfg.stFocusCfg.stHParam_FIR1.s8HFltHpCoeff[1] = -3;
stsCfg.stFocusCfg.stHParam_FIR1.s8HFltHpCoeff[2] = 0;
stsCfg.stFocusCfg.stHParam_FIR1.s8HFltHpCoeff[3] = -10;
stsCfg.stFocusCfg.stHParam_FIR1.s8HFltHpCoeff[4] = 0;
// Config vertical high pass filter.
stsCfg.stFocusCfg.stVParam_FIR.s8VFltHpCoeff[0] = 8;
stsCfg.stFocusCfg.stVParam_FIR.s8VFltHpCoeff[1] = -15;
stsCfg.stFocusCfg.stVParam_FIR.s8VFltHpCoeff[2 ] = 0;
stsCfg.unKey.bit1FEAfStat = 1;
s32Ret = CVI_ISP_SetStatisticsConfig(ViPipe, &stsCfg);
if (s32Ret != CVI_SUCCESS) {
CVI_TRACE_LOG(CVI_DBG_ERR, "ISP Set Statistic failed with %#x!\n", s32Ret);
return s32Ret;
}
printf("select. c -> Fv curve\n");
printf("........ h0 -> print h0 blocks statistic\n");
printf("........ h1 -> print h1 blocks statistic\n");
printf("........ v0 -> print v0 blocks statistic\n");
printf("........ hlc -> print hlcnt blocks statistic\n");
scanf("%s", input);
while(1) {
// Wait VD start for get focus statistic data.
s32Ret = CVI_ISP_GetVDTimeOut(ViPipe, enIspVDType, 5000);
s32Ret |= CVI_ISP_GetFocusStatistics(ViPipe, &afStat);
if (s32Ret != CVI_SUCCESS) {
CVI_TRACE_LOG(CVI_DBG_ERR, "Get Statistic failed with %#x\n", s32Ret);
return CVI_FAILURE;
}
// print each focus statistic.
if (strncmp(input, "c", 1) != 0) {
for (row = 0; row < AF_ZONE_ROW; row++) {
for (col = 0; col < AF_ZONE_COLUMN; col++) {
if (strncmp(input, "h0", 2) == 0) {
stsValue = afStat.stFEAFStat.stZoneMetrics[row][col].u64h0;
} else if (strncmp(input, "h1", 2) == 0) {
stsValue = afStat.stFEAFStat.stZoneMetrics[row][col].u64h1;
} else if (strncmp(input, "v0", 2) == 0) {
stsValue = afStat.stFEAFStat.stZoneMetrics[row][col].u32v0;
} else {
stsValue = afStat.stFEAFStat.stZoneMetrics[row][col].u16HlCnt;
}
printf("%d ", stsValue);
}
printf("\n");
}
continue;
}
CVI_U64 FVn = 0, FV = 0;
CVI_U32 totalWeightSum = 0;
// weight for each statistic
const CVI_U32 weight1 = 1, weight2 = 1, weight3 = 1;
const CVI_U32 blockWeightSum = weight1 + weight2 + weight3;
// calculate AF statistics
for (row = 0; row < AF_ZONE_ROW; row++) {
for (col = 0; col < AF_ZONE_COLUMN; col++) {
CVI_U64 h0 = afStat.stFEAFStat.stZoneMetrics[row][col].u64h0;
CVI_U64 h1 = afStat.stFEAFStat.stZoneMetrics[row][col].u64h1;
CVI_U32 v0 = afStat.stFEAFStat.stZoneMetrics[row][col].u32v0;
FVn = (weight1 * h0 + weight2 * h1 + weight3 * v0) / blockWeightSum;
FV += FVn * AFWeight[row][col];
totalWeightSum += AFWeight[row][col];
}
}
FV = FV / totalWeightSum;
}
return CVI_SUCCESS;