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
hlgr
drawing-app
Commits
0d7603d5
Commit
0d7603d5
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
Visual representation of recognized line
parent
4a2642ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app.js
+17
-0
17 additions, 0 deletions
src/app.js
src/shapes.js
+4
-1
4 additions, 1 deletion
src/shapes.js
with
21 additions
and
1 deletion
src/app.js
+
17
−
0
View file @
0d7603d5
...
...
@@ -7,6 +7,7 @@ import * as canvas from "./canvas.js"
import
*
as
HTML
from
"
./elements.js
"
import
{
connect
}
from
"
./room.js
"
import
*
as
toolSelection
from
"
./tool-selection.js
"
import
recognizeFromPoints
from
"
./shapes.js
"
const
TEST_ROOM
=
"
imperial
"
...
...
@@ -101,9 +102,25 @@ const onRoomConnect = (room_) => {
room
.
addEventListener
(
"
addOrUpdatePath
"
,
({
detail
:
{
id
,
points
}
})
=>
{
canvas
.
renderPath
(
id
,
points
)
drawRecognized
(
points
)
})
}
const
mp
=
(
x
,
y
)
=>
[
x
,
y
,
1
,
"
black
"
,
true
]
function
drawRecognized
(
points
)
{
const
recognizedShape
=
recognizeFromPoints
(
points
)
if
(
recognizedShape
.
shape
)
{
console
.
log
(
recognizedShape
)
const
[
x
,
y
]
=
points
[
0
]
const
a
=
(
recognizedShape
.
angle
*
Math
.
PI
)
/
180
const
[
x0
,
y0
]
=
[
x
-
2000
*
Math
.
cos
(
a
),
y
+
2000
*
Math
.
sin
(
a
)]
const
[
x1
,
y1
]
=
[
x
+
2000
*
Math
.
cos
(
a
),
y
-
2000
*
Math
.
sin
(
a
)]
canvas
.
renderPath
(
"
lastRecognizedLine
"
,
[
mp
(
x0
,
y0
),
mp
(
x1
,
y1
)])
}
else
{
canvas
.
renderPath
(
"
lastRecognizedLine
"
,
[])
}
}
const
tryRoomConnect
=
async
(
roomID
)
=>
{
return
await
connect
(
roomID
)
.
then
(
onRoomConnect
)
...
...
This diff is collapsed.
Click to expand it.
src/shapes.js
+
4
−
1
View file @
0d7603d5
...
...
@@ -9,7 +9,7 @@ function sin(a) {
}
const
rhoStep
=
5
const
angleStep
=
rhoStep
*
2
const
angleStep
=
10
const
numAngleCells
=
180
/
angleStep
const
rhoMax
=
1000
...
...
@@ -18,6 +18,7 @@ function findMaxInHough(accum, threshold) {
// let bestRho = 0
let
bestTheta
=
0
for
(
let
i
=
0
;
i
<
numAngleCells
;
i
++
)
{
if
(
!
accum
[
i
])
continue
for
(
let
j
=
0
;
j
<
accum
[
i
].
length
;
j
++
)
{
if
(
accum
[
i
][
j
]
>
max
)
{
max
=
accum
[
i
][
j
]
...
...
@@ -56,6 +57,7 @@ function constructHoughAccumulator(accumulator, x, y) {
}
function
recognizeFromPoints
(
points
)
{
if
(
!
(
points
&&
points
.
length
))
return
{}
const
accum
=
Array
(
numAngleCells
)
points
.
forEach
((
x
)
=>
constructHoughAccumulator
(
accum
,
...
x
))
const
angle
=
findMaxInHough
(
accum
,
points
.
length
-
1
)
...
...
@@ -64,6 +66,7 @@ function recognizeFromPoints(points) {
return
{
shape
:
Shapes
.
line
,
angle
:
90
-
angle
,
hough
:
accum
,
points
,
}
}
...
...
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