PDA

View Full Version : How to store the image data in one dimension



zihui_w
October 5, 2005, 06:26:52
I am new to use IC ImageControl.

Any one know how to store the image data in one dimension or to convert the imagebuffer data to an one dimension data array in vb.net

The sample code is using 2 dimension array for data processing. I want to use one dimension data.

Private Sub IcImagingControl1_ImageAvailable1(ByVal sender As Object, ByVal e As TIS.Imaging.ICImagingControl.ImageAvailableEventAr gs) Handles IcImagingControl1.ImageAvailable
Dim CurrentBuffer As TIS.Imaging.ImageBuffer
Dim x, y As Integer
Dim BytesPerLine As Integer
Dim i As Integer
Dim img_buff() As Byte

Cursor = Cursors.WaitCursor
CurrentBuffer = IcImagingControl1.ImageBuffers(e.bufferIndex)

BytesPerLine = CurrentBuffer.BitsPerPixel / 8 * CurrentBuffer.PixelPerLine
img_size = CurrentBuffer.Lines * BytesPerLine

ReDim img_buff(img_size)

' Calculate the count of bytes ber line using the color format and the
' pixels per line of the image buffer.
BytesPerLine = CurrentBuffer.BitsPerPixel / 8 * CurrentBuffer.PixelPerLine - 1
For y = 0 To CurrentBuffer.Lines - 1
For x = 0 To BytesPerLine
img_buff(y * BytesPerLine + x) = CurrentBuffer(x, y)
Next x
Next y

end sub

Stefan Geissler
October 5, 2005, 09:15:03
Hello Zihui,

The IC Imaging Control ActiveX and .NET component only provide image data in two dimensional arrays. There are two ways to handle this as one dimensional array:
1.) Write a function, that convertes the one dimensional index in a two dimensional index, that returns one byte.
2.) Copy the image data array into a one dimensional array.

At least you can get a pointer to the image with the method ImageBuffer.GetImageDataPtr from the .NET component Please note that the images are stored bottom up, therefore the byte at the address returned by this method is the first byte of the first pixel of the last line of the image.

zihui_w
October 5, 2005, 15:34:55
Hi Stefan,

Thank you for your prompt reply. But how to using the imageDataPtr to get full image data? Using "marshal.copy" in vb.net? or other method? Any sample code?


I have tried to use the following code to convert the two dimension data to an one dimension array. But the speed is very slow.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub IcImagingControl1_ImageAvailable1(ByVal sender As Object, ByVal e As TIS.Imaging.ICImagingControl.ImageAvailableEventAr gs) Handles IcImagingControl1.ImageAvailable
Dim CurrentBuffer As TIS.Imaging.ImageBuffer
Dim x, y As Integer
Dim BytesPerLine As Integer
Dim i As Integer
Dim img_buff() As Byte

Cursor = Cursors.WaitCursor
CurrentBuffer = IcImagingControl1.ImageBuffers(e.bufferIndex)

BytesPerLine = CurrentBuffer.BitsPerPixel / 8 * CurrentBuffer.PixelPerLine
img_size = CurrentBuffer.Lines * BytesPerLine

ReDim img_buff(img_size)

' Calculate the count of bytes ber line using the color format and the
' pixels per line of the image buffer.
BytesPerLine = CurrentBuffer.BitsPerPixel / 8 * CurrentBuffer.PixelPerLine - 1
For y = 0 To CurrentBuffer.Lines - 1
For x = 0 To BytesPerLine
img_buff((CurrentBuffer.Lines - 1-y) * BytesPerLine + x) = CurrentBuffer(x, y)
Next x
Next y
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Stefan Geissler
October 6, 2005, 08:03:22
Hello Zihui,

I must surrender, i never tried pointer operations in Visual Basic, so i did not used the ImageDataPtr method in it. It was invented for C#.
Your copy function is correct, but Visual Basic is too slow. It is not suitable for image processing. If you would use C#, you could do very fast, especial if you would use unsafe sections.

zihui_w
March 27, 2006, 11:33:04
Hi Stefan,

I have a professional lib. version 2.0 which can detect the USB camera. But it doesn't support the "GetImageDataPtr" method in vb.net. Do you have the higher version that can support this method.

I need it urgently for a demo with a USB camera. I don't want to change much source code.

Thanks a lot.

Best Regards

Johannes Vogel
March 28, 2006, 13:28:06
Hello,

please send an email to support@imagingcontrol.com asking for an update to version 3. You have to provide your original 2.1 installtion key with the email, otherwise we will not be able to generate a free update.

zihui_w
April 18, 2006, 04:16:19
Hi Stefan,

I found a exception in the DisplayBuffer sample code (vb71) in ICImagingControl3.0.

When i run this sample code, the exception message show "Object reference not set to an instance of an object"

How to fix it?

Thanks

Zihui

Stefan Geissler
April 18, 2006, 09:06:02
Hello Zihui,

This is a very nice Visual Studio 2003 problem. The only solution i know is to remove the component from the frame, then remove it from the component tools. After this close Visual Studio 2003. Start it again, open the project and insert the IC Imaging Control3 component again. Then insert it into your frame. After this, the sample may be works.

zihui_w
April 18, 2006, 09:17:20
Hi Stefan,

Thank you so much for your reply. I am waiting for it after i posted this problem.

Acturally, i found all sample code in vb71 have this problem.

Should i need to remove those IC Imaging Control3 components from the reference list?

zihui_w
April 18, 2006, 10:17:47
Hi Stefan,

I have tried to fix this problem following your steps listed in your last reply. But the result is same.

I am thinking if it is due to i have two IC imaging Control in my customize toolbox under .Net Framework Component tab.

There are two IC Imaging Control Lib (V2.1 and V3.0)installed in my PC.

The V2.1 (2.1.110.7) is come with the image capture card delivered from your company. the V3.0 (3.0.1.0)is download from the web (it is a free upgrade version from your support dept.)

I do need your help to fix it. :-((

Stefan Geissler
April 18, 2006, 14:40:53
Hello Zihui,

Both versions of IC Imaging Control can be installed parallel. There are now problems with it.
Please let me know, wether the same problem happens with the other IC 3.0 .NET samples too.
At lease you may create a new project using the IC Imaging Control project wizard. It would be interesting to know, whether the same problem occurs with it too.

The error message "Object reference not set to an instance of an object" means that there is a null pointer to the control. It was declared (in the automatically created code) but the control does not exist. Thus you may post the line that the error occurs.

zihui_w
April 19, 2006, 07:49:25
Hi Stefan,

Thanks for your answer. But all sample codes has this problem.

I have sent some source code to you. Please check them for me.

Zihui

Stefan Geissler
April 19, 2006, 09:05:31
Zihui,

You use Visual Studio 2005 instead 2003. I saw this in the SLN file, you have sent to me. I already sent an IC update link to you.