TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Branden
NA
9
7.2k
OCR not reading images created from MemoryStream or Bitmap
Feb 9 2018 4:58 PM
I am using the IronOCR
to read an image to text, I ave also tried Tesseract and Tessnet to no avail. However, it is not reading the file created from my MemoryStream() or just Bitmap.Save in general.
The code below is funcitonal:
class
Screenshot
{
public
static
bool
saveToClipboard =
true
;
public
static
void
CaptureImage(
bool
showCursor, Size curSize, Point curPos, Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle,
string
FilePath,
string
extension)
{
using
(Bitmap bitmap =
new
Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
{
using
(Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
if
(showCursor)
{
Rectangle cursorBounds =
new
Rectangle(curPos, curSize);
Cursors.Default.Draw(g, cursorBounds);
}
}
using
(MemoryStream ms =
new
MemoryStream())
{
Image img = (Image)bitmap;
img.Save(ms, ImageFormat.Jpeg);
Bitmap bm =
new
Bitmap(ms);
Clipboard.SetImage(bm);
if
(!File.Exists(@
"C:\Users\Cowboy\Desktop\Images\mstemp.jpg"
))
{
img.Save(@
"C:\Users\Cowboy\Desktop\Images\mstemp.jpg"
);
}
else
{
File.Delete(@
"C:\Users\Cowboy\Desktop\Images\mstemp.jpg"
);
img.Save(@
"C:\Users\Cowboy\Desktop\Images\mstemp.jpg"
);
}
ms.Dispose();
}
}
}
}
}
IronOCR and tesseract will not read the images.
var ocr =
new
AutoOcr();
var result = ocr.Read(@
"C:\Users\Cowboy\Desktop\mstemp.jpg"
);
tbOCR.Text = result.GetType().ToString();
However, if IronOCR is able to read screenshot created by other applications like green shot, light shot, and print screen (a MS built in function), then the code I am using is in fact excluding some important raw data that would otherwise prevent the IronOCR functionality from doing its job. Nothing is wrong with IronOCR, its how the raw data stream/bitmap of my images are preventing the programs like IronOCR or Tesseract from reading my screenshots.
Reply
Answers (
1
)
Regarding data managment
Methods C Sharp