View Full Version : Performance Questions

August 4, 2011, 03:49:16
I am developing a windows service to take pictures of my companies product as it is leaving the assembly line. We have several different usb2.0 cameras some 5mp and some 1024x768 at different points in the plant. Some areas uses multiple cameras to trigger images of each side of the product and at other areas there is just one camera being triggered. The software is working and photos are being saved, but we are seeing a very big difference in the time it takes for the pictures to be taken. In some cases it takes a second or two and in others it can take 40 seconds plus. As it is important for our quality process to have these photos a 40 second delay makes it tough to keep production on target. I am hoping that someone can give me some pointers on ways to speed this process up. Probabbly isn't the best code and I'm still learning... so go easy ;) but any assistance is greatly appreciated!

Thank you

' Example code to create a simple list of cameras
Dim cameras As New List(Of ICImagingControls)

Dim cam1 As New ICImagingControl(My.Settings.Key)
cam1.Device = My.Settings.Cam1DeviceName

Dim cam2 As New ICImagingControl(My.Settings.Key)
cam2.Device = My.Settings.Cam2DeviceName


' And heres a rough look at the code I'm using to loop through cameras and take photos
For Each cam As ICImagingControl In cameras
'code would go here to set filename
filename = "C:\test\" cam.Device + "-" + Now.ToString("yyyyMMddHHmmssfff") + ".jpg"
cam.ImageActiveBuffer.SaveAsJpeg(filename, 100)

Tim Cassens
August 4, 2011, 09:02:42

Are you able to debug it or add timers and debug output to find out which operation takes so long?

Could you also try to find out whether the cameras work on the computer in question when you use IC Capture? Please check whether the frame rate is stable and as high as the camera is configured.

Best regards
Tim Cassens

August 4, 2011, 13:13:07
I have been using now.ticks and timespan.fromticks to time different parts of the code. The delay always seems to be with memorysnapimage. I'm going to try loading the device state from a file. I noticed, after I posted, that the videoformat wasn't what I expected.

August 4, 2011, 22:06:09
The part that seems to be taking the longest is the memorysnapimage() the other method calls seem to happen very quickly. I'm looking into the videoformat as I noticed it wasn't using the parameters I expected in the devicestate. Maybe I have some code wrong in that setup. Is it a best practice to always load the device state for a camera? Any other things that might slow down the memorysnapimage method?

Thank you,

Austin Lippert

Tim Cassens
August 5, 2011, 09:03:49
Hello Austin

MemorySnapImage waits for the next image to come from the camera. If LiveStart has not been called yet, MemorySnapImage also calls LiveStart and LiveStop after one image has been received.

There are several possible reasons for MemorySnapImage being slow:
- You did not call LiveStart for the camera
- You set a long exposure time, so that it takes several seconds before the camera is sending an image
- You have frame drops

To check for frame drops, please use IC Capture, setup the camera as you expect your program to do it and have a look at the FPS display in the title bar.

It is important to always inititialize all camera parameters at the start of your program. That way you can make sure that the camera is always in the state you expect it to be.

Best regards
Tim Cassens