I've been searching for resources for number recognition in images on the web. I found many links providing lots of resources on that topic. But unfortunately it's more confusing than helping, I don't know where to start.
I've got an image with 5 numbers in it, non-disturbed (no captcha or something like this). The numbers are black on a white background, written in a standard font.
My first step was to separate the numbers. The algorithm I currently use is quite simple, it just checks if a column is entirely white and thus a space. Then it trims each character, so that there is no white border around it. This works quite well.
But now I'm stuck with the actual recognition of the number. I don't know what's the best way of guessing the correct one. I don't think directly comparing to the font is a good idea, because if the numbers only differ a little, it will no more work.
Could anyone give me a hint on how this is done?
It doesn't matter to the question, but I'll be implementing this in C# or Java. I found some libraries which would do the job, but I'd like to implement it myself, to learn something.
Why not look at using an open source OCR engine such as Tesseract?
http://code.google.com/p/tesseract-ocr/
C# Wrapper for Tesseract
http://www.pixel-technology.com/freeware/tessnet2/
Java Wrapper for Tesseract
http://sourceforge.net/projects/tessocrinjava/
While you might not consider using a third-party library as implementing it yourself, there's a tremendous amount of work that goes into just integrating the third-party tool. Keep in mind also that something that may seem simple (recognizing the number 5 versus the number 6) is often very complex; we're talking thousands and thousands of lines of code complex. In the least, look at the source code for tesseract and it'll give you a good reason to want to leverage a third-party library.
Here's another SO question that'll give you some ideas about the algorithms involved: https://stackoverflow.com/questions/850717/what-are-some-popular-ocr-algorithms
Related
This question already has answers here:
Best way to protect Excel VBA code?
(2 answers)
Closed 2 years ago.
I consider myself to be quite a competent Excel VBA programmer. Over a few years of my professional finance career I created quite a lot of useful procedures (UDF's, some small or big apps with multiple user-forms and a lot of small, easy to do stuff).
I decided that I will take a step forward and try to monetize my work. I have looked at VBA obfuscators, VBA compilers and stuff like that but sadly, the protection from obfuscators seems to be weak (at least I think so, I cannot comment as I know only VBA language, I am not master in computer science) or in case of compilators, compilation modifies my code so much, that 1/3 of it is not working properly (I have tried to debug it, but no matter what I do it does not work).
I checked the amount of code I have and it is about 13-14 thousand lines.
Now - is it worth or even possible for me to translate all that stuff into VB.NET or C# starting from scratch?
I have no experience with any of them, I have programmed only in VBA. I have been reading and it seems like it is nearly impossible to convert and re-write the code due to differences in user-forms, no UDF's, which I use in my subroutines and stuff like that. If it is possible, can someone point me in the right direction, what would be a better choice?
I am quite lost at the moment, as I have no experience and I know no developer who could "guide" me into this or that direction. What would be a good way to "translate" my VBA code and make a working app from it?
I know it is not easy, but if it will take me a few months of after-hours work, I will do it. The thing is that I do not want to completely waste the time and I want to do it right.
Thank you kindly for all ideas and your help. I hope my message is not completely off-topic.
It feels like an of topic question because it can't be factually answered; we can only give you our opinion for the most part. I'll pick out those parts that can be answered with facts:
Now - is it worth or even possible for me to translate all that stuff into VB.NET or C# starting from scratch?
Worth, I can't answer. Value is contextual - look at the number of people who get a kick out of providing stuff for free.
Possible; certainly. Your VBA code encapsulates a process, a notion, it does useful work and makes your life easier. It could make someone else's life easier too; would they pay you to make their life easier? Would they be able to integrate your work into theirs? Do you know how to make your work available to them in a way that means that they can actually use it?
You can put all this stuff into .NET, but don't think it makes it any harder to reverse engineer your work. If you want your stuff to be immune to reverse engineering, sell the data processing it does rather than selling the code. Create a webservice that calculates all the things people want, don't sell them a DLL that they could integrate and use but then their kid could decompile and release as a rival offering. That's not to say that this happens in business as much - businesses tend to be staffed with conscientious types that recognise when they license someone's work and use it, if they just ripped it and took it for free they would be stabbing one of their own in the back. If you're creating components for businesses to license and use, you'll probably have fewer piracy problems than shareware type licensing to end home users. But you can probably still sell the processing as a service rather than the software as a thing..
impossible to convert and re-write the code due to differences in user-forms, no UDF's, which I use in my subroutines and stuff like that
It might well be impossible to drop your code into something .netty, press play and have it working in an hour.. But I didn't think we were doing that. I thought we were re-implementing the process/software in .NET. Maybe whatever you pick doesn't have some blah UDF (user defined function?) this, or input box that - but at the end of it all, those things do some simple job and you can use something else in .NET that does that simple job. If anyone told me "seriously, there are things you can do in VBA that are flat out impossible in C#" I'd laugh for a while, then go back to playing javascript quake
14 thousand lines isn't an overbearing amount of code that you couldn't just sit down and start bashing it out in the evenings, and probably have reimplemented it all in something else in about a month - you already know what you want the code to do, so the hard part is getting info on how you do that in (your chosen language) - it's on topic for SO though, so fee free to search and ask how to translate various bits of VBA to C# etc.. People won't take kindly to questions that are a dump of 500 lines of VBA and a "can someone translate this to C# for me" though
By compact I mean one that doesn't require you to pull the entire 600+MB monster of a library with you if you only need some capture/cropping/resizing/thresholding/image arithmetic done. I know I could attempt writing that subset myself, but I don't want to reinvent the wheel. And while there are loads of OpenCV wrappers floating on NuGet, nearly all of those are bloated and/or bugged to some extent.
Ideally the subset of operations require should be determined at compile time. However, as far as I'm aware, C# compiler is unable to optimize away unused methods or classes, even under assumption of Reflection not being used. So no luck on that front, I guess.
For simple tasks like you described i would recommand using Accord.net Imaging library from NuGet http://accord-framework.net/docs/html/N_Accord_Imaging.htm,
very good performance and easy to use, also check out all of Imaging.* namespace http://accord-framework.net/docs/html/R_Project_Accord_NET.htm
Good luck!
Have you given Emgu.CV or OpenCVSharp a try? I've used them couple of years ago and they only took like 100/150 MB (the whole installation).
The final end result(your released app e.g) usually takes much less space since not everything is used. Usually one or two DLLs are used based on one's usage of course. In my case it was like 20+ MB or so. So there is nothing monstrous here to be afraid of!
I didn't like OpenCVSharp much, Emgu.CV looked much better and mature. I guess I was using Emgu.CV.3.2.0.2721. The latest version though is Emgu.CV.3.4.1.2976
I'm working on a personal project that involves finding the intersections of tubes (thin walled cylinders). It requires two main math computations I'm trying to find in a library or in sample code.
1) The minimum distance between two lines. (I've found code for this already)
2) The two corresponding points on the two lines that are each closest to the other line.
I've found plenty of sites with the math on how to do #2, but no sample code of anyone implementing it.
I am fully capable of writing this from scratch based on the math, but I'd much prefer saving several hours of coding, testing, and verifying by finding existing code I can incorporate in my C# app. Even if the sample is in another language, I can port things over to C# much faster than writing from scratch.
Since this is very much a "solved problem," I assume there has to be an open source library in some language already in existence, and re-inventing the wheel (and testing it and verifying it) would be a waste of time. (And, as we all know, any time we can spare from life for "personal projects" is a scarce and valuable commodity.)
There many open source library, if you familiar width javascript, you can try three.js, there is an implementation https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/CylinderGeometry.js
or you can find some ascriptscript library, like papervision3d
http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cylinder.as
Question:
I want code for: syntax highlighting (of programming languages)
Language: C# or assembly x86 (preferably C#)
Platform: Windows
Qualifications: most efficient implementation possible / most professional / the way that big corporations like Microsoft do it
Rephrased: How do I implement syntax highlighting in C# for Windows in the most efficient way presently known?
Elaboration (feel free to skip - not needed to answer question :)):
I don't want just any way of implementing it - I've already seen several.
What I'd like to know is how Microsoft does it so well on Visual Studio (whichever version).
People keep trying to reinvent the wheel when it comes to syntax highlighting. I don't understand why.
Is this considered a very hard problem? I've seen implementations that only highlight what's currently showing on the screen, I think that's the way to go... (it used some clever API to know which lines of a textbox were actually showing).
I've also seen implementations using RichTextBox and I think that's not the way to go (maybe I'm wrong here) - I think something like subclassing the routine that draws text on the regular textbox and changing its brushes might be better (maybe I've seen that somewhere - I doubt I'd think of that myself)
Also I've heard that some people implement it with AST just like a compiler would be coded (the lexer part, I think?) - I'd hope that that's overkill - I don't see that as being efficient. (uneducated guess)
If it's indeed a hard problem, then how do the big corps always get it right? I've never heard of a way to break the syntax highlighting in Visual Studio, for example.
But any other tool that implements it does so poorly, or worse than the big guys.
What's the official "this is the best way and any other way is less efficient" way of doing it?
I really don't have any evidence that Microsoft's way is better, but seeing that they probably know more about Windows API than anybody else, I'd guess that there way of implementing it is the best (I would love to be wrong - imagine being able to say that my implementation of syntax highlighting is better than MS's!)
Sorry for the disjointed elaboration.
Also I apologize in advance for any faux-pas - this is my first question.
I don't think there is a "this is the best way and any other way is less efficient" way to do it. In reality I don't think that efficiency is the major problem. Rather complexity is.
A good syntax highlighter is based on a good parser. As long as you can parse the code you can highlight every part of it in any way you like. But, what happens then when the code is not well-formed? A lot of syntax highlighter just highlight keywords and a few block structures to overcome this problem. By doing this, they can use simple regular expressions instead of having a full-fledged, syntax-error tolerant parser (which is what Visual Studio has).
The best way is probably to reuse something existing, such as ScintillaNET.
As with anything code.... there rarely is a "best" way. There are multiple ways of doing things and each of them have benefits and drawbacks.
That said, some form of the Interpreter Pattern is probably the most common way. According to the GoF book:
The Interpreter pattern is widely used
in compilers implemented with
object-oriented languages, as the
Smalltalk compilers are. SPECTalk
uses the pattern to interpret
descriptions of input file formats.
The QOCA constraint-solving toolkit
uses it to evaluate constraints.
It also goes on to talk about it's limitations in the applicability section
the grammer is simple. For complex grammars, the class hierarchy for the
grammer becomes large and unmanagable.
Tools such as parser generators are a
better alternative in such cases
effeciency is not a critical concern. The most efficient
interpreters are usually not
implemented by interpreting parse
trees directly but by first
translating them into another form.
For example, regular expressions are
often transformed into state machines.
But even then, the translator can be
implemented by the Interpreter
pattern, so the pattern is still
applicable.
Understanding this, you should now know why it's better to pre-compile your reusable RegEx first before performing many matches with it. If you don't, it will have to do both steps every time (transformation, interpretations) rather than building the state machine once, and applying it efficiently several times over.
Specifically for the type of interpretation you are describing, Microsoft exposes the Microsoft.VisualStudio namespace and all of it's powerful features as part of the Visual Studio SDK. You can also look at System.CodeDOM for dynamic code generation and compilation.
If you are able to embed a web page you could look at Prism.js
I've created a workflow/flowchart style designer for something. At the moment it is using relatively simple Bezier curve lines to connect up the various end points of the "blocks" on the workflow.
However I would like something a bit more intuitive for the user. I want the lines to avoid obstacles like other blocks (rectangles) and possibly other lines too.
I prefer the bezier splines rather than polylines because they are prettier and seem to fit in better with the designer in general. But am willing to compromise if they are much harder to accomplish.
I know there is a whole load of science behind this. I've looked into things like Graphviz, Microsoft's GLEE and their commericial AGL (automatic graph layout) library.
GLEE seems to barely be production worthy. And their commercial alternative is, well, a commercial alternative... it's quite expensive.
Graphviz doesn't seem to have been ported to .NET in any way.
I have seen a polyline implementation used by Windows Workflow Foundation for its "freeform designer". And this works, just, but it is not really of production grade appearance.
I'm surprised there isn't some plug'n'play .NET library for this type of thing? Something like:
Point[] RoutePolyline(Point begin, Point end, Rectangle[] rectObstacles, Point[] lineObstacles);
I haven't tried it (although I'm a happy customer of their Gantt product), but ILOG have a similar tool here.
To quote:
The ILOG Diagram for .NET algorithms
share generic goals such as:
Minimizing the number of overlapping
nodes
Minimizing the number of link
crossing
Minimizing the total area
of the drawing
Minimizing the number
of bends (in orthogonal drawings)
Maximizing the smallest angle formed
by consecutive incident links
Maximizing the display of symmetries
Supporting incremental layout,
partial layout, subgraphs,
intergraph links and nested layouts
Perhaps worth a look, at least.
Diagram.NET is a free, open source diagramming library in C#. It hasn't been updated in quite some time, but it's certainly worth a look - there may something there which you can reuse.
http://www.dalssoft.com/diagram/
Are you limited to managed code only?
I did not have this restriction and the past and effectively integrated GraphViz with .Net. What we did was call an external process containing the natively compiled "dot" and parse the result in a .Net object model. It worked perfectly and was fast enough for our needs.
I'm sure you could do better and easier with C++/CLI today.