Reading 7 segment digits of weighing controller

Question:

i am trying to read the 7-segment display of a industrial weighing machine. as there is no serial out port for the machine i have to note down the weight manually. the idea is to use python-computer vision to capture the weight and store it in text file. the image is as shown 7 segment from weighing machine.
i have used the following python code for this purpose.
the code runs fine till i am converting the image to gray. the converted image is grayed image . the problem starts when i start applying the threshold to the image. after applying the threshold the image is as shown threshold imageany suggestions so as to how i should proceed.

Asked By: bipin_s

||

Answers:

Something like this, using just OpenCV and Pytesseract, seems to work okay:

import cv2
import pytesseract

img = cv2.imread("Cf8ko.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thres = img.max() * 0.9  # 90% of the maximum brightness
img[img < thres] = 0  # set all pixels below threshold to black
img[img >= thres] = 255  # set all pixels above threshold to white
img = cv2.bitwise_not(img)  # invert to black text on white background
text = pytesseract.image_to_string(img, lang="eng")
print(text)

This prints out

9830

and the processed image looks like

enter image description here

– depending on the quality of your images, you may want to run a blur/dilate/… or adjust the Empirical Stetson-Harrison value 0.9.

Answered By: AKX
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.