A guide to the EasyImages API
Note: We highly recommend that you look at the Tutorial Examples, as this will help you understand how to use this API.
CameraClient
CameraClient is the easiest way for a client to use the webcamera: a CameraServer (a separate program) actually generates the frames, which the CameraClient then accesses via events. Using this Client/Server approach also allows several programs to simultaneously use the same webcamera.
Fields:
FramesPerSecond float Sets the number of frames the system should attempt to capture from the camera each second. The value is not known until the CameraClient has been started.
ServerMaxSpeed float Gets the maximum new frames per second that the server will display. The value is not updated until the first frame from the camera is received.
Events:
ReceivedFrame An event with the current frame. Note that events will probably be returned on a new thread.
ServerStopped An event fired when the server stops cleanly.
ServerStarted An event fired when the server is started.
Constructor:
CameraClient(string servername) The name of the server that the client will connect to.
Methods:
Image GetFrame() Returns a the last frame captured by the camera.
Image GetTestPattern() Returns a test frame image.
bool Start() Connects to the Camera Server. If the camera server is not running, it spawns an instance of CameraServer. If connecting to the server is ultimately successful, it returns true, else it returns false. If Start() returns true, the CameraClient returning frames via the Received frame.
void Stop() Disconnects from the Camera Server.
Camera
Camera provides a way for the user to directly access webcamera. It provides the ability to either capture frames from a camera on demand or on callbacks as new frames are received. Normally, one should use the CameraClient class instead.
Fields:
Bitmap CurrentFrame Gets the current frame in the form of a bitmap. Note that if the camera is not running, the camera will then be initialized and then asked to capture a new frame.
FramesPerSecond float Sets the number of frames the system should attempt to capture from the camera each second. This can be changed while the camera is running.
int Width, int Height These fields control the resulting width and height of the image that the camera captures. Note that extremely small widths and heights may result in unusual behavior. The width and height should not be changed while the camera is running.
Events:
ReceivedFrame An event with the current frame. Note that events will probably be returned on a new thread.
Methods:
void Start() Starts the camera and begins capturing frames and returning events.
void StartFileMapping(string servername) Starts a region to capture images to, then copies camera captures to it. Used in creating camera servers.
void StartMappingTestPattern(string servername) As StartFileMapping but instead of capturing camera images, copies a test pattern to that region. Used in creating camera servers.
void Stop() Deinitializes the camera and kills all callback threads.
ImageAnalyzer
The ImageAnalyzer class provides static methods to perform various useful analysis functions on individual bitmaps or pairs of methods. None of the functions damage the bitmaps passed to it.
Methods:
float PercentDifferenceDegree(Bitmap photo1, Bitmap photo2) For each pixel location in photo1and photo2, it sums the difference in red, green, and blue values. The total difference, summed over all pixels, divided by (number of pixels * 255 * 3) is the value returned. In this manner, the greatest difference is a solid black image compared to a solid white image, resulting in a difference of 1. Two identical images return a value of 0.
float PercentDifferencePixels(int threshold, Bitmap photo1, Bitmap photo2) For each pixel location in photo1and photo2, it sums the difference in red, green, and blue values. If this value is over the threshold, the pixel is marked as different. The threshold value can be set between 0 and 765. If the threshold is set very low, such as to 0, even the noise alone can result in a great deal of different pixels. Two completely different images return a value of 1 while two identical images return a value of 0.
ImageManipulator
This ImageManipulator class performs a number of useful image processing operations on the Bitmap objects passed to its various methods. All the methods in the class are static. None of the methods for image manipulation in this class have any return, rather they manipulate the bitmap in place. This is done for efficiency. The rule is that the first image in a method’s signature is the one that will be overwritten with the new result.
Methods:
AlphaBlend(ref Bitmap photo1, Bitmap phot2, int amount)
Blends photo1 and photo2 together, the exact amounts of each determined by the amount field. 0 is completely photo2, 100 completely photo1. Photo1 must be passed as a reference and is overwritten.
Distort(EasyImages.DistortionStyle ds, Bitmap photo1)
Performs the selected distortion on photo1, overwriting it.
The available distortion styles are: Blur1 – Blur7 apply a blur to photo1, the larger the suffix number, the greater the degree of blurring. EdgeDetect applies an edge detect filter to the photo EmbossAllDirections, EmbossHorizontal, EmbossVertical, EmbossHorizontalAndVertrical, EmbossLossy, LaplacianEmboss are all various common types of emboss filters MeanRemoval performs a very specific function to photo1 array. This is needed for some multimedia tasks. Sharpen, SharpenMore apply a sharpen function to photo1
Dither(EasyImages.DitherStyle ds, Bitmap photo1) Performs a dither on photo1. The result overwrites photo1
The available dither styles are: BlackAndWhite, Gray4, Gray16, Gray256, Color16, Color256 Note that Color256 can be very slow, due to that nature of the algorithm.
Image FormattedByteArrayToImage(byte[] array) Returns an Image when passed an array containing the description of an image.
byte[] ImageToFormattedByteArray(System.Drawing.Imaging.ImageFormat imgf, Image I) Converts the image to a byte array in the selected image format. Consider, instead, using the JPEG class.
Operation(EasyImages.OperationStyle os, ref Bitmap photo1, Bitmap photo2) Performs the selected operation on the pair of images, replacing photo1.
The following operations are available: Subtract: Performs a differencing on the two images.
Resize(int width, int height, ref Bitmap photo) Replaces the bitmap with one of the desired width and height.
ImageGenerator
This ImageGenerator provides the same functionality as the ImageManipulator class, but instead of overwriting images it returns a new image, the result of the function applied. Otherwise, the notes for ImageManipulator apply.
Methods:
Image AlphaBlend(ref Image photo1, Image phot2, int amount)
Image Distort(EasyImages.DistortionStyle ds, Image photo1)
Image Dither(EasyImages.DitherStyle ds, Image photo1)
Image FormattedByteArrayToImage(byte[] array)
Image byte[] ImageToFormattedByteArray(System.Drawing.Imaging.ImageFormat imgf, Image I)
Image Operation(EasyImages.OperationStyle os, Image photo1, Image photo2)
Image Resize(int width, int height, Image photo)
JPEG [Serializable]
The JPEG class exists for a couple reasons. First, it allows the user to convert a bitmap to a serializable object for transport over the network. It also allows the user to set the quality of the image, which can radically reduce the amount of storage required.
Constructor:
JPEG(Image i) i is the image to be used to create the JPEG
JPEG(Image i, int quality) i is the image to be used to create the JPEG quality is a value between 1 and 100 that determines the degree of compression to be used on the image, where 1 is the most compression and 100 the least. The scale is not linear and there maybe be very little difference or very great difference between two sequential values
Methods:
Image GetImage() Returns the image object representation of the jpeg
byte[] GetArray() Returns the byte array representation of the jpeg