Yes, there are ways to measure it, though there are many different algorithms claiming to be more correct than the others. This formula by Vassilakis is recent (2007).
These measure "roughness", which is similar to dissonance. (Dissonance is basically roughness, but weighted towards certain intervals due to cultural conditioning, which is obviously hard to measure quantitatively.) For two sine tones, roughness vs frequency difference looks like this:
For more complex signals, made up of multiple tones:
The roughness of signals corresponding to spectra with more than two sine components is calculated by summing the roughness of all sine-pairs in the spectrum.
For tones with harmonic spectra, the net effect of the roughness between all the harmonics present produces graphs with notches of consonance at intervals that we're familiar with, like 3:2 perfect fifth:
The black curve is from the older Plomp-Levelt 1965 paper, with this description:
We assume that the total dissonance of such an interval is equal to the sum of the dissonances of each pair of adjacent partials ... these presuppositions are rather speculative ... In this way, the curves ... were computed for complex tones consisting of 6 harmonics. ... shows how the consonance of some intervals, given by simple frequency ratios, depends on frequency.
(So the Plomp-Levelt curve is based on summing up the roughness of adjacent partials while Vassilakis sums "all sine-pairs". (Sethares wrote me and says the "adjacent" thing is just because computational power was limited in the 60s. Comparing every pair is more appropriate.))
Further descriptions of this curve can be found in Marc Leman - Foundations of musicology as content processing science (which also talks about deriving the slendro and pelog scales from the same algorithm applied to inharmonic gong instruments) and Plomp and Levelt's Hidden Ratio
The blue curve is from Sethares Relating Tuning and Timbre, which uses this MATLAB calculation, also based on the Plomp-Levelt curves. (And here's my Python translation.) Here's a MATLAB-based app that uses the 2007 Vassilakis model to also calculate the same curve for 6 harmonics (and has the M3 as more consonant than the m3).
You can see the two curves disagree on whether the m3 or M3 is more consonant. I'm not sure if this is due to calculating only adjacent partials vs all partials or if the partials have different amplitudes or what. Of course, real instruments produce lots of variation in their harmonic spectra, even playing the same note on the same instrument, so these curves are all inherently approximations. Here's a plot I made of violin vs clarinet, showing that the M3 is more consonant when the violin is playing the higher note, due to clarinets producing mostly odd harmonics.
Also, for more than 2 tones, the Sethares algorithm ranks minor and major chords as equally consonant, which is not the usual interpretation. So Erlich and Monzo interpret Sethares' number as only a measure of "roughness" and require "dissonance" to include both "roughness" and "tonalness", where major chords are more consonant because they are closer to the root of a harmonic series (4:5:6) while minor chords are farther away (10:12:15). I don't know of a way to quantify that for arbitrary frequencies, though.