擅长:python、mysql、java
<p>您可以对图像进行二值化以查找缩放段的轮廓:</p>
<p><a href="https://i.stack.imgur.com/xBcjh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xBcjh.png" alt="processing"/></a></p>
<pre class="lang-py prettyprint-override"><code>scale = cv2.imread('scalenanometer.png', cv2.IMREAD_COLOR)
scale_gray = cv2.cvtColor(scale, cv2.COLOR_BGR2GRAY)
# adjust the second value of the next line to tune the detection
ret, thresh = cv2.threshold(scale_gray, 210, 255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# filter noisy detection
contours = [c for c in contours if cv2.contourArea(c) > 100]
# sort from by (y, x)
contours.sort(key=lambda c: (cv2.boundingRect(c)[1], cv2.boundingRect(c)[0]))
# work on the segment
cv2.rectangle(scale, cv2.boundingRect(contours[-1]), (0,255,0), 2)
x,y,w,h = cv2.boundingRect(contours[-1])
print(x,y,w,h) # x,y: (39 152) w,h: [304 21]
</code></pre>
<p>如果要检测该值,可以使用tesseract ocr</p>