PDA

View Full Version : DFK 42BUC03 - PictureBox and SizeMode problem in C#



JamesP
March 28, 2014, 14:30:41
Hi, I'm programming in C# using OpenCVSharp wrapper and I have a problem with capturing properly the images from DFK 42BUC03 Camera.

When I used my programm with Plug&Play WebCam - all were OK, but after implementation of IC Imaging Camera some problems appeared.

I know that there's a secial library to download for MSVisual which gives icImagingControl, but I need to do all in PictureBoxes.

When I'm using PistureBoxes I can display live images from Camera but Properties like SizeMode.Zoom or StretchImage doesn't work.

Is there any idea how to solve this kind of problem?

I described it here too:

http://stackoverflow.com/questions/22696561/how-to-fit-image-to-picturebox

If anyone have any idea I would be grateful.

Stefan Geissler
March 28, 2014, 14:54:21
Hello

I must say

pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

works fine for me in


private void icImagingControl1_ImageAvailable(object sender, TIS.Imaging.ICImagingControl.ImageAvailableEventAr gs e)
{
try
{
TIS.Imaging.ImageBuffer ImgBuffer;
ImgBuffer = icImagingControl1.ImageActiveBuffer;
ImgBuffer.Lock();

pictureBox1.Image = ImgBuffer.Bitmap;


ImgBuffer.Unlock();


}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}

JamesP
March 28, 2014, 15:32:38
It's OK, but as I wrote I have to use only PictureBoxes, because I need IplImage from Camera and ICImageControl gives me BMP.
IplImage is an object which I can use to Camera calibration, circles recognition (HoughCircles Method) and these methods are implemented in OpenCVsharp.
That's why I can't use ICImageControl.

My method to view live from Camera:


private void onlineCAM()
{

while (true)
{
IplImage img = cap.QueryFrame();
img = img.Clone();

Bitmap bm = BitmapConverter.ToBitmap(img);

this.pictureBox3.Image = bm;
storage.Clear();
Thread.Sleep(50);
}

}

Stefan Geissler
March 28, 2014, 16:16:25
I am very sorry, I must have missed the IplImage part in your first post. I only saw Picturebox and resizing.

I would like to point you to ImageBuffer.GetImageData
http://www.imagingcontrol.com/en_US/support/documentation/dotnet/meth_descImageBuffer_GetImageData.htm
You can pass this pointer to your IplImage structure or, may be better you do a memcpy(). I did this in C++ only, not in C#, therefore, I do not know, how to do this in best way in C#

JamesP
March 28, 2014, 20:23:24
I have one more question. I saw that when I'm changing properties about image viewing in IC Capture 2.3 for my Industrial Camera I can see that these settings are saved in my PictureBox with image.
eg. When I change the resolution that another part of image is viewed in PictureBox but still not Streched.

Is there any setting in IC Capture 2.3 that can scale my image from camera, allow to resizing, or fit the image to the size of window (because when I'm changing form 1280x960 RGB32 to 640x480 RGB32 the image isn't fitted but just cropped)?

I think this kind of option could be help.

Stefan Geissler
March 31, 2014, 09:10:29
Hello James

If you use resolutions smaller than 2592x1944, then you will see a cropped (part) of the image only. This is intended. Since you already work with a picture box, you can use the System.Drawing.Graphics functions to resize your image to your needs.