I wanna write on images using EmguCV in Windows Form C# In actual I wanna create a simple app for images as an image editor. Its simple purpose is to open images through an open file dialogue I can open the file but now I can't get any help or resource on How to write on images?. Let me explain my question through some image examples:
Image Before Editing:
Image after Editing:
So how can I do this using EmguCV in C#
I am newbie in dealing with images if there any way so kindly tell me.
And If there is not a such function involved in writing on images using EmguCV then please tell the alternative if any of you know??
Thanks in advance.
You can write on images with CvInvoke.PutText, one simple example is here:
// load the image
Mat image = new Mat("test.png");
// write "hello!" in red(0,0,255) at 100,100 coordinate from the top left corner
CvInvoke.PutText(image, "hello!", new System.Drawing.Point(100, 100), FontFace.HersheySimplex, 1.0, new MCvScalar(0, 0, 255), 2);
// display the result
CvInvoke.Imshow("Image with text", image);
// wait for user input to dismiss the image
CvInvoke.WaitKey();
// free allocated memory
image.Dispose();
Seems confusing for somebody new to EmguCV but it really is just a matter of looking at what each parameters do, more info in the EmguCV official documentation.
Related
I want colored portion of image to be placed at center of bitmap image. I was not able to find Aforge filters which can achieve this. Can you please guide how to achieve this(there will be only one color loop every time, like attached image). I have used Aforge through out project, but if EmguCV (OpenCV) can achieve this, I am open to use it.
I am able to achieve this using Aforge library, will provide link, code and result picture below.
Aforge documentation
// create filter
ExtractBiggestBlob filter = new ExtractBiggestBlob( );
// apply the filter
Bitmap biggestBlobsImage = filter.Apply( image );
Because I have only one blob, used filter which can output biggest blob. Now the colored portion occupies total image and it's center, becomes center of image.
I'm working on a project which generally is collecting data and drawing results in charts. (Using C#) I need to save my charts in a PDF file. My question is, how to save charts in a PDF file without loosing resolution? My point is how to draw vector graphics instead of raster graphics?
I tried iTextSharp to create PDF file but the result is not satisfying at all!
I'm new here, so I'm not able to upload pictures.
Here is the result after saving my file:
https://www.dropbox.com/s/ruwtc82hfosxk6y/Test.pdf?dl=0
Here is the PDF that I need to create:
https://www.dropbox.com/s/jvu5uu069imo9xc/nir%20well%20abfar.pdf?dl=0
There are two ways I know of to get high-quality images from your Chart into a PDF.
One is by using vector formats:
Use chart.SaveImage with one of the three emf formats.
Convert the resulting emf file to wmf
Insert the wmf file into your iTextSharp document.
1 and 3 are one-liners. But step 2 is not. In fact I haven't found a working c# solution at all. The best was a weird reference to an edit that has disappeared here ..
If you can use some other program to do the conversion you will get nice results like this demo pdf file.. I used Illustrator for the conversion.
Two: If you can't get step 2 to work, you can still get nice results, if you use raster images with a nice and high resolution. Here is how to do it:
First we hide the Chart, so we don't scare the user. Then we make it as large as we want the output to be. Then we DrawToBitmap and finally we reset the chart again..:
Size s = chart1.Size;
chart1.Hide();
// pick your size in pixels
// I simply multiply my screen size..:
chart1.Size = new System.Drawing.Size(s.Width * 5, s.Height * 5);
using (Bitmap bmp = new Bitmap(chart1.ClientSize.Width, chart1.ClientSize.Height))
{
// you should set the resolution,
// although I didn't find a way for iTextSharp to use it visually
bmp.SetResolution(600, 600);
using (Graphics G = Graphics.FromImage(bmp))
{
G.SmoothingMode = SmoothingMode.HighQuality;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
chart1.DrawToBitmap(bmp, chart1.ClientRectangle);
bmp.Save(yourImageFile, ImageFormat.Png);
}
}
chart1.Size = s;
chart1.Show();
You could also use SaveImage and save a few lines, but you can't set the resolution of the png file there and it will be saved at the currnt screen resolution, which is 96dpi here..
Now you have a large image and will probably have to scale it down in iTextSharp:
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(yourImageFile);
img .ScalePercent(15); // scale to fit your needs..
doc.Add(img );
Note that the legend and the labels get very small this way, so you may have to enlarge them before saving. I also found that, when scaling down, the image is rather bright until you zoom in..
Here are two screenshots, one from the chart, the other from the pdf documnet after zooming in a lot (300%)..:
I'm kind of a greenhorn to Windows Phone development and I've been looking for a way in order to crop an image already built into the project (Maybe even from the camera some day), but every package I've found has either had a fuss with Visual Studio, or throws argument exceptions. So I've decided that I will make my own function to do so.
However, I have not the slightest idea where to start. I'm pretty sure WriteableBitmap has something to do with it, and something to do with the following code:
Application.GetResourceStream(new Uri("/PhoneApp3;component/Assets/Flowers/Daff.jpg"));
So how would one start out with getting the pixel data or creating a new image and apply pixel data. And finally how would one save the result and reference it through the UI's image elements.
Use WriteableBitmapEx to crop images on Windows Phone. The way you solution will have to work is to manipulate the WritableBitmap.Pixels property. You first load in an image, change the Pixels property and transform the raw pixels into a saved image format like JPG or PNG. That's a lot of work so lucky for you WriteableBitmapEx does that for you.
First, install WritebleBitmapEx from NuGet:
Install-Package WriteableBitmapEx
Then you can load any image, crop it and save back to the MediaLibrary. Here's for example how to load a file from the app's XAP, crop to top-left 25% of the image and save to the "Saved Pictures" WP7/8 album.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var bmp = new WriteableBitmap(0, 0).FromContent("Assets/ApplicationIcon.png");
var croppedBmp = bmp.Crop(0, 0, bmp.PixelWidth/2, bmp.PixelHeight/2);
croppedBmp.SaveToMediaLibrary("myImage.jpg");
}
When we run this code we can see the new cropped image:
I recently needed to do this and didn't want to use an external lib. Microsoft provide a good example on MSDN on how to do it (and is also very good at not causing memory leaks!)
http://code.msdn.microsoft.com/wpapps/Photos-Sample-a38a2c8e
Cheers,
Will
I want to search for an image on screen using C# or other .NET languages(like powershell). Something like i give an image location in the file system and the code consider the whole screen as an image and search the image in the file system in the big image(the screen) then returns the image position on screen. I can't find this kind of things in the .net classes.
Thanks.
This is a pretty specific problem, which is why you won't find it in the .NET Framework. You should break down your problem in smaller pieces:
Load image from file on disk
Use System.Drawing.Image.FromFile().
Acquire an image of the screen, i.e. a screen shot
Use System.Drawing.Graphics.CopyFromScreen():
Bitmap CaptureScreen()
{
var image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
var gfx = Graphics.FromImage(image);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
return image;
}
Find image inside image
See answer to this question.
i have made a program which used a lib i coded in c# which will return the value of x and y of a small image inside a bigger image (screenshot) you can see all the details here https://www.nulled.io/topic/22223-an-advanced-image-search-library-saeedsearchdll/
I am working a mvc web app. I upload a image to use it as system logo. Now if I select image and upload it, it can be replaced easily until image file is not of large dimesion. For file with large dimension i need to reduce its size to some smaller size to make it look like a system logo. Preferable size for my logo is 100x75. How can I reduce the file dimesion?
THanks,
kapil
try this.
I found it in the msdn, and it works.
Bitmap map = new Bitmap(Image.FromFile("F:\\1.jpg"), new Size(20, 20));
map.Save("F:\\5.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
You can use the classes that are in the System.Drawing namespace.
See this tutorial for details.