Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sweng-group-15
drawing-app
Commits
3f21fb08
Commit
3f21fb08
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
Angle based line checking
parent
3912ba19
No related branches found
Branches containing commit
No related tags found
1 merge request
!65
Simple shape recognition
Pipeline
#105480
failed
5 years ago
Stage: fetch
Stage: deps
Stage: check
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shapes.js
+41
-5
41 additions, 5 deletions
src/shapes.js
with
41 additions
and
5 deletions
src/shapes.js
+
41
−
5
View file @
3f21fb08
...
...
@@ -73,12 +73,48 @@ function boundingCoords(points) {
}
}
const
LINE_Q
=
10
function
vectorLength
([
x
,
y
])
{
return
Math
.
hypot
(
x
,
y
)
}
function
diffVector
([
x0
,
y0
],
[
x1
,
y1
])
{
return
[
x0
-
x1
,
y0
-
y1
]
}
function
angleBetweenVectors
(
p1
,
p2
)
{
const
[[
x0
,
y0
],
[
x1
,
y1
]]
=
[
p1
,
p2
]
return
Math
.
acos
((
x0
*
x1
+
y0
*
y1
)
/
(
vectorLength
(
p1
)
*
vectorLength
(
p2
)))
}
const
LINE_ANGLE_THRESHOLD
=
Math
.
PI
/
4
const
VECTOR_LEN_THRESHOLD
=
400
function
couldBeLine
(
points
)
{
const
{
maxX
,
minX
,
maxY
,
minY
}
=
boundingCoords
(
points
)
const
[
dx
,
dy
]
=
[
maxX
-
minX
,
maxY
-
minY
].
map
((
x
)
=>
x
+
0.00001
)
return
dy
/
dx
>
LINE_Q
||
dx
/
dy
>
LINE_Q
if
(
points
.
length
<
2
)
return
false
const
pivot
=
points
[
0
]
let
cumulativeThreshold
=
0
for
(
let
i
=
2
;
i
<
points
.
length
;
i
++
)
{
const
p1
=
points
[
i
-
1
]
const
p2
=
points
[
i
]
const
d1
=
diffVector
(
pivot
,
p1
)
const
d2
=
diffVector
(
p1
,
p2
)
const
d2Len
=
vectorLength
(
d2
)
if
(
cumulativeThreshold
<
VECTOR_LEN_THRESHOLD
&&
d2Len
<
VECTOR_LEN_THRESHOLD
)
{
cumulativeThreshold
+=
d2Len
continue
}
const
angle
=
angleBetweenVectors
(
d1
,
d2
)
if
(
Math
.
abs
(
angle
)
>
LINE_ANGLE_THRESHOLD
)
{
return
false
}
}
return
true
}
const
MATRIX_SIZE
=
3
...
...
@@ -186,7 +222,7 @@ function recognizeLine(points) {
if
(
!
(
points
&&
points
.
length
))
return
{}
const
accum
=
Array
(
numAngleCells
)
const
houghConfig
=
{
rhoStep
:
points
.
length
>
5
0
?
50
:
5
,
rhoStep
:
points
.
length
>
3
0
?
50
:
5
,
}
points
.
forEach
((
x
)
=>
constructHoughAccumulator
(
houghConfig
,
accum
,
...
x
))
const
angle
=
findMaxInHough
(
accum
,
points
.
length
-
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment