Store OCR quality metrics
ocrMetrics object stores optical character recognition
(OCR) quality metrics, consisting of the character and word error rates, for a set of images.
function returns the
Create an OCR quality metrics object by using the
DataSetMetrics — Data set metrics
Data set metrics, specified as a table with one row. The table contains OCR metrics
aggregated over the data set. The table contains one column for each metric specified by
Metrics name-value that correspond to the metrics of the
ImageMetrics — OCR metrics
table with N rows
OCR metrics, specified as a table with N rows, where
N is the number of images in the data set. The table contains one
column for each metric specified by the
Metrics name-value of the
function. Each image metric returns a vector with one element for each image in the data
set. The order of the rows matches the order of the images in the data set.
Evaluate Accuracy of OCR Model
This example shows how to evaluate the accuracy of an OCR model that can recognize seven-segment numerals on a dataset. The evaluation dataset contain images of energy meter displays that have seven-segment numerals in them.
Download and extract dataset.
datasetURL = "https://ssd.mathworks.com/supportfiles/vision/data/7SegmentImages.zip"; datasetZip = "7SegmentImages.zip"; if ~exist(datasetZip,"file") disp("Downloading evaluation dataset (" + datasetZip + " - 96 MB) ..."); websave(datasetZip,datasetURL); end datasetFiles = unzip(datasetZip);
Load the evaluation ground truth.
ld = load("7SegmentGtruth.mat"); gTruth = ld.gTruth;
Create datastores that contain images, bounding boxes and text labels from the
groundTruth object using the
ocrTrainingData function with the label and attribute names used during labeling.
labelName = "Text"; attributeName = "Digits"; [imds,boxds,txtds] = ocrTrainingData(gTruth,labelName,attributeName);
Combine the datastores.
cds = combine(imds,boxds,txtds);
Run OCR on the evaluation dataset.
results = ocr(cds, Model="seven-segment");
Evaluate the OCR results against the ground truth.
metrics = evaluateOCR(results,cds);
Evaluating ocr results ---------------------- * Selected metrics: character error rate, word error rate. * Processed 119 images. * Finalizing... Done. * Data set metrics: CharacterErrorRate WordErrorRate __________________ _____________ 0.082195 0.19958
Display accuracy of the OCR model.
modelAccuracy = 100*(1-metrics.DataSetMetrics.CharacterErrorRate); disp("Accuracy of the OCR model= " + modelAccuracy + "%")
Accuracy of the OCR model= 91.7805%
Error rates are a percentage of characters (words) in the input
groundTruthTxtthat have been incorrectly predicted in
To compute the number of incorrect predictions to use in the error rate calculation, the function uses the Levenshtein distance, which is defined as the minimum number of edits (such as insertions, deletions, or substitutions) required to change one word (or sentence) into another one.
Error rate = (S + D + I)/N where,
S — Number of substitutions
D — Number of of deletions
I — Number of insertions
N — Maximum number of characters (words) between
Introduced in R2023a