Created
September 6, 2020 02:01
-
-
Save xximjasonxx/3215a61045a6bd892f9f0545b5d7326f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<OcrResult> AsResultList(this ImageAnalysis analysisResult, string fileId) | |
{ | |
var returnList = new List<OcrResult>(); | |
returnList.AddRange(analysisResult.Adult.AsOcrPairs(fileId, OcrType.ComputerVision)); | |
returnList.AddRange(analysisResult.Color.AsOcrPairs(fileId, OcrType.ComputerVision)); | |
returnList.AddRange(analysisResult.ImageType.AsOcrPairs(fileId, OcrType.ComputerVision)); | |
returnList.AddRange(analysisResult.Description.Captions.FirstOrDefault()?.AsOcrPairs(fileId, OcrType.ComputerVision)); | |
//returnList.AddRange(analysisResult.Brands.AsOcrPairs(fileId, OcrType.ComputerVision)); | |
//returnList.AddRange(analysisResult.Faces.AsOcrPairs(fileId, OcrType.ComputerVision)); | |
return returnList; | |
} | |
static IEnumerable<OcrResult> AsOcrPairs(this object obj, string fileId, OcrType ocrType) | |
{ | |
foreach (var propertyInfo in obj.GetType().GetProperties()) | |
{ | |
if (typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType) == false || propertyInfo.PropertyType == typeof(string)) | |
{ | |
yield return new OcrResult(fileId) | |
{ | |
KeyName = propertyInfo.Name, | |
OcrValue = propertyInfo.GetValue(obj).ToString(), | |
OcrType = ocrType | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment