How to overlay text or markers on an bmp image - c

I'm working with an image processing project where I'm trying to locate features on a .bmp image. I'm writing the whole source code in C.
The algorithm I'm developing is going to search for some features, if a desired feature was found by the algorithm then it is going to create a point (x co-ord, y co-ord), now I want to overlay this point on the image with a green or red DOT.
As of now its only a point, later on I wish to draw a box around a group of features- for example a face.
I don't know how to do this, I'm developing this in Linux (Ubuntu 9.04) environment, can anyone suggest what I should do?
Vikram

Take a look at ImageMagick as well. I've used it in the past with Perl, but it has a C interface as well.
ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

I would recommend using Cairo for your drawing. What you can do is load the image into an Image Surface, do your processing on the image surface using direct pixel access, and then use a Cairo context to draw what you need. The library also supports text using libpango, and Ubuntu loves the use of Cairo since GTK uses it. There are many tutorials for Cairo as well if you search around. The main site has some already.

Related

WPF blurry vector icons

I'm not able to get crisp icons in a WPF project. I've tried several solutions but the results are terrible when the icons are downscaled. The starting files are .ai (Illustrator) that I've exported to xaml code using Expression Design
Here is an example
blurry icons example
First of all, you can try to play with properties SnapsToDevicePixels and UseLayoutRounding.
Next, please check what coordinates your vector images use. In order to get the sharp lines, you must either move your coordinate system to (0.5, 0.5) or use half-integer coordinates (e.g. 0.5, 2.5, 11.5).
Please, have a look at this MSDN topic.
There is also a perfect article on this topic. It's in Russian, but you can try to use Google Translate for it.

OpenGL, Showing Text and getting values using C

This has been my problem since I started using openGL.
What code am I going to use to show text and get value. I could not use printf and scanf and my only header file is glut.h.
This has been my problem since I started using openGL.
What code am I going to use to show text
Difficult subject, because OpenGL itself doesn't deal with text output. You can:
render text to an image and display that
create a texture atlas from the glyphs of a font, then render from that font texture
draw the font glyph outlines as geometry
If you Google "OpenGL font rendering" you'll get a large number of results of papers on the topic. Recent and old ones alike.
and get value.
Not with OpenGL. OpenGL is a drawing API. You send it points, lines and triangles, and it draws nice pictures for you. User input is outside the scope of OpenGL. That's on part of the GUI system. Most likely one of
Windows GDI
MacOS Cocoa
X11
Standard user input event processing applies. Usually one uses a toolkit like Qt, GTK or similar. Those toolkits deal with user input processing through their event mechanism.
http://linux.die.net/man/3/glutstrokestring
How about this?
#include <openglut.h>
glutStrokeString(GLUT_STROKE_ROMAN, "I will draw this string at the origin of the model");

Saving xlib XImage to PNG

I am using xlib.
I have an XImage structure filled with information from an XGetImage() call. Is there a popular method to get from XImage to something more meaningful.. namely PNG?
I have looked at libpng, but have heard from pretty much everyone that it's a beast to tame. Would this still be the recommended path to take?
See also How to save XImage as bitmap? though that person had the constraint that they couldn't use a library.
If you can use a library, Cairo is a good one that will do this for you I believe. It has PNG saving dealing with the libpng mess for you, and it has code to get the pixels from X. However, it may make it hard to get pixels from an XImage; it will want to get them from a window or pixmap. If you can just replace your XGetImage() with cairo, then it might work fine. The way you would do things roughly in cairo I think is:
create an Xlib surface pointed at your drawable
save to PNG http://cairographics.org/manual/cairo-PNG-Support.html
You could also use the Xlib surface as source to draw to an image surface, and then do other stuff with the image surface (scale or paint on it or whatever) if you wanted, before saving as PNG.
If you're using any kind of UI toolkit, it probably has code for this too, e.g. GTK+ has gdk_pixbuf_get_from_drawable() etc.

Get path geometry from image

