question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Limiting false positives

See original GitHub issue

During excessive testing, I found that I get about 5 to 10 percent false positives. But I found out – and I do not think that this is documented - if you check the error of the decodedCodes, you will find that by rejection codes with a certain error margin will increase your hit rate 100 percent.

This is the code I use. I take the average error margin. If it is below 0.1 it is fair to assume we detected the code correct.

So far I had no false positives at all while still a very fast detection.

var countDecodedCodes=0, err=0;
$.each(result.codeResult.decodedCodes, function(id,error){
    if (error.error!=undefined) {
        countDecodedCodes++;
        err+=parseFloat(error.error);
    }
});
if (err/countDecodedCodes < 0.1) {
    // correct code detected
} else {
    // probably wrong code
}

Hope this helps!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:10
  • Comments:15

github_iconTop GitHub Comments

7reactions
sam-lexcommented, May 16, 2018

Based on @iFlash answer, I made it using median instead of averages.

private _getMedian(arr: number[]): number {
  arr.sort((a, b) => a - b);
  const half = Math.floor( arr.length / 2 );
  if (arr.length % 2 === 1) // Odd length
    return arr[ half ];
  return (arr[half - 1] + arr[half]) / 2.0;
}

// Initializers
private _initDetectedHandler() {
  this.onDetectedHandler = (result) => {
    const errors: number[] = result.codeResult.decodedCodes
      .filter(_ => _.error !== undefined)
      .map(_ => _.error);
    const median = this._getMedian( errors );
    if (median < 0.10)
      // probably correct
    else
      // probably wrong
  };

  Quagga.onDetected( this.onDetectedHandler );
}

During my tests (built-in webcam), I noticed that many times it reads correctly, but its averages were all above 0.1 because some of the errors has a much higher value like 0.3 ..0.4 while others are 0.05. .0.07, thus “pulling” the average up.

Medians represents most of the dataset a bit better. That being said, I still get false positives occasionally. Hit rate of probably 7-8/10, but a faster match than averages.

4reactions
reon777commented, Oct 27, 2020

Its good for me.

let codes = []
function _onDetected(result) {
	codes.push(result.codeResult.code)
	if (codes.length < 3) return
	let is_same_all = false;
	if (codes.every(v => v === codes[0])) {
		is_same_all = true;
	}
	if (!is_same_all) {
		codes.shift()
		return
	}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Avoid False Positives and False Negatives ... - ACD/Labs
The most effective way to reduce both your false positives and negatives is using a high-quality method. This is particularly important in ...
Read more >
Limit of Detection; Type I (False Positive) and ... - ConsultGLP
So, when we state “Not Detected (ND) ” for an analyte in our test report, it indicates that this analyte may be present...
Read more >
Practices of Science: False Positives and False Negatives
A false positive is when a scientist determines something is true when it is actually false (also called a type I error).
Read more >
Handling false negatives, false positives and reporting limits in ...
This paper concludes that the z-scoring system is adaptable without change to false negatives and positives, although a degree of statistical expertise is ......
Read more >
How to limit false positives in environmental DNA and ...
Unfortunately, false positives may occur for multiple reasons, such as contamination during sampling or during laboratory work, PCR or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found