• Flutter
  • Dart
  • OCR

From a ticket photo to draw results in Zoveso

Zoveso reads tickets on the phone, extracts the station, draw date, and ticket number, then looks up the results.

When I built ticket scanning for Zoveso, reading the text was only part of the job. A ticket carries the station name, the draw date, the ticket price, prize amounts, and the number the user wants to check. Optical character recognition (OCR) turns the writing in a photo into text the app can process. An entirely readable OCR result can still lead to the wrong results if the app picks the wrong date or takes a number from a printed prize amount.

The scan has three steps. The recognizer reads the image. The parser finds the station, draw date, and ticket number in that text. The results screen uses those fields to select the draw and check the number.

Retry at the image-processing stage

After capture, Zoveso preprocesses the image with its standard settings and sends it to the recognizer. Preprocessing means adjusting the photo before recognition so the text is easier to read. On iOS, Flutter calls Apple Vision through a platform channel (Flutter’s bridge from Dart code to native iOS or Android code) configured for Vietnamese and English. On Android, the app uses ML Kit’s Latin-script text recognizer. Both paths return lines of text to the same Dart parser. Apple Vision text recognition, ML Kit Text Recognition

If the output is empty or fewer than 20% of its non-whitespace characters are digits, Zoveso starts again from the original image with more aggressive preprocessing. If only 4 of the 30 non-whitespace characters are digits, for example, the ratio is about 13% and the app retries. The threshold reflects how many numbers a ticket usually contains. A ticket can still pass the ratio check with a misread digit, so the decision to look up results happens further downstream.

Extract three fields from the text

The parser looks for the station by code or name and can match Vietnamese names with their diacritics removed. It also handles Northern tickets that use a common label such as XSMB. For the draw date it accepts separators such as hyphens, slashes, and periods, then normalizes the result to DD-MM-YYYY.

Suppose OCR returns these three lines:

XSAG
24 / 11 / 2026
012345

The parser extracts 24-11-2026 and removes the matched date text before searching for the ticket number, so the digits of the date cannot be mistaken for part of a ticket number. It looks for six consecutive digits first and falls back to joining digits separated by whitespace when it finds no contiguous match. The ticket number 012345 stays a string, preserving its leading zero for comparison.

For this fixture, the parsed result has all three fields the results screen needs:

Field From the fixture Missing-station fixture
Station matched from the code label XSAG none
Draw date 24-11-2026 24-11-2026
Ticket numbers ["012345"] ["012345"]

The second column is the same fixture without the XSAG line. The date and number come out the same; only the station is empty, and that one gap is enough to stop the lookup, as the next section shows.

When the lookup starts and when the photo is deleted

The screen starts the lookup once it has a station, a date, and at least one ticket number. If a field is missing, the screen can use the parsed result to tell the user what is missing. In the missing-station case above, the app has the date and 012345 but still lacks the information it needs to choose a draw, so it reports the missing station instead of guessing. Text recognition runs on the device and, as the Zoveso app page states, the photo is deleted once it has been read. What reaches the results lookup is the station, date and number, not the image.

The OCR flow keeps the original image until the retry is finished because both preprocessing passes use it. A finally block attempts to remove the capture and the generated temporary files whether recognition succeeds or fails. With recognition and lookup split this way, I can reproduce a parsing issue with a text fixture and investigate a lookup issue with the exact station, date, and number that reached it.

ABN Signal handles a related problem differently: it reads a live camera feed rather than one photo, so it confirms a number only after it appears in two consecutive frames.

Conclusion

Treat OCR as a source of candidate text, not as the final answer. Separating recognition, field parsing, and results lookup makes each stage easier to test and gives the app a clear way to report missing information before it opens a draw.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me