0

x = pytesseract.image_to_string(im1, lang='eng', config='--psm 10 --oem 1 -c tessedit_char_whitelist=1234567890JQKA')

print('' + x + '')

output ***9


How do I get rid of line returns and spaces or what am I doing wrong? Just reading one char/number.

DonnyMT
  • 11
  • 1

1 Answers1

0

Can you show the image you're processing? The print quotes and the content + x + also look strange to me. These ***9 : are these stars actually printed, because you say to get rid of "spaces and returns"? Or it's an emphasize?

Right, --psm 10 is for recognized single characters.

If the output has spaces and returns only (not ***) you can trim it: How do I trim whitespace?

x = x.strip()

(Possibly the spaces and lines not count as recognized characters).

Twenkid
  • 825
  • 7
  • 15
  • I used the *** to mark each side of the value being stored so I could visualize the extra lines and spaces being added for some reason. Here are a couple of the numbers I am reading. Part of a card game. – DonnyMT Dec 22 '20 at 19:10
  • Can't seem to finger out how to load an image in with this text. But the graphics are just the value portion of playing cards - 2-10 and J, Q, K and A. pytesseract does a great job of reading value, just seems to append return lines. Tried Strip, should do the trick, thanks!! – DonnyMT Dec 22 '20 at 19:20
  • OK, cards. Good. You can add images in your question if you wish, I think they are not allowed in the comments. Also, you may mark answers which were useful for you, so future visitors could notice and be directed and the contributors would gain reputation points for their contribution. – Twenkid Dec 23 '20 at 01:28