babalae/better-genshin-impact · error · Exception

未识别的等级:{levelLine}

Error message

未识别的等级:{levelLine}

What it means

Thrown when a level line was found (157 passed) but int.TryParse fails OR the parsed value is outside [0, 20]. Genshin artifact levels are bounded 0-20, so out-of-range indicates an OCR/capture error rather than a real level.

Source

Thrown at BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs:735

        #endregion

        #region 等级
        string levelLine = levelAndMinorAffixLines.Select(l =>
        {
            string pattern = @"^\+(\d*)$";
            Match match = Regex.Match(l, pattern);
            if (match.Success)
            {
                return match.Groups[1].Value;
            }
            else
            {
                return null;
            }
        }).Where(l => l != null).Cast<string>().SingleOrDefault() ?? throw new Exception($"未找到等级对应的行:\n{levelAndMinorAffixLines}");
        if (!int.TryParse(levelLine, out int level) || level < 0 || level > 20)
        {
            throw new Exception($"未识别的等级:{levelLine}");
        }
        #endregion

        return new ArtifactStat(name, mainAffix, minorAffixes.ToArray(), level);
    }

    public static ArtifactStatus GetArtifactStatus(Mat src)
    {
        using Mat upperLine = new Mat(src, new Rect(0, 0, src.Width, (int)(src.Height * 0.19)));
        //using Mat hsvMat = upperLine.CvtColor(ColorConversionCodes.BGR2HSV_FULL);
        //var pixel_hsv_pink = hsvMat.At<Vec3b>(17, 12);    // 注意是(Y,X)
        //var pixel_hsv_grren = hsvMat.At<Vec3b>(8, 105);   // 注意是(Y,X)

        // 粉色锁
        Scalar pinkhsv = OpenCvCommonHelper.CommonHSV2OpenCVHSVFull(new Scalar(9, 0.54, 1.00));
        var lowPink = new Scalar(pinkhsv.Val0 - 3, pinkhsv.Val1 - 25, pinkhsv.Val2 - 25);
        var highPink = new Scalar(pinkhsv.Val0 + 3, pinkhsv.Val1 + 25, pinkhsv.Val2);
        using Mat pinkMask = OpenCvCommonHelper.InRangeHsvFull(upperLine, lowPink, highPink);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Log levelLine to inspect the misread value.
  2. Improve OCR preprocessing for the level region (threshold, scale).
  3. Tighten 157's selection so only the true level line is matched.
  4. Apply RecognitionFailurePolicy (Skip/Throw) consistently for out-of-range.
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidLevel(int level) => level >= 0 && level <= 20;

Prevention

When it happens

Trigger: OCR mis-read the level digits (e.g. '+2O' with a letter O); the matched line is not actually the level (false positive from 157's regex matching another '+N'); value exceeds 20 due to merged text.

Common situations: OCR confusion between digits and similar glyphs (0/O, 1/l); a non-level line matching '+\d+' leaked through; UI overlay text captured alongside the level.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/d5ad934bbe3a4ada. Report an issue: GitHub.