#๐ Reading Data from Obfuscated Image
13 messages ยท Page 1 of 1 (latest)
@heavy juniper
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
I am so glad it deleted all of that text!
You can ask some mod to recover it for you
It's fine lol, just gonna retype it.
Fyi it probably deleted it because you sent a file
Yeah that's what it was lol. w/e
Hello everybody! Currently scratching my head at the implementation of a project.
The basic idea is this: there is some binary form (checkboxes) that gets printed, mailed, filled, and then scanned. What I would like to do is convert the checkboxes to a database somewhere as automatically as possible ('lest it be a pain in the ass). Normally, this wouldn't be an issue, but because the process above cannot be changed, some errors occur:
- The form, due to being printed oddly, doesn't have the exact same layout anymore. Orientation within the page can be off.
- Due to needing to be mailed and then scanned, the form can have black lines appear on it. They are purely vertical, and I have been able to get rid of most of them.
- Because lots of people fill out the checkboxes, they all do it a different way.
Right now, my idea is to use a piece of sample text that appears on every form ('the EXAMPLE FORM' on the image I'll be putting in here), and use that to figure out what linear transformation needs to happen to get everything back in its original place. What I'm currently scratching my head over, is how best to check if a box is ticked off. Since they get printed oddly, they don't share the same shape every time. Since multiple people fill 'em out, they don't get filled in nearly the same way. I'll post my current code, along with an image of a sample form, below. Any help would be appreciated.
#Getting imports set up
import os
import openpyxl
import numpy as np
import pytesseract
import cv2
from pytesseract import Output
#Initializing Tesseract
pytesseract.pytesseract.tesseract_cmd = r"C:\\Program Files\\Tesseract-OCR\\Tesseract.exe"
imagepath = os.listdir("images\\") #Get all input images
pagecount = 0
for file in imagepath:
fullpath = "images\\" + file
im = cv2.imread(fullpath) #Read image data
boxdata = pytesseract.image_to_boxes(im) #Grab all of the characters and their locations
boxdata = boxdata.splitlines()#Grab 'em, character by character.
firstchar = boxdata[0].split(" ") #The 'E' in EXAMPLE FORM at the top
lastchar = boxdata[n].split(" ") #The 'M' in EXAMPLE FORM at the top
#From here, what I'd like to do is using a 'perfect copy' (one that hasn't been
#printed, but instead just immediately converted to image, figure out what
#matrix is needed to get 'EXAMPLE FORM' to its original position. From there,
#use the same transformation on the rest of the image, so that way the
#image now sits nicely as it should and can be easily read.
#Struggling to implement past here, nor do I have a solid way of reading
#when a box has been checked...
pagecount += 1
printpath = "post\\" + file
#print(text)
This is the 'ideal copy' - I can get it scanned and printed to show what I mean. But this is the curernt problem I'm struggling to grasp right now.
Reorienting the image has been solved. Now it's just a matter of seeing if checkboxes are ticked or not.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.