If i have a logo, let's say done as a jpg or even a png. Any suggestion for how I can use that to define a path geometry? It would be really good if any suggestions could be provided for how i can do it in blend.
Thanks
Yes - I just tackled this problem for an LOB application two days ago.
I can't offer advice for Blend (though I've read that it can be done in Expression Designer). However, the best free tool I've found for this is called InkScape (http://www.inkscape.org).
It's opensource, and while it's intended primarily for editing SVG vector-based images, it has two key features that are useful to us WPFers:
It can vectorize (i.e. "trace") raster images like bitmaps and jpegs, albeit not as well as one would hope, and
It can export the vector image as XAML
You'll invariably find that you get better results from loading vector formats (like SVG, EMF, WMF, etc) and saving to XAML, than if you try to convert a bitmap/jpeg... simply because the process of vectorizing a raster image is error prone at best. So if you want to bring a company logo into XAML, try to get hold of the source files used to create the logo (perhaps done in Illustrator?) and import that into InkScape.
If this post is helpful, please be kind and give it a one-up.
Jasema is a terrific tool right for the job.
Also, don't be shy to use Blend - it is somewhat more difficult to use (drawing shapes using pen) but it gets easier pretty fast. Switch on gridlines and optionally snap to them for good results.
What both Jasema and Blend are lacking, is the ability to easily create shapes with a central symmetry (like stars), so I took parts from Jasema and created my own tool (named Radius) that works a bit like a combination of a ruler and compass.
I have a good idea but you're png, bmp, jpg or other non vector file is must be very simple because we need best scan results and only use inkscape.
Step: Drag and drop your file workspace on Inkscape, download free.
Tip: If your image is color white, Top menu item File->Document Properties-> heck Checkerboard Background and if you want uncheck Page border show.
Step: Top menu item Path-> Trace Bitmap-> Mode check what you want property, i usually use color property and if your file is png check Remove Background then click OK, then wait again Ok button is Enable and close window.
Step: Now you have a two layer, top layer vektor file and bottom layer your file. Select vector file and top menu item Edit-> XML Editor-> select svg path and look side column, d name propery in your data path value.
But this method may not always work or may not give the desired results and draw your own shapes with the scape so you can get the path data from the XML editor.
Example, my first tests this like:
and after working on it some more:
I've solved my problem (export an image as XAML) using Microsoft Expression Design 4 (Free Version). I've downloaded from the link
http://www.microsoft.com/en-us/download/confirmation.aspx?id=36180
As input, I had Adobe Ilustrator files.
Adobe Illustrator / CorelDraw is perhaps the best tool out there for these operations that I have used.
Personally, I prefer illustrator for on-screen media. These tracings can be exported into several formats such as EPS, SVG, AI, or even XAML (with this plugin)
Best of Luck !!!!
I have recently been struggling with this myself. I had a set of icons done in data and needed to update them to look nicer.
I tried everything, manually typing them out. drawing in svg, converting svg to xaml.
in the end i found a list of open source icons from google material icons.
I then used this to convert from the svg files to data
https://github.com/BerndK/SvgToXaml
It works well but not for the icons i drew myself.
I decided to place all the icons data i convert into an app i built myself that will give you the data and a preview of the icon. feel free to use and contribute. I will keep updating as much as i can.
https://github.com/sgreaves1/XamlIcons
Convert your image from png to svg in online converter, then drop file into this site http://inloop.github.io/svg2android/ and you will see pathData of your image like below shown in my image.

How to embed a png in an Adobe Illustrator or Expression Design file to create XAML

I have an AI file. I paste it into Expression Blend and then export the XAML for use in my WPF project. Works for most of my files, but some export the XAML plus a seperate png file. What can I do so that the png is embedded into the paths of my image and not a seperate image? Can it be done?
Checkout this page that describes converting raster graphics to vector and then XAML -
http://weblogs.asp.net/rrobbins/archive/2007/11/11/how-to-convert-raster-graphics-to-xaml.aspx
Another route that you could try is to use Expression Design to convert the .ai file.
(Please note that once you have Expression Design open, you need to create a new document before the File->Import menu item is even enabled.)
However, once you convert the .ai file with Expression Design, you will likely still have the problem of having some raster information in the .ai ... which as Terrapin already mentions is hard to convert to vector (and usually brings a high memory footprint to get even close to the quality of the raster image).
But to help you out there, Expression Design also comes with some ability to convert raster information into vector. If you select the image that you want to convert, just go to Object->Image->Auto Trace Image in order to convert it.
See this StackOverflow question for more info, but basically Microsoft allows you to download a trial that you can use for 90 days.
Hope that helps.
It sounds like the PNG that is generated is probably the raster part of your AI file, and it can't be converted to vector graphics. Are you importing PNGs, or JPGs, or another raster graphic into your AI file?
To convert raster images to vectorial images, I found Inkscape (free) to do an excellent job (comparable to VectorMagic, which is not free anymore by the way).
In Inkscape, import your image and use the Path/Trace Bitmap function. It has a lot of control.
Once you converted to a vectorial image, save it as a SVG. Then, using ViewerSvg, you can convert to XAML vector data. (Path & Canvas)

Resources