Not sure why it took a long time to load, possibly my 3D calculation that pre-calculates height information for all pixel. Technically I should be loading the image in another thread so the ui event doesn't get blocked. I'll eventually get around to it.
This code deals with the detection. There's a function at the bottom that detects the color and later finds the brightest green point.
Also everything in my code is threaded. Each scanline is handled by a thread, so it should be pretty fast at what its doing. The only thing that isn't multithreaded is the 3D calculation. I will eventually multithread this thing as well.
I've been playing with it, and the red lasers are really easy to work with. The bean's center is almost pure white, so all I had to do to extract the lasers was to threshold the red channel of the image.
As for the dewarping, I am going to redo a lot of the code. I want it to work only with a set of three images, and no user-defined values: a calibration image, an input laser image, and a laser-less image.
I'm pretty happy with where I'm at with my code.. Over the weekend I tidied it up so I'm pretty much ready to try it out with the lasers.
The approach I"m going to use is take a few calibration images, using QR codes. The first one will be on the base, the second one probably on a section of 2x4, and a final one with stacked 2x4 (so more like a 4x4). Then I'll use those images to determine the camera height, laser angle, image rotation, etc.
Then I'll probably scan a full book, with a laser image taken every 10 pages or so and see how well it works.
I'm in the process of using OpenCV's image mapping functions to create my dewarping grid. PIL is just way too slow, and it can't interpolate. Here's a quick test I did for radial dewarping: Python's Imaging Library takes > 20 seconds to radially dewarp an image (without interpolation). OpenCV's camera calibration: a fluid animation of dewarping the image, starting from k=0 to 1, with a step size of 0.00001.
20 sec per image? thats pretty slow. I tried the c++ implementation I have with a 8 mega pixel camera and its about .5 ~ 1 sec to correct image with bicubic interpolation. Although my bicubic algorithm seems to be broken at the moment... I'm getting weird artifacts some times.
Anyway I've been thinking what order to apply the image correction... lens distortion -> key stone correction -> rotate/move image respect to laser -> book flattening.