USB microscope works like normal USB webcam with the difference on the lens fixed on it which is used to magnify the object. It gives a low cost alternative for some inspection works, such as PCB inspection.

Using the Equalis Advanced Image and Video Processing Module, I've tested the USB microscope for some simple job --> object detection and counting.

With the RGB image input (640 x 480), which is resized to half of during processing, the first test running in real-time, in which the original image and the binary image after processing is shown side by side.

The source code shown as below:

// 1. Loading Background Image which has been captured before this
load('Background.sod'); // Background image saved in variable R
R = imresize(R,0.5); // Resize to half for speed
n = camopen(3,[640 480]);
se = imcreatese('ellipse',12,12); // Creating Structure Element for Morphological operation
 // 2. Running for 200 frames, Frame rate not measured    for cnt = 1:200
        im = avireadframe(n); // Read a frame from USB Microscope
        im = imresize(im,0.5);  // Resize image to half of the size
        S = rgb2gray(im);   // Convert image to grayscale
        S_diff = imabsdiff(S,R);    // Compare the image with the background image
        S_bin = im2bw(S_diff,imgraythresh(S_diff)); // Convert the difference image to binary

        S2 = imopen(S_bin,se);  // Perform Imahe Opening
        [S3,nn] = imlabel(im2double(S2));   // Labelling image
        if  nn ~= 0 then
            [Area, BB, ctr] = imblobprop(S3); // Find the object properties
            imshow([S im2uint8(S2)]);   // Show image in cascade
            imrects(BB,[255 0 0]);   // draw frame around detected objects
            xtitle('Detected Object : ' + string(nn)); 
            imshow([S im2uint8(S2)]);
            xtitle('Detected Object : ' + '0');