e4eae8dc192c30218aba070feabfda573e5af379
1
module MatchingEllipses
5 open System.Collections.Generic
11 type EllipseScore = { mutable matchingScore: float; e
: Ellipse }
13 let matchingScoreThreshold1 = 0.5
14 let matchingScoreThreshold2 = 2.0
16 let ellipseArea e
= e
.a
* e
.b
* Math.PI
18 type MatchingEllipses () =
19 let ellipses = List<EllipseScore>()
21 member this
.Add (e
: Ellipse) =
23 // dprintfn "new ellipse: %A, nb: %A" e ellipses.Count
25 let areaE = ellipseArea e
27 let mutable matchingScoreE = 0.0
29 for other
in ellipses do
30 let areaOther = ellipseArea other
.e
31 let commonArea = EEOver.EEOverlapArea e
other.e
32 let matchingScore = (2.0 * commonArea / (areaE + areaOther)) ** 2.0
33 if matchingScore >= matchingScoreThreshold1
35 other.matchingScore <- other.matchingScore + matchingScore
36 matchingScoreE <- matchingScoreE + matchingScore
39 ellipses.Add({ matchingScore = matchingScoreE; e
= e
})
41 member this
.Ellipses : Ellipse list =
42 dprintfn
"Number of ellipse: %A" ellipses.Count
44 (*let sortedEllipses =
45 List.filter (fun e -> e.matchingScore >= matchingScoreThreshold2) (List.ofSeq ellipses)
46 |> List.sortWith (fun e1 e2 -> e2.matchingScore.CompareTo(e1.matchingScore))*)
48 List.filter
(fun e
-> e
.matchingScore >= matchingScoreThreshold2) (List.ofSeq
ellipses)
49 |> List.sortWith
(fun e1 e2
-> e2
.matchingScore.CompareTo(e1
.matchingScore))
50 |> List.map
(fun { e
= e
} -> e
)
52 // ellipses.Where(fun e -> e.matchingScore >= matchingScoreThreshold2)
53 // ([], fun acc { matchingScore = score; e = e } -> if score >= matchingScoreThreshold2 then e :: acc else acc)