maddevsio / go-idmatch

ID cards recognition based on gocv
https://idmatch.co
42 stars 13 forks source link

Coefficients for text regions search mechanism #41

Open Lezh1k opened 6 years ago

Lezh1k commented 6 years ago

Right now there are no optimal coefficients for OpenCV filters in processing step. There is some mechanism in text-extraction-coeff-finder , but it's not ideal because of bruteforce. Maybe we need to use some optimizations like Newton or something like that for coefficient searching.

Need to make research how can we get optimal coefficients for text areas detection step.

Suupa commented 6 years ago

A general solution to the issue is not to use brute force, but gradient descent with a learning rate (stepsize) small enough not to overshoot local minima and large enough to converge in a reasonable time. This seems counterintuitive because ANNs are complex models with large numbers of local minima, however empirical evidence has indicated that linear ANNs have most of their minima near the global minimum, meaning that gradient descent often performs “well enough” as a heuristic solution.

Lezh1k commented 6 years ago

Agree. Hardest part is to detect that we are closer to optimal coefficients here . But there is good enough distance function for this.

Suupa commented 6 years ago

Where can I find this distance function? Indeed, the problem I'm foreseeing is that it's hard to do clear cut comparative testing when the algorithm still contains stochastic components. Their usage should, i.m.o. be restricted to training the system (finding optimal coefficients) and should not be allowed in the actual execution of the system (testing).

Lezh1k commented 6 years ago

Same file text-extraction-coefficients-finder.go.

func compareRects(x00, y00, x01, y01, x10, y10, x11, y11 int, devX, devY float64) bool {
    return math.Abs(float64(x10-x00)) <= devX &&
        math.Abs(float64(y10-y00)) <= devY &&
        math.Abs(float64(x11-x01)) <= devX &&
        math.Abs(float64(y11-y01)) <= devY
}

func checkRegionsNewID(regions [][]image.Point, rects []frect, devX, devY float64) bool {
    count := 0
    for _, regIn := range regions {
        rect := gocv.BoundingRect(regIn)
        for _, regEt := range rects {
            if compareRects(rect.Min.X, rect.Min.Y, rect.Max.X, rect.Max.Y,
                regEt.x0, regEt.y0, regEt.x1, regEt.y1, devX, devY) {
                count++
            }
        }
    }
    return count >= len(rects) //warning!
}

We use these 2 functions.