SharpCap has a "Focus Assistance" for planets and surfaces. One of its options is to do a "contrast edge detection" where it measures the total contrast in an image. The higher the number, the better the focus. They have a couple of other options as well.
A long time ago I used a SBIG STV camera. It had a wonderful function on it called "Best Sharp" for use with planets. It would take an image, then a second image, compare the two using what they called a "Figure of Merit", and display the sharpest. It would continue to take images and compare the latest image to what it had determined was the sharpest. If the new one was sharper, that would then become the displayed image. This was great for public outreach as you could end up with a pretty good live planetary image.
JohnD