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 but with inharmonic 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, the Sethares algorithm ranks minor and major chords as equally consonant, which is not the usual interpretation. So others 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 approximate a harmonic series and minor chords do not.