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
This commit is contained in:
RKrom 2012-09-22 13:58:16 +00:00
commit 9553f840cb
6 changed files with 29 additions and 6 deletions

View file

@ -53,7 +53,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="LanguageKeys.cs" />
<Compile Include="ModiInterop.cs" />
<Compile Include="OCRConfiguration.cs" />
<Compile Include="OCRDestination.cs" />
<Compile Include="OCRPlugin.cs" />

View file

@ -37,6 +37,7 @@ namespace GreenshotOCR {
private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>();
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);
}
}

View file

@ -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 {
/// <param name="ImageOutputEventArgs">Has the Image and the capture details</param>
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;
}

View file

@ -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

View file

@ -12,6 +12,7 @@
<AssemblyName>GreenshotOCRCommand</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
@ -49,6 +50,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View file

@ -38,7 +38,7 @@ namespace GreenshotOCRCommand {
if ("-c".Equals(filename)) {
return 0;
}
modiDocument.Create(args[1]);
modiDocument.Create(filename);
modiDocument.OCR(language, orientimage, straightenImage);
IImage modiImage = modiDocument.Images[0];
ILayout layout = modiImage.Layout;