Understanding Camera Client Server

<< Back to the EasyImage Toolkit page

How To - Understanding the Camera Client and Camera Server

What you will learn

This How-To describes most of the things you will need to know about the Camera Client and Camera Server. You will learn

  • why you should use a camera server
  • how to start the Server from either the Start Menu or through your program
  • some issues that may affect how it all works.

Why you should use a camera server

Conceptually, if you have a web camera attached to your computer, you should just be able to ask it for a frame. Alternately, you should be able to set a frame rate and be notified when a new frame is ready for you to use. If only all of life were that simple.

The reality is that accessing frames on a web camera is a mess. In fact, one of our motivations for writing EasyImages was to try to reduce this mess to a manageable state! Here are a few reasons:

  • Camera hardware and drivers all deliver different things. Just because you set a property (e.g., a camera size and frame rate) doesn't mean you can get it.
  • Windows tends to block access to camera images to a single process. That means that if you are getting camera frames from one program, you can't run another program to get frames from that same camera.
  • If you have multiple cameras attached to your computer, things get hairy.
  • Threading tends to mess up how you can reliably access camera frames without adding program complexity.

To get around some of these issues, we include a Camera Server with Easy Images. The first job of the server is to start a web camera with some certain properties set (e.g., frame rate, size, and a name), and then capture frames from an attached web camera. Multiple client programs can then access those frames. Under the covers, the camera server writes frames to a named location (that is what the Camera name is used for), and the camera clients just read from that location.

For most people, all you need to know how to do is start the camera server and set properties that work well with your program.

We should mention that you don't have to use the Camera Client / Server model in your own programs. You can use the Camera object supplied in EasyImages to access frames directly. This approach will actually work for most things, but see the issues mentioned above.

Starting the Client Server.

This sequence illustrates two ways to start the Camera Server.

Method 1: The Start Menu

If you have installed the CameraServer Installer package (in the Easy Images download and installation section), you will find an entry on your start menu called Grouplab -> EasyImages -> Camera Server. Select this, and the window below should appear:

At this point, you can specify the following properties of the camera server:

  • the name of your camera (but this name has to match the name provided to the CameraClient initialization method) - unless you have multiple cameras, you will find it easiest to just leave the name as DefaultCamera.
  • a maximum frame rate that you want the server to try to generate frames (this cannot be guaranteed, but it will do the best it can)
  • the image resolution (note that large images will slow the system)

When you are done, you can start generating frames from the web camera, or you can generate a test pattern instead. The two images below show both cases. The left starts the server using actual camera frames by clicking the Start Camera checkbox, while the right does the same except that it generates a test pattern by clicking the Start Test Pattern button. You can see the video or the test pattern as it is being generated by clicking the ''Display video' checkbox (see image below). Note that the test pattern shows the current time in one second intervals.

Method 2: Automatic Server Starting through your Client Programs.

If you try to start a program that uses the Camera Client to access frames (e.g., all the tutorials are written this way), that program will expect the server to be running. However, if for some reason you have not started the Server, the program will recognize and try to remedy this.

Instead of failing, thatprogram will install its own version of the server (which is actually included in the EasyImages.dll, and then try to invoke it. You will then see the series of dialog boxes below. You then need to select the Start checkbox in the Camera Server window, and the Ok button in the Start Camera dialog box after the camera is started.

A few other things to know:

  • Starting and stopping the camera takes a few seconds.
  • You cannot change the camera properties if the camera is started. Instead, you have to stop the camera, change its properties, and restart it.
  • If you stop the camera, it will automatically unselect the Display Video checkbox and shrink the window. This is because there is nothing being captured anymore, so its misleading to show an image there.
  • If you don't have a web camera attached to your computer, the results are somewhat uncertain.
  • If you don't have the server running while the Camera Client program is trying to get camera frames unpredictable things can happen. We have gone to great lengths to try to minimize the effects of this:
    • you may get a blank image if the server has never been started, or
    • you may get a frozen image of the last frame captured before the server is stopped.
  • the CameraServer program is written in EasyImages - it just uses the Camera object instead of the CameraClient object.