I try This Solution but Its Can't Able to Get All type of Math Equation From Image Source
private void GetEquation()
{
try
{
Regex imgRegex = new Regex(@"", RegexOptions.IgnoreCase);
MatchCollection imgMatches = imgRegex.Matches(ImageSting);
foreach (Match match in imgMatches)
{
string imgTag = match.Value;
string base64String = match.Groups[1].Value; // Extract the base64 string
// Convert Base64 image to math equation
string mathEquation = ConvertImageToMathEquation(base64String);
// Replace tag with extracted math equation
question = question.Replace(imgTag, $"");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public static string ConvertImageToMathEquation(string base64Image)
{
byte[] imageBytes = Convert.FromBase64String(base64Image);
// Save the image to a temporary file
string tempImagePath = Path.Combine(Path.GetTempPath(), "temp_math_image.png");
File.WriteAllBytes(tempImagePath, imageBytes);
// Use Tesseract to extract the equation
string tessdataPath = @"C:\Program Files\Tesseract-OCR\tessdata";
using (var engine = new TesseractEngine(tessdataPath, "eng+equ", EngineMode.Default))
{
engine.SetVariable("tessedit_char_whitelist", "0123456789+-=*/()"); // Restrict characters to math symbols
engine.DefaultPageSegMode = PageSegMode.SingleBlock; // Optimize for single equations
using (var img = Pix.LoadFromFile(tempImagePath))
{
using (var page = engine.Process(img))
{
string extractedText = page.GetText().Trim();
return string.IsNullOrEmpty(extractedText) ? "No equation detected" : extractedText;
}
}
}
}