Page 1 of 1
Image to Text C#
Posted: 2016-04-02T14:09:44-07:00
by rlee1985
Is it possible to convert an image to a text document with magick.net? I can convert an image to text by using imagemagick IMDisplay and it outputs the image into a text file and looks like this:
# ImageMagick pixel enumeration: 1057,314,65535,srgb
0,0: (33410,1799,6939) #82071B srgb(130,7,27)
1,0: (33924,1285,6168) #840518 srgb(132,5,24)
2,0: (34438,1285,6425) #860519 srgb(134,5,25)
3,0: (34181,1028,6168) #850418 srgb(133,4,24)
4,0: (34181,1028,6168) #850418 srgb(133,4,24)
5,0: (34181,1028,5654) #850416 srgb(133,4,22)
6,0: (34181,1028,5654) #850416 srgb(133,4,22)
7,0: (34695,514,5397) #870215 srgb(135,2,21)
If this is possible are there any examples available?
Thanks,
Robert
Re: Image to Text C#
Posted: 2016-04-02T14:16:44-07:00
by snibgo
Just write the image to a "txt:" format output.
Re: Image to Text C#
Posted: 2016-04-02T14:53:27-07:00
by rlee1985
Just read the file using read?
using (MagickImage image = new MagickImage("Image.jpg"))
{
image.Write("NewText.txt");
}
I am getting an error message.
Re: Image to Text C#
Posted: 2016-04-02T14:54:58-07:00
by snibgo
Try:
image.Write("txt:NewText.txt");
Re: Image to Text C#
Posted: 2016-04-02T15:18:37-07:00
by rlee1985
Still does not work. That to me looks like it just renames the file and puts txt: on the front of it. I also added this:
image.Format = MagickFormat.Txt;
and it did not make any difference.
Re: Image to Text C#
Posted: 2016-04-02T15:19:23-07:00
by rlee1985
private void btnDecode_Click(object sender, EventArgs e)
{
using (MagickImage image = new MagickImage("image.png"))
{
image.Format = MagickFormat.Txt;
image.Write("NewText.txt");
}
}
just doing it on a button click.
Re: Image to Text C#
Posted: 2016-04-02T16:15:20-07:00
by snibgo
I don't use C# so I can't test it. Perhaps this isn't implemented in the C# interface. Sorry, I don't know what to suggest.
Re: Image to Text C#
Posted: 2016-04-02T16:21:38-07:00
by rlee1985
What do you use?
Re: Image to Text C#
Posted: 2016-04-02T16:45:08-07:00
by snibgo
I use the command-line interface, or C mostly at the MagickCore level but sometimes MagickWand.
For example, MagickCore:
Code: Select all
(void) strcpy(thumbnails->filename,argv[2]);
WriteImage(image_info,thumbnails);
This writes the text you want, when argv[2] is "x.txt" or "txt:x.txt".
Re: Image to Text C#
Posted: 2016-04-03T03:59:18-07:00
by dlemstra
Are you using the latest version of Magick.NET? I get a correct file with the following code:
Code: Select all
using (var image = new MagickImage("logo:"))
{
image.Write("logo.txt");
}
Re: Image to Text C#
Posted: 2016-04-03T10:16:28-07:00
by rlee1985
Awesome guys thanks for the help.
Re: Image to Text C#
Posted: 2016-04-03T12:05:05-07:00
by rlee1985
Dlemstra,
Would you have any idea as to why my program would crash as soon as I try to execute MagickImage code.
This is the process I followed:
Using visual studio 2013.
.Nets are installed up to 4.5.1.
Installed Magick.NET-Q16-x64.
In project set using ImageMagick;
Put this code in a button.
using (MagickImage image = new MagickImage(@"C:\Images\TestImage.jpg"))
{
image.Format = MagickFormat.Txt;
image.Write(@"C:\Images\TestImage.txt");
}
Then I get this error message:
Additional information: Could not load file or assembly 'Magick.NET-Q16-x64, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Then I installed this.
installed Magick.NET.Core-Q16.Native
I am still getting the same error.
Can you see anything that I am doing wrong?
Thanks,
Robert
Re: Image to Text C#
Posted: 2016-04-03T12:14:50-07:00
by rlee1985
Well I am lucky and it appears to be fixed!
I uninstalled both 64 core and native and used the anycpu and it works now.
THANKS FOR THE HELP!
Have a good one
Re: Image to Text C#
Posted: 2016-04-03T14:07:46-07:00
by dlemstra
It looks like your application is 32 bit. Your error messages means that you try to load a 64-bit library in a 32-bit application. Switching to AnyCPU fixed that. And you don't need to use the .NET Core version of Magick.NET.