Odd results with OpenCV

Continuing on the WW2CP project, I found some test gifs that look like casualty lists by county and state. I pulled down one sample page to see if I could get OpenCV to read the text on the page. No luck at first. The page was black text on gray paper in a gif, so I thought that fixing the brightness and contrast and cropping the page might help, but no.

The pages are organized by sets of columns that list the last name, first name, middle initial, serial number, rank and fate (KIA, DNB, etc). These sets of columns are then organized as three sets of columns on a page. With review of the Pillow documentation, I figured out how to crop the columns to make them one column only. I also figured out how to change the brightness of the page (to make the gray background turn whiter) and the contrast (to make the letters look more like letters). I ran OpenCV on the modified pages and I still could not get OCR to work properly. 

I probably need to look at Natural Language Processing to make this work the way I want. It sounds interesting, but it could also be a rabbit hole of never-ending tasks. Apparently, I may need a corpus (?) of names, I think. I should probably read a book first. (Natural Language Processing with Python).

Advertisements

WW2CP.org update – OCR!?!

I had some time to get back to this project, so I decided to make some updates. My updates were not to the website, but to the data underscoring the website. I needed to show that I could take data (pages scanned as gifs – really) available at the National Archives and read that data into a database. I pulled a page from here (https://www.archives.gov/research/military/ww2/army-casualties). It’s not really a random page — it’s a page from U. S. Army casualties from Los Angeles County.

I discovered I could not open the file using Python 3 and OpenCV because it can’t open GIF files. (???) I was able to open the file using the Pillow module from Python 3. I can also convert the file to a PNG file and resave the file into a different folder. Once the file was saved, I could read the file using OpenCV and could get some OCR. The results were very bad, but it’s the first try.

The page is set up to show three columns of casualties. I need to crop the page to show three separate columns and read each column. Additionally, I need to boost the contrast to see if that makes the text in the image easier to read. I’ll need to review  Pillow to see how I can change contrast, but it does not look hard.

Progress!!!