I'm one of the people behind Electroscope, a free, open-source (MIT) viewer app for USB microscopes on Windows 11 and Apple Silicon Macs. This post is about one small part of it that turned out more useful than expected: the focus meter.
Why bother
The scope we built it around is a cheap Generalplus one (USB id 1b3f:2002, 1280x720). On a Mac it exposes no image controls to the app at all: no focus, no exposure, no brightness. Windows gives you more, but on most of these scopes focus is purely mechanical anyway. So the one thing you actually do all day is turn the ring, and at high magnification it's hard to tell by eye whether you've passed the sharpest point, especially on a laptop screen.
What the number is
About three times a second the app takes the current frame, scales it down to 640 px on the long edge, converts it to greyscale and runs a simple 3x3 Laplacian over it (each pixel's four neighbours minus 4x the pixel). The score is the variance of that result. A sharp image has lots of strong edges, so the variance goes up; blur smooths the edges out and it drops.
In the window you get the number, a little 16-bar history, and a peak hold. If you're within 2% of the best value seen it says "at peak", otherwise it shows the peak so you know to turn back. The peak decays by 0.5% per update, so after you move the board it follows the new scene instead of being stuck on an old high score.
Two things we learned:
- Measure before any picture adjustments. Electroscope has its own brightness/contrast/saturation (done in software, so they work on any camera), but the focus score is taken from the frame before those are applied. Otherwise cranking contrast makes the meter claim things got sharper.
- The number only means something within the same scene. Moving the board, changing the light or pointing at a plain area of solder mask changes it a lot, so it's for "turn until it peaks", not for comparing two different boards.
The rest of the viewer
Zoom, pan, rotate, mirror, freeze, a grid and crosshair, your own circles/arrows/text that stay on the part when you zoom, and saving photos. Sliders a camera ignores get hidden instead of shown and doing nothing.
The image on this post is an illustration made for it, not a screenshot. Real screenshots of the app running on that Generalplus scope are in the first comment.
Getting it
Signed installers (Windows x64 setup/portable, macOS Apple Silicon DMG) are on the releases page, or build it from source with npm ci and npm start. No Linux build yet.
Repo: https://github.com/UnlikeOtherAI/electroscope
What I'd like feedback on: would a focus-peaking overlay (highlighting the sharp edges on the image itself) be more useful to you than a single number? And if you've got a USB scope that does expose focus or exposure controls on Windows, I'd like to know which one, so we can test against more than two cameras.