hi y’all! I’m a complete newbie to image processing, and I’ve found myself trying to process an image of a table, printed on a sheet of paper. in my use case, this sheet of paper can be warped a decent amount, because of printers or other kinds of folding, as such:
and the hope is to be able to take the contents of each of these cells, and run them through OCR. I’m thinking it would be a lot easier to work with this table if the frames weren’t warped like this, so my first macro step in this pipeline is to somehow “unwarp” the table into a proper straight table.
I’ve definitely started with a simple threshold step, as every image processing pipeline should. I unfortunately can’t send another image, but I definitely have gotten that working.
my first exploration here seemed to point me in the direction of contours, where I would run a contour detection on the image, giving me a bunch of arcs. unfortunately, there were a couple problems with this; the contours were choppy and not continuous, despite my threshold output seeming to result in pretty continuous lines.
this was my attempt at filtering them, because ideally I would only be looking for the largest contours so that I could find the longest lines.
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for i, cnt in enumerate(contours):
length = cv2.arcLength(cnt, False)
if 1000 < length < 10000:
print(length)
cv2.drawContours(img, cnt, -1, (255,0,0), 50)
this unfortunately led to the really choppy contours, and I feel like it was already kinda bad to be hardcoding arc lengths anywho
either way, I was then trying to think how I would even correct the image with these contours in hand. I’ve seen the most common next step for this contouring process, being to use approxPolyDP to simplify the contour into straight lines; however, this still doesn’t explain how I would actually warp the image to these straight lines.
would someone be able to help me with a simple image processing pipeline that would allow me to get to where I’m going? I would totally understand if this is a bit too complex, but it doesn’t seem like it should be.
and my biggest priority here is honestly to learn the methods and transformations used for this, so any help is greatly appreciated. thanks y’all!