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
No related merge requests found
......@@ -8,7 +8,6 @@ function sin(a) {
return Math.sin(dtor(a))
}
const rhoStep = 5
const angleStep = 10
const numAngleCells = 180 / angleStep
const rhoMax = 1000
......@@ -38,14 +37,14 @@ function findMaxInHough(accum, threshold) {
return undefined
}
function constructHoughAccumulator(accumulator, x, y) {
function constructHoughAccumulator(config, accumulator, x, y) {
for (let thetaIndex = 0; thetaIndex < numAngleCells; thetaIndex++) {
const theta = thetaIndex * angleStep
let rho = x * cos(theta) + y * sin(theta)
rho = Math.floor(rho)
rho += rhoMax
rho >>= 1
rho /= rhoStep
rho /= config.rhoStep
rho = Math.floor(rho)
if (accumulator[thetaIndex] == undefined) accumulator[thetaIndex] = []
if (accumulator[thetaIndex][rho] == undefined) {
......@@ -150,7 +149,10 @@ function recognizeRect(points) {
function recognizeLine(points) {
if (!(points && points.length)) return {}
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)
if (angle !== undefined) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment