Drawing a string that follows a path using GDI+ - c#

I've been scratching my head over this all day. I need to dynamically create an image that contains a string provided by the client. The only problem is, the string needs to be drawn along a curve like the image below. I would also like to specify the angle of the curve because this text needs to be displayed on a number of products, and the curve varies on each product.
I've attempted to loop through the string and display each character and give each one a specific coordinate to resemble a parabola, but in order for that to be useful, each character needs to be rotated to fit the curve. Does anyone have any suggestions from the System.Drawing library that may be of use to me?

I found this article on Code Project related to drawing text along a path in VB.NET - I'm sure a standard code converter could change this automatically to C# for you and it may solve your problem!
http://www.codeproject.com/Articles/13864/Text-on-Path-with-VB-NET

After doing a bit of research, it seems that WPF is the best route to take when generating warped text. A few google searches led me to this project. There is a minimal amount of XAML, and it's still written in C#. Credit goes to #lneir on codeproject for providing this remarkable bit of code. It's scalable, flexible, and wonderfully written, and the best part... no bezier curves.
I also mentioned that this text needs to be rendered on a dynamically created image. Turns out you can convert any WPF control to an image. Here's a link I found.
Thanks for the responses.

Related

Detect Object Defects with Open CV

I try to identify changes on an object. Therefore I take a picture before and after using the object. At the moment I'm working with the absolute Difference of the two pictures and taking the contours of the resulting difference image. That works fine as long as the object is positioned perfectly and captured like in the image before. Only small differences in its position make my method useless.
Has anybody a different solution approach with OpenCV oder EmguCV? I was thinking about checking if one of the neighbor pixels is identical then there should be no change detected, but I don't know of an existing performant algorithm.
Example Images (Pictures don't match my usecase, but they should be helpful to illustrate my problem):
Before
After
Yes there are many way to do this. I like the following:
Histogram match. Get a histogram before and after and check for differences. Is sensitive to changes in lighting. Very good method if you are in a controlled lighting setting
Correlation match. If you use MatchTemplate you can get the “quality” of the match. This can be made to be less sensitive to light. But is sensitive to rotation changes between the two images.
Try to implement some and let’s see your code.

Image map based on HSL or HSI values

I am trying to figure out a way to digitally map an image of a stained glass window. Between and around every piece of glass is a line of lead solder. What I'm thinking would be the best way to go about this would be to map the image based on the range of HSL or HSI values of the soldering material, such that each piece of glass would be its own zone, with its own information and click function.
I'm trying to make this a desktop application using C#, but could probably use html/javascript if that would be easier. I have been searching for some time to try and figure out a good way to accomplish this, but I'm having a hard time figuring it out.
Does anyone have any pointers on how I might go about doing this? I'm sorry if this question seems vague; if further clarification is needed, please comment on it and I will try to be clearer if necessary.
I don't have enough reputation to post a picture, but look at these for an idea:
http://rootsofknowledge.tc.uvu.edu/Gallery
I have had a little look, but don't want to do too much in case I am barking up the wrong tree!
I like to use ImageMagick, available for free with C/C++, Perl, PHP bindings and on the command line in most Linux distros. It is here.
I started with this image:
and tried a little blurring to make it less sensitive to tonal changes in the glass, followed by a Canny Edge detector and got this:
The command I used was this:
convert glass.jpg -blur 0x2 -canny 0x1+5%+10% edges.jpg
Obviously there is loads more to do, but it is maybe a start... and maybe others will add their expertise now we have a starting point....

Drawing Lines in WPF-Forms with crayon-shader?

we have a project at university where we have to create fractals that are controllable by the user (with kinect). We are still in an early phase where we evaluate some ideas (though we already got some working prototypes). Our idea right now is to use a blackboard-image as background and draw the fractals on top of it. To make this look more natural we'd like to use some crayon effects on the lines we draw.
Our internet-research produced two main ideas to achieve this:
Paint an image of a photoshop-like brush for every moueposition of a line.
Use shaders on drawline-functions.
The first does work for an early test, but looks awful. I guess the latter would be the best approach, but the information in the internet seems to be lacking regarding this topic. At least I didn't find anything that really helped a lot. The Questions is:
Has anyone links or general tips on how to achieve this effect, or is it not possible in C#/WPF. Might there be an even better way? And how can I apply a created shader to drawline-method/brushes?
Thanks in advance and kind regards
Michael
EDIT
Nice tip from #Bradley Uffner ! (unfortunately he deleted his answer)
There is a tutorial here on how to achieve such effect :
http://alastaira.wordpress.com/2013/11/01/hand-drawn-shaders-and-creating-tonal-art-maps/
Another thing I've found recently which might interests you :
http://blogs.msdn.com/b/hemipteran/archive/2014/03/26/generating-noise-for-applications.aspx
I've didn't read well the title of your question, Windows Forms do not support shaders at all.
Be more specific about the meaning of a crayon shader
Regarding using shaders in WPF, you cannot apply them at a line-level but on a Control level instead.
This the class representing a shader in WPF:
http://msdn.microsoft.com/en-us/library/system.windows.media.effects.effect(v=vs.110).aspx
What I suggest
use an Image and set its Source property to use a WriteableBitmap
use the excellent WriteableBitmapEx library to easily draw on it, basically it's the WriteableBitmap in WPF but with many extension methods for drawing lines, circles, rectangles etc ...
then apply your shader to the Effect property of Image
For developing your shader
Use Shazzam, it allows you to develop an HLSL shader for WPF in a cool interface, preview it instantly and it will generate the Effect class ready to paste on your project.
There might be a couple of interesting shader for you in DOSBox SVN-Daum
Here's an example of the cartoon shader :
Obviously there will be quite some work as copy-pasting the shader to Shazzam won't work right away but you'll know what are the maths behind achieving the effect.
Mark the answer as accepted if you are satisfied with it :D if not edit your question and add more details.

WPF/C#: WPF Path Maker Tool/Sample?

I am just wondering if it's possible to create a WPF application that allows users to use a certain pen to plot directions to make a certain path and able to display the path data.
The idea is almost the same with this one: http://blogs.msdn.com/b/gavingear/archive/2007/02/15/intoducing-pathmaker-a-tool-for-creating-path-markup-for-wpf-e.aspx
I also found a good sample where I can draw lines and stuff inside the canvas: http://www.codeproject.com/KB/WPF/WPF_DrawTools.aspx
I'm just looking for a good head start. Any suggestions?
Jesema is another one that might be helpful for you:
http://marlongrech.wordpress.com/jasema/
If you want something where you can draw stuff inside a canvas, there's livegeometry
http://livegeometry.codeplex.com/
but that one has the path data abstracted away (that's more similar to your draw tools example).
Hope those help!
I know this question is quite old, but I found that Inkscape supports save to XAML.
See this article: http://www.software-architects.com/devblog/2008/01/13/Graphic-In-XAML-And-WPF

Recognizing barcodes with AI

As a pet project/learning experience (no this is not homework) I'm working on software to recognize barcodes from a photograph. I'm not looking for software or a library that does it - instead I'm using this as a learning exercise that I'm blogging about and will post up on Codeplex.
I have code that successfully recognizes EAN13 barcodes (which I published on CodePlex) and UPC version A/E should follow shortly. I have two areas that I'm concerned about, though. First is in decoding barcodes that are in a picture that is bit blurry or with poor contrast, etc. Second is in simply finding the actual barcode in a larger picture (right now you have to give me a photo of just the barcode).
I have the gut feeling that some form of AI is going to help me out here. I played a bit in the past with genetic algorithms and I took a course ages ago on AI so it's not totally foreign to me, but I'm not quite sure where to start.
What type of algorithm is best suited to this type of problem? Any recommended reading or code for the AI grunt work? Yes, I want to understand what's happening, but I don't necessarily want to go down to the level of coding the sorts, etc myself.
I would suggest to search for properties that a barcode has. Some that I have in mind are:
Histogram of colors shows two distinct colors in about even distribution
Doing a hough transformation finds many parallel lines
The thickness of the lines have two distinct dimensions.
Some other?
Having this I would split the image into pieces and do a classification with these features then cobine the results to calculate a liklyhood if the piece contains an barcode or not.
For your second problem (blurry image) I would suggest to calculate the 1st order derivative of the grayvalues and then detect the edges of the lines in this space. The maximum of the derivative is lower if the image is blurred but it should be detectable to a certain blurring factor.
Does this help you?
As mp already noted you don't necessary need any real AI technique for it. Have a look at chapter 12 of Real World Haskell. It implements an almost complete barcode recognizer. Sample code is in Haskell, but there is plenty of explanation, so you can probably understand the ideas and tricks even without Haskell experience.
If you want to solve it with AI then the best bet is probably using ANNs. For the given problem I would recommend to use a quite advanced technique called HyperNEAT. See my explanation (and links) as the first answer to the SO question Neural Network Size...
I would probably use two or three different networks,
The first one to find the barcode on the bigger picture. One output neuron per pixel/set of pixels, output value is the confidence if that pixel seems to be a part of a barcode. Based on the result I would use some image transformation to convert it to a "standard" format (x*y rectangle)
If you have difficulties with finding the location of the barcode use a second one. Feed the result of the first one, and ask it to give the coordinates of two corners. However, I'm not quite sure that it will be very easy to evolve this one.
Last one would work on the standardized format, output neurons for each line (or square, if you work with a possibly 2D barcode), saying if the given area should be considered black or white.
Probably it would also help to do some pre-processing of the image, e.g. those that are described in RWH.
You don't need any specific AI or softcomputing technique. You need to apply image processing technique to improve the quality of the image or to isolate the barcode from a larger image.
You could use Matlab for prototyping and learnig more about image processing.

Categories