public void Apply(string inputPath, string outputPath, string intermediatePath, RGBThreshold thd, int tnum) { try { if (thd.upperBlueColorThd == thd.lowerBlueColorThd || thd.upperGreenColorThd == thd.lowerGreenColorThd || thd.upperRedColorThd == thd.lowerRedColorThd) Binarization.ApplyBradleyLocalThresholding(inputPath,outputPath); else Binarization.ApplyRGBColorThresholding(inputPath, outputPath, thd, tnum); } catch (Exception e) { Log.WriteLine("ExtractTextLayerFromMapWorker:" + e.Message); Log.WriteLine(e.Source); Log.WriteLine(e.StackTrace); throw; } }
public static string ApplyRGBColorThresholding(string inputPath, string outputPath, RGBThreshold thd, int tnum) { AForge.Imaging.Filters.BradleyLocalThresholding bradley = new AForge.Imaging.Filters.BradleyLocalThresholding(); _srcimg.Dispose(); _srcimg = null; _srcimg = new Bitmap(inputPath); _srcData = _srcimg.LockBits( new Rectangle(0, 0, _srcimg.Width, _srcimg.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); _dstimg = new bool[_srcimg.Height,_srcimg.Width]; try { Thread[] thread_array = new Thread[tnum]; for (int i = 0; i < tnum; i++) { thread_array[i] = new Thread(new ParameterizedThreadStart(Binarization.RunRGBColorThresholding)); thread_array[i].Start(i); } for (int i = 0; i < tnum; i++) thread_array[i].Join(); _srcimg.UnlockBits(_srcData); _srcimg.Dispose(); _srcimg = null; Bitmap img = ImageUtils.Array2DToBitmap(_dstimg); img.Save(outputPath); img.Dispose(); img = null; _dstimg = null; return outputPath; } catch (Exception e) { Log.WriteLine(e.Message); Log.WriteLine(e.Source); Log.WriteLine(e.StackTrace); throw; } }
public static void readConfigFile(string layer) { try { Log.WriteLine("Reading application settings..."); if (ReadString(layer + ":URL", "") != "") { layer += ":"; //setting found } else { layer = ""; //use the default setting } _rgbThreshold = new RGBThreshold(); _rgbThreshold.upperBlueColorThd = ReadInt(layer + "UpperBlueColorThreshold", 0); _rgbThreshold.upperRedColorThd = ReadInt(layer + "UpperRedColorThreshold", 0); _rgbThreshold.upperGreenColorThd = ReadInt(layer + "UpperGreeColorThreshold", 0); _rgbThreshold.lowerBlueColorThd = ReadInt(layer + "LowerBlueColorThreshold", 0); _rgbThreshold.lowerRedColorThd = ReadInt(layer + "LowerRedColorThreshold", 0); _rgbThreshold.lowerGreenColorThd = ReadInt(layer + "LowerGreenColorThreshold", 0); _numberOfSegmentationColor = ReadInt(layer + "NumberOfSegmentationColor", 0); _char_size = ReadInt(layer + "CharSize", 12); _language = ReadString(layer + "Language", "en"); _elasticsearch = ReadBool(layer + "Elasticsearch", false); _dictionaryFilePath = ReadString(layer + "DictionaryFilePath", ""); _dictionaryExactMatchStringLength = ReadInt(layer + "DictionaryTwoLetterFilePath", 2); _dictionaryWeightsPath = ReadString(layer + "DictionaryWeightsPath", ""); _sourceMapFileName = ReadString("SourceMapFileName", "SourceMapImage.png"); _textLayerOutputFileName = ReadString("TextLayerOutputFileName", "BinaryOutput.png"); _straboReleaseVersion = ReadString("Version", ""); } catch (Exception e) { Log.WriteLine(e.Message); Log.WriteLine(e.Source); Log.WriteLine(e.StackTrace); throw; } }
public static void readConfigFile(string layer) { try { Log.WriteLine("Reading application settings..."); if (ReadString(layer + ":URL", "") != "") layer += ":"; //setting found else layer = ""; //use the default setting _rgbThreshold = new RGBThreshold(); _rgbThreshold.upperBlueColorThd = ReadInt(layer + "UpperBlueColorThreshold", 0); _rgbThreshold.upperRedColorThd = ReadInt(layer + "UpperRedColorThreshold", 0); _rgbThreshold.upperGreenColorThd = ReadInt(layer + "UpperGreeColorThreshold", 0); _rgbThreshold.lowerBlueColorThd = ReadInt(layer + "LowerBlueColorThreshold", 0); _rgbThreshold.lowerRedColorThd = ReadInt(layer + "LowerRedColorThreshold", 0); _rgbThreshold.lowerGreenColorThd = ReadInt(layer + "LowerGreenColorThreshold", 0); _numberOfSegmentationColor = ReadInt(layer + "NumberOfSegmentationColor", 0); _char_size = ReadInt(layer + "CharSize", 12); _language = ReadString(layer + "Language", "en"); _elasticsearch = ReadBool(layer + "Elasticsearch", false); _dictionaryFilePath = ReadString(layer + "DictionaryFilePath", ""); _dictionaryExactMatchStringLength = ReadInt(layer + "DictionaryTwoLetterFilePath", 2); _dictionaryWeightsPath = ReadString(layer + "DictionaryWeightsPath", ""); _sourceMapFileName = ReadString("SourceMapFileName", "SourceMapImage.png"); _textLayerOutputFileName = ReadString("TextLayerOutputFileName", "BinaryOutput.png"); _straboReleaseVersion = ReadString("Version", ""); } catch(Exception e) { Log.WriteLine(e.Message); Log.WriteLine(e.Source); Log.WriteLine(e.StackTrace); throw; } }