I am writing a c# program with emgucv library.
I use the imagebox in emgucv to capture image from webcam.
And I want to get the color pixel of the image by using bitmap.Getpixel() by mouse clicking the imagebox.
However,
it contain error The error is..it cannot implicitly convert type 'Emgu.CV.IImage' to 'System.Drawing.Bitmap'
Can anyone give me idea to solve this problem?
Bitmap bitmap = newdetectimageBox.Image; //error
Please use this code
Image<Bgr, Byte> ImageFrame = newdetectimageBox.Image ; //Capture the cam Image
Bitmap BmpInput = ImageFrame.ToBitmap(); //Convert the emgu Image to BitmapImage
Here's how you do it (image data is NOT shared with the bitmap) - see documentation on emgu website about IImage :
Bitmap bitmap = new Bitmap(newdetectimageBox.Image.Bitmap);
The IImage interface contains property Bitmap.
However if you are using the Image class than you should maybe use the ToBitmap method.
Related
I am making an windows form application in which i am overlaying an image during a webcam stream from the laptop.
the overlayed image is showing absurd colours. it is showing alot of pink colour. is there anything i can do to make the overlayed image look properly.
i am using the camera_Net Library to connect to the webcam
suggestions for overlaying an image during during a webcam video shall also be appreciated.
here is my code to draw the image
string filepath = #"E:\office\lux desktop app\Camera_Net-master\Camera_Net-master\Samples\CameraControlTool\water_PNG3290.png";
Bitmap bitmap1 = new Bitmap(filepath);
g.DrawImage(bitmap1, new Rectangle(400 , 0, 250, 600));
here is the look of the image during webcam stream
and here is the orignal image being overlayed
I think the problem is the image itself. It's an .png image, so I it has the possibility of an alpha-value. The white in the back is cropped out but in between the water, the light blue values are pink.
I would first try to use an easier image. Something like this. I think this will work just fine. Then search for some more complex images and try to find the weak-spot and find some alternative options to bring the image in to the cam.
As #Roman R pointed out that g point correctly to an incorrect background,
the problem was indeed with color format, so the solution is to use the correct image pixelformat based on your image.
here is the complete code
Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(bmp);
Image newImage;
newImage = Properties.Resources.red_frame_03;
using (Bitmap oldBmp = new Bitmap(newImage))
using (Bitmap newBmp = new Bitmap(oldBmp))
using (Bitmap targetBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), PixelFormat.Format16bppArgb1555))
{
g.DrawImage(targetBmp, new Rectangle(100, 0, 350, 350));
}
I am using emgu cv version 3. I try to load image to process. but it will provide error for me. According to the error it will say image cannot be read. But i have a image under that location.
This is my code line..
Image<Bgr, Byte> image = new Image<Bgr, Byte>("image.jpg");
Code line that you have provided is correct. Please check this with absolute path. It will be worked because if your image is not within your source directory your relative path (you have given only name of image that means your image is within your source directory) will not work. Its good to check with your absolute path. Like as follows
Image<Bgr, Byte> image = new Image<Bgr, Byte>(#"E:\Downloads\image.jpg");
Image "image.jpg" is within E:\Downloads location.
I have a image in picturebox. I want to get that image as a Bitmap.
My one line code is:
Bitmap default_image = (Bitmap)pictureBox5.Image.Clone();
But what i am getting is:
default_image value=null;
Can anyone help me.
Bitmap default_image = new Bitmap(pictureBox5.Image);
You are never instantiating a Bitmap which is why it is null.
If you got the image into the PictureBox by using imageLocation
pbSourceImage.ImageLocation = openFile.FileName;
then PictureBox.Image will be null.
Instead, load the picture using
pbSourceImage.Image = Image.FromFile(openFile.FileName);
Then you will be able to clone from the Image property.
This is because you do not have image, probably you have BackgroundImage.
You need to have Image properties fill with your picture.
I write a 48bppRgb to a file but when I create a bitmap from this file it is 32bppArgb(object img2 has a property PixelFormat.32bppArgb).
Minimized example:
Bitmap img1 = new Bitmap(100, 100, PixelFormat.Format48bppRgb);
img1.Save("/img1.bmp");
Bitmap img2 = new Bitmap("/img1.bmp");
Why?
More than one problem. You didn't save the image in the BMP format. The default format for Image.Save(string) is PNG. The PNG encoder built into GDI+ doesn't support 48bpp images. Saving as a BMP requires specifying the image format:
Bitmap img1 = new Bitmap(100, 100, PixelFormat.Format48bppRgb);
img1.Save("c:/temp/img1.bmp", ImageFormat.Bmp);
You'll however find that the BMP encoder doesn't support 48bpp images either, you'll get a 24bpp image when you load it back. None of the codecs supports 48bpp.
There's lots of missing functionality in GDI+. ImageFormat.Icon doesn't work for example, it actually saves a PNG. And support for any of the Indexed pixels formats is quite poor. If you need this kind of support then you'll need a professional imaging library. LeadTools or ImageMagick are the usual choices.
I have a WriteableBitmap which loads the bitmap image from file(mostly bmp). The bitmap files I am using have different pixel formats such as Indexed8, Bgra32, etc etc. The problem is that my code only works for bgra32 pixel format. So I need help in converting the bitmaps to Bgra32 pixel format in c# wpf.
Thanks
I have found the solution:
if (bmpSource.Format != PixelFormats.Bgra32)
bmpSource = new FormatConvertedBitmap(bmpSource, PixelFormats.Bgra32, null, 0);