From 9553f840cb964ac5d284a868a39882835833777b Mon Sep 17 00:00:00 2001 From: RKrom Date: Sat, 22 Sep 2012 13:58:16 +0000 Subject: [PATCH] Fixed OCR usages, now working for Windows 7 by using an additional exe. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2082 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj | 1 - Greenshot-OCR-Plugin/OCRDestination.cs | 6 +++++- Greenshot-OCR-Plugin/OCRPlugin.cs | 10 +++++++--- Greenshot/Greenshot.sln | 11 +++++++++++ GreenshotOCRCommand/GreenshotOCRCommand.csproj | 5 +++++ GreenshotOCRCommand/Program.cs | 2 +- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj b/Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj index 975155be9..633b5f33f 100644 --- a/Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj +++ b/Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj @@ -53,7 +53,6 @@ - diff --git a/Greenshot-OCR-Plugin/OCRDestination.cs b/Greenshot-OCR-Plugin/OCRDestination.cs index 5021cabc3..f33c7798c 100644 --- a/Greenshot-OCR-Plugin/OCRDestination.cs +++ b/Greenshot-OCR-Plugin/OCRDestination.cs @@ -37,6 +37,7 @@ namespace GreenshotOCR { private static OCRConfiguration config = IniConfig.GetIniSection(); private const int MIN_WIDTH = 130; private const int MIN_HEIGHT = 130; + private OcrPlugin plugin; public override string Designation { get { @@ -50,8 +51,11 @@ namespace GreenshotOCR { } } + public OCRDestination(OcrPlugin plugin) { + this.plugin = plugin; + } public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { - OcrPlugin.DoOCR(surface); + plugin.DoOCR(surface); return new ExportInformation(this.Designation, this.Description, true); } } diff --git a/Greenshot-OCR-Plugin/OCRPlugin.cs b/Greenshot-OCR-Plugin/OCRPlugin.cs index 83d6d6bbc..784b1918a 100644 --- a/Greenshot-OCR-Plugin/OCRPlugin.cs +++ b/Greenshot-OCR-Plugin/OCRPlugin.cs @@ -65,7 +65,7 @@ namespace GreenshotOCR { public class OcrPlugin : IGreenshotPlugin { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OcrPlugin)); private const string CONFIG_FILENAME = "ocr-config.properties"; - private const string OCR_COMMAND = "greenshotocrcommand.exe"; + private string OCR_COMMAND; private static IGreenshotHost host; private static OCRConfiguration config; private PluginAttribute myAttributes; @@ -92,6 +92,8 @@ namespace GreenshotOCR { LOG.Debug("Initialize called of " + myAttributes.Name); host = greenshotHost; this.myAttributes = myAttributes; + + OCR_COMMAND = Path.Combine(Path.GetDirectoryName(myAttributes.DllFile), "greenshotocrcommand.exe"); if (!HasMODI()) { LOG.Warn("No MODI found!"); @@ -154,7 +156,7 @@ namespace GreenshotOCR { private void StartOCRRegion() { LOG.Debug("Starting OCR!"); - host.CaptureRegion(false, new OCRDestination()); + host.CaptureRegion(false, new OCRDestination(this)); } private void MyHotkeyHandler() { @@ -176,7 +178,7 @@ namespace GreenshotOCR { /// Has the Image and the capture details private const int MIN_WIDTH = 130; private const int MIN_HEIGHT = 130; - public static void DoOCR(ISurface surface) { + public void DoOCR(ISurface surface) { string filePath = null; OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp); @@ -204,6 +206,7 @@ namespace GreenshotOCR { ProcessStartInfo processStartInfo = new ProcessStartInfo(OCR_COMMAND, "\"" + filePath + "\" " + config.Language + " " + config.Orientimage + " " + config.StraightenImage); processStartInfo.CreateNoWindow = true; processStartInfo.RedirectStandardOutput = true; + processStartInfo.UseShellExecute = false; Process process = Process.Start(processStartInfo); process.WaitForExit(30*1000); if (process.ExitCode == 0) { @@ -218,6 +221,7 @@ namespace GreenshotOCR { } } if (text == null || text.Trim().Length == 0) { + LOG.Info("No text returned"); return; } diff --git a/Greenshot/Greenshot.sln b/Greenshot/Greenshot.sln index 5a7636559..dec5907d1 100644 --- a/Greenshot/Greenshot.sln +++ b/Greenshot/Greenshot.sln @@ -17,6 +17,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Greenshot", "Greenshot.cspr {0A07500E-7404-48D7-8789-7EB2A23E0DD5} = {0A07500E-7404-48D7-8789-7EB2A23E0DD5} {19FEEF09-313F-43C7-819D-F1BCA782B08B} = {19FEEF09-313F-43C7-819D-F1BCA782B08B} {80D8DEB9-94E3-4876-8CCA-2DF1ED5F2C50} = {80D8DEB9-94E3-4876-8CCA-2DF1ED5F2C50} + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02} = {D61E6ECE-E0B6-4467-B492-F08A06BA8F02} EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotTest", "..\GreenshotTest\GreenshotTest.csproj", "{EFD01BC7-15E5-48AD-BE68-D7B62FEEED2D}" @@ -33,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotFlickrPlugin", ".. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotDropboxPlugin", "..\..\Greenshot-Plugins\GreenshotDropboxPlugin\GreenshotDropboxPlugin.csproj", "{AD7CFFE2-40E7-46CF-A172-D48CF7AE9A12}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotOCRCommand", "..\GreenshotOCRCommand\GreenshotOCRCommand.csproj", "{D61E6ECE-E0B6-4467-B492-F08A06BA8F02}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -129,5 +132,13 @@ Global {697CF066-9077-4F22-99D9-D989CCE7282B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {697CF066-9077-4F22-99D9-D989CCE7282B}.Release|Any CPU.Build.0 = Release|Any CPU {697CF066-9077-4F22-99D9-D989CCE7282B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Debug|Any CPU.Build.0 = Debug|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Debug|Any CPU.ActiveCfg = Debug|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Debug|x86.Build.0 = Debug|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Debug|x86.ActiveCfg = Debug|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Release|Any CPU.Build.0 = Release|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Release|Any CPU.ActiveCfg = Release|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Release|x86.Build.0 = Release|x86 + {D61E6ECE-E0B6-4467-B492-F08A06BA8F02}.Release|x86.ActiveCfg = Release|x86 EndGlobalSection EndGlobal diff --git a/GreenshotOCRCommand/GreenshotOCRCommand.csproj b/GreenshotOCRCommand/GreenshotOCRCommand.csproj index 846614509..2c4a8f277 100644 --- a/GreenshotOCRCommand/GreenshotOCRCommand.csproj +++ b/GreenshotOCRCommand/GreenshotOCRCommand.csproj @@ -12,6 +12,7 @@ GreenshotOCRCommand v2.0 512 + OnBuildSuccess x86 @@ -49,6 +50,10 @@ + + mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin" +