Skip to content

Commit

Permalink
Improve perspective calculation #48
Browse files Browse the repository at this point in the history
  • Loading branch information
piderman314 committed Jun 19, 2023
1 parent a57f997 commit 44711e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/detect/linescan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,24 +495,23 @@ fn find_qr_internal(
}

// Estimate distance between finders, in module count
let mut dist = ((dist(one, three) / module_size) + 7.0) as u32;
let estimated_dist = (dist(one, three) / module_size) + 7.0;

trace!("DIST {}", dist);
trace!("ESTIMATED DIST {}", estimated_dist);

// The actual distance is always a value of 4*n + 1 so we'll try to find the n that matchest most closely
let n = ((estimated_dist - 1.0) / 4.0).round() as u32;

// Now recalculate the best guess of the actual distance based on the above n
let dist = 4 * n + 1;

trace!("ESTIMATED ACTUAL DIST {}", dist);

// QR codes are at least 21 modules wide so discard any that are smaller
if dist < 20 {
return None;
}

// Since the distance in modules between finders needs to be a multiple of 4 plus one, adjust our estimate if it doesn't conform
dist = match dist % 4 {
0 => dist + 1,
1 => dist,
2 => dist - 1,
3 => dist - 2,
_ => return None,
};

// QR might be mirrored, in that case store the finders the other way around
if perpendicular > 0.0 {
Some(QRLocation {
Expand Down
2 changes: 2 additions & 0 deletions src/extract/qr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ impl QRExtractor {

impl Extract<GrayImage, QRLocation, QRData, QRError> for QRExtractor {
fn extract(&self, prepared: &GrayImage, loc: QRLocation) -> Result<QRData, QRError> {
debug!("LOC {:?}", loc);

let size = 17 + loc.version * 4;
let p = determine_perspective(prepared, loc.version, size, &loc)?;

Expand Down

0 comments on commit 44711e2

Please sign in to comment.