Just saw this today and I felt like integrating my code into yours (mostly because I need to do a lot of clean-up with my code and doing this forces me to figure out what parts are and aren't needed in my own code).
- A much easier way to do a threshold is cvInRangeS(..)
an example would be
Code:
cvInRangeS(src, cvScalar(b_low, g_low, r_low, 0), cvScalar(b_high, g_high, r_high, 0), dst);
- I kept the BGR threshold, but cvInRangeS also works if you convert your image to another type (like HSL)
- For blurring, I scale it down to half-size and back up... I have no real reason for why I do it this way.
- I also use a convexHull operation to fill in the gaps after that
- I take each blob and find points which are closest to the corners of a bounding rectangle, I choose these as the corners.
- I eliminate found rectangles that are within other found rectangles (this is a problem that comes with the logic I use).
- I also eliminate small polygons, so that my threshold can be wider
I hope somebody will find this useful, it's a pain to get started with javaCV. Classes to add and result are attached.