Skip to content
Snippets Groups Projects
Commit 05429a34 authored by Yuriy Maksymets's avatar Yuriy Maksymets
Browse files

Configurable rho step

parent 40f0f158
No related branches found
No related tags found
1 merge request!65Simple shape recognition
Pipeline #104987 failed
...@@ -8,7 +8,6 @@ function sin(a) { ...@@ -8,7 +8,6 @@ function sin(a) {
return Math.sin(dtor(a)) return Math.sin(dtor(a))
} }
const rhoStep = 5
const angleStep = 10 const angleStep = 10
const numAngleCells = 180 / angleStep const numAngleCells = 180 / angleStep
const rhoMax = 1000 const rhoMax = 1000
...@@ -38,14 +37,14 @@ function findMaxInHough(accum, threshold) { ...@@ -38,14 +37,14 @@ function findMaxInHough(accum, threshold) {
return undefined return undefined
} }
function constructHoughAccumulator(accumulator, x, y) { function constructHoughAccumulator(config, accumulator, x, y) {
for (let thetaIndex = 0; thetaIndex < numAngleCells; thetaIndex++) { for (let thetaIndex = 0; thetaIndex < numAngleCells; thetaIndex++) {
const theta = thetaIndex * angleStep const theta = thetaIndex * angleStep
let rho = x * cos(theta) + y * sin(theta) let rho = x * cos(theta) + y * sin(theta)
rho = Math.floor(rho) rho = Math.floor(rho)
rho += rhoMax rho += rhoMax
rho >>= 1 rho >>= 1
rho /= rhoStep rho /= config.rhoStep
rho = Math.floor(rho) rho = Math.floor(rho)
if (accumulator[thetaIndex] == undefined) accumulator[thetaIndex] = [] if (accumulator[thetaIndex] == undefined) accumulator[thetaIndex] = []
if (accumulator[thetaIndex][rho] == undefined) { if (accumulator[thetaIndex][rho] == undefined) {
...@@ -150,7 +149,10 @@ function recognizeRect(points) { ...@@ -150,7 +149,10 @@ function recognizeRect(points) {
function recognizeLine(points) { function recognizeLine(points) {
if (!(points && points.length)) return {} if (!(points && points.length)) return {}
const accum = Array(numAngleCells) const accum = Array(numAngleCells)
points.forEach((x) => constructHoughAccumulator(accum, ...x)) const houghConfig = {
rhoStep: points.length > 100 ? 50 : 5,
}
points.forEach((x) => constructHoughAccumulator(houghConfig, accum, ...x))
const angle = findMaxInHough(accum, points.length - 1) const angle = findMaxInHough(accum, points.length - 1)
if (angle !== undefined) { if (angle !== undefined) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment