Make sure that guard line gets invalidated correctly
This commit is contained in:
parent
4c7deffdfe
commit
30cbfb6ffd
@ -634,9 +634,6 @@ export class Aard {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cornerViolations = [0,0,0,0];
|
|
||||||
let subpixelViolation = false;
|
|
||||||
|
|
||||||
let edgePosition = this.settings.active.arDetect.sampling.edgePosition;
|
let edgePosition = this.settings.active.arDetect.sampling.edgePosition;
|
||||||
const segmentPixels = width * edgePosition;
|
const segmentPixels = width * edgePosition;
|
||||||
const edgeSegmentSize = segmentPixels * 4;
|
const edgeSegmentSize = segmentPixels * 4;
|
||||||
@ -652,14 +649,12 @@ export class Aard {
|
|||||||
|
|
||||||
let i = rowStart;
|
let i = rowStart;
|
||||||
while (i < firstSegment) {
|
while (i < firstSegment) {
|
||||||
subpixelViolation = false;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
imageData[i] > this.testResults.blackThreshold
|
imageData[i] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 1] > this.testResults.blackThreshold
|
|| imageData[i + 1] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 2] > this.testResults.blackThreshold
|
|| imageData[i + 2] > this.testResults.blackThreshold
|
||||||
) {
|
) {
|
||||||
cornerViolations[Corner.TopLeft]++;
|
this.testResults.guardLine.cornerPixelsViolated[Corner.TopLeft]++;
|
||||||
}
|
}
|
||||||
i += 4;
|
i += 4;
|
||||||
}
|
}
|
||||||
@ -669,6 +664,10 @@ export class Aard {
|
|||||||
|| imageData[i + 1] > this.testResults.blackThreshold
|
|| imageData[i + 1] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 2] > this.testResults.blackThreshold
|
|| imageData[i + 2] > this.testResults.blackThreshold
|
||||||
) {
|
) {
|
||||||
|
// DONT FORGET TO INVALIDATE GUARDL LINE
|
||||||
|
this.testResults.guardLine.top = -1;
|
||||||
|
this.testResults.guardLine.bottom = -1;
|
||||||
|
this.testResults.guardLine.invalidated = true;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
i += 4;
|
i += 4;
|
||||||
@ -679,7 +678,7 @@ export class Aard {
|
|||||||
|| imageData[i + 1] > this.testResults.blackThreshold
|
|| imageData[i + 1] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 2] > this.testResults.blackThreshold
|
|| imageData[i + 2] > this.testResults.blackThreshold
|
||||||
) {
|
) {
|
||||||
cornerViolations[Corner.TopRight]++;
|
this.testResults.guardLine.cornerPixelsViolated[Corner.TopRight]++;
|
||||||
}
|
}
|
||||||
i += 4; // skip over alpha channel
|
i += 4; // skip over alpha channel
|
||||||
}
|
}
|
||||||
@ -701,7 +700,7 @@ export class Aard {
|
|||||||
|| imageData[i + 1] > this.testResults.blackThreshold
|
|| imageData[i + 1] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 2] > this.testResults.blackThreshold
|
|| imageData[i + 2] > this.testResults.blackThreshold
|
||||||
) {
|
) {
|
||||||
cornerViolations[Corner.BottomLeft]++;
|
this.testResults.guardLine.cornerPixelsViolated[Corner.BottomLeft]++;
|
||||||
}
|
}
|
||||||
i += 4; // skip over alpha channel
|
i += 4; // skip over alpha channel
|
||||||
}
|
}
|
||||||
@ -714,6 +713,10 @@ export class Aard {
|
|||||||
|| imageData[i + 1] > this.testResults.blackThreshold
|
|| imageData[i + 1] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 2] > this.testResults.blackThreshold
|
|| imageData[i + 2] > this.testResults.blackThreshold
|
||||||
) {
|
) {
|
||||||
|
// DONT FORGET TO INVALIDATE GUARDL LINE
|
||||||
|
this.testResults.guardLine.top = -1;
|
||||||
|
this.testResults.guardLine.bottom = -1;
|
||||||
|
this.testResults.guardLine.invalidated = true;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
i += 4;
|
i += 4;
|
||||||
@ -727,7 +730,7 @@ export class Aard {
|
|||||||
|| imageData[i + 1] > this.testResults.blackThreshold
|
|| imageData[i + 1] > this.testResults.blackThreshold
|
||||||
|| imageData[i + 2] > this.testResults.blackThreshold
|
|| imageData[i + 2] > this.testResults.blackThreshold
|
||||||
) {
|
) {
|
||||||
cornerViolations[Corner.BottomRight]++;
|
this.testResults.guardLine.cornerPixelsViolated[Corner.BottomRight]++;
|
||||||
}
|
}
|
||||||
i += 4; // skip over alpha channel
|
i += 4; // skip over alpha channel
|
||||||
}
|
}
|
||||||
@ -735,21 +738,23 @@ export class Aard {
|
|||||||
|
|
||||||
const maxViolations = segmentPixels * 0.20; // TODO: move the 0.2 threshold into settings
|
const maxViolations = segmentPixels * 0.20; // TODO: move the 0.2 threshold into settings
|
||||||
|
|
||||||
|
console.log('Corner violations counts — segment px & max violations,', segmentPixels, maxViolations )
|
||||||
|
|
||||||
// we won't do a loop for this few elements
|
// we won't do a loop for this few elements
|
||||||
// corners with stuff in them will also be skipped in image test
|
// corners with stuff in them will also be skipped in image test
|
||||||
this.testResults.guardLine.cornerViolations[0] = cornerViolations[0] > maxViolations;
|
this.testResults.guardLine.cornerViolated[0] = this.testResults.guardLine.cornerPixelsViolated[0] > maxViolations;
|
||||||
this.testResults.guardLine.cornerViolations[1] = cornerViolations[1] > maxViolations;
|
this.testResults.guardLine.cornerViolated[1] = this.testResults.guardLine.cornerPixelsViolated[1] > maxViolations;
|
||||||
this.testResults.guardLine.cornerViolations[2] = cornerViolations[2] > maxViolations;
|
this.testResults.guardLine.cornerViolated[2] = this.testResults.guardLine.cornerPixelsViolated[2] > maxViolations;
|
||||||
this.testResults.guardLine.cornerViolations[3] = cornerViolations[3] > maxViolations;
|
this.testResults.guardLine.cornerViolated[3] = this.testResults.guardLine.cornerPixelsViolated[3] > maxViolations;
|
||||||
|
|
||||||
const maxInvalidCorners = 1; // TODO: move this into settings — by default, we allow one corner to extend past the
|
const maxInvalidCorners = 1; // TODO: move this into settings — by default, we allow one corner to extend past the
|
||||||
// guard line in order to prevent watermarks/logos from preventing cropping the video
|
// guard line in order to prevent watermarks/logos from preventing cropping the video
|
||||||
|
|
||||||
// this works because +true converts to 1 and +false converts to 0
|
// this works because +true converts to 1 and +false converts to 0
|
||||||
const dirtyCount = +this.testResults.guardLine.cornerViolations[0]
|
const dirtyCount = +this.testResults.guardLine.cornerViolated[0]
|
||||||
+ +this.testResults.guardLine.cornerViolations[1]
|
+ +this.testResults.guardLine.cornerViolated[1]
|
||||||
+ +this.testResults.guardLine.cornerViolations[2]
|
+ +this.testResults.guardLine.cornerViolated[2]
|
||||||
+ +this.testResults.guardLine.cornerViolations[3];
|
+ +this.testResults.guardLine.cornerViolated[3];
|
||||||
|
|
||||||
if (dirtyCount > maxInvalidCorners) {
|
if (dirtyCount > maxInvalidCorners) {
|
||||||
this.testResults.guardLine.invalidated = true;
|
this.testResults.guardLine.invalidated = true;
|
||||||
@ -799,7 +804,7 @@ export class Aard {
|
|||||||
|
|
||||||
// we don't run image detection in corners that may contain logos, as such corners
|
// we don't run image detection in corners that may contain logos, as such corners
|
||||||
// may not be representative
|
// may not be representative
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopLeft]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopLeft]) {
|
||||||
while (i < firstSegment) {
|
while (i < firstSegment) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -823,7 +828,7 @@ export class Aard {
|
|||||||
};
|
};
|
||||||
i++; // skip over alpha channel
|
i++; // skip over alpha channel
|
||||||
}
|
}
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopRight]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopRight]) {
|
||||||
while (i < rowEnd) {
|
while (i < rowEnd) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -839,7 +844,7 @@ export class Aard {
|
|||||||
|
|
||||||
// we don't run image detection in corners that may contain logos, as such corners
|
// we don't run image detection in corners that may contain logos, as such corners
|
||||||
// may not be representative
|
// may not be representative
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopLeft]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopLeft]) {
|
||||||
while (i < firstSegment) {
|
while (i < firstSegment) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -863,7 +868,7 @@ export class Aard {
|
|||||||
};
|
};
|
||||||
i++; // skip over alpha channel
|
i++; // skip over alpha channel
|
||||||
}
|
}
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopRight]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopRight]) {
|
||||||
while (i < rowEnd) {
|
while (i < rowEnd) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -889,7 +894,7 @@ export class Aard {
|
|||||||
|
|
||||||
// we don't run image detection in corners that may contain logos, as such corners
|
// we don't run image detection in corners that may contain logos, as such corners
|
||||||
// may not be representative
|
// may not be representative
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopLeft]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopLeft]) {
|
||||||
while (i < firstSegment) {
|
while (i < firstSegment) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -913,7 +918,7 @@ export class Aard {
|
|||||||
};
|
};
|
||||||
i++; // skip over alpha channel
|
i++; // skip over alpha channel
|
||||||
}
|
}
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopRight]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopRight]) {
|
||||||
while (i < rowEnd) {
|
while (i < rowEnd) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -929,7 +934,7 @@ export class Aard {
|
|||||||
|
|
||||||
// we don't run image detection in corners that may contain logos, as such corners
|
// we don't run image detection in corners that may contain logos, as such corners
|
||||||
// may not be representative
|
// may not be representative
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopLeft]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopLeft]) {
|
||||||
while (i < firstSegment) {
|
while (i < firstSegment) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -953,7 +958,7 @@ export class Aard {
|
|||||||
};
|
};
|
||||||
i++; // skip over alpha channel
|
i++; // skip over alpha channel
|
||||||
}
|
}
|
||||||
if (! this.testResults.guardLine.cornerViolations[Corner.TopRight]) {
|
if (! this.testResults.guardLine.cornerViolated[Corner.TopRight]) {
|
||||||
while (i < rowEnd) {
|
while (i < rowEnd) {
|
||||||
imagePixel = false;
|
imagePixel = false;
|
||||||
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
imagePixel ||= imageData[i++] > this.testResults.blackThreshold;
|
||||||
@ -1535,7 +1540,9 @@ export class Aard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BOTTOM:
|
// BOTTOM
|
||||||
|
// Note that bottomRows candidates are measured from the top
|
||||||
|
// Well have to invert our candidate after we're done
|
||||||
if (
|
if (
|
||||||
this.testResults.aspectRatioCheck.bottomRows[0] === this.testResults.aspectRatioCheck.bottomRows[1]
|
this.testResults.aspectRatioCheck.bottomRows[0] === this.testResults.aspectRatioCheck.bottomRows[1]
|
||||||
&& this.testResults.aspectRatioCheck.bottomRows[0] === this.testResults.aspectRatioCheck.bottomRows[2]
|
&& this.testResults.aspectRatioCheck.bottomRows[0] === this.testResults.aspectRatioCheck.bottomRows[2]
|
||||||
|
@ -10,7 +10,8 @@ export interface AardTestResults {
|
|||||||
top: number, // is cumulative
|
top: number, // is cumulative
|
||||||
bottom: number, // is cumulative
|
bottom: number, // is cumulative
|
||||||
invalidated: boolean,
|
invalidated: boolean,
|
||||||
cornerViolations: [boolean, boolean, boolean, boolean],
|
cornerViolated: [boolean, boolean, boolean, boolean],
|
||||||
|
cornerPixelsViolated: [0,0,0,0]
|
||||||
},
|
},
|
||||||
imageLine: {
|
imageLine: {
|
||||||
top: number, // is cumulative
|
top: number, // is cumulative
|
||||||
@ -25,6 +26,7 @@ export interface AardTestResults {
|
|||||||
topCandidate: number,
|
topCandidate: number,
|
||||||
topCandidateQuality: number,
|
topCandidateQuality: number,
|
||||||
bottomCandidate: number,
|
bottomCandidate: number,
|
||||||
|
bottomCandidateDistance: number,
|
||||||
bottomCandidateQuality: number,
|
bottomCandidateQuality: number,
|
||||||
},
|
},
|
||||||
aspectRatioUncertain: boolean,
|
aspectRatioUncertain: boolean,
|
||||||
@ -45,7 +47,8 @@ export function initAardTestResults(settings: AardSettings): AardTestResults {
|
|||||||
top: -1,
|
top: -1,
|
||||||
bottom: -1,
|
bottom: -1,
|
||||||
invalidated: false,
|
invalidated: false,
|
||||||
cornerViolations: [false, false, false, false],
|
cornerViolated: [false, false, false, false],
|
||||||
|
cornerPixelsViolated: [0,0,0,0]
|
||||||
},
|
},
|
||||||
imageLine: {
|
imageLine: {
|
||||||
top: -1,
|
top: -1,
|
||||||
@ -60,6 +63,7 @@ export function initAardTestResults(settings: AardSettings): AardTestResults {
|
|||||||
topCandidate: 0,
|
topCandidate: 0,
|
||||||
topCandidateQuality: 0,
|
topCandidateQuality: 0,
|
||||||
bottomCandidate: 0,
|
bottomCandidate: 0,
|
||||||
|
bottomCandidateDistance: 0,
|
||||||
bottomCandidateQuality: 0,
|
bottomCandidateQuality: 0,
|
||||||
},
|
},
|
||||||
aspectRatioUncertain: false,
|
aspectRatioUncertain: false,
|
||||||
@ -76,10 +80,14 @@ export function resetAardTestResults(results: AardTestResults): void {
|
|||||||
results.notLetterbox = false;
|
results.notLetterbox = false;
|
||||||
results.imageLine.invalidated = false;
|
results.imageLine.invalidated = false;
|
||||||
results.guardLine.invalidated = false;
|
results.guardLine.invalidated = false;
|
||||||
results.guardLine.cornerViolations[0] = false;
|
results.guardLine.cornerViolated[0] = false;
|
||||||
results.guardLine.cornerViolations[1] = false;
|
results.guardLine.cornerViolated[1] = false;
|
||||||
results.guardLine.cornerViolations[2] = false;
|
results.guardLine.cornerViolated[2] = false;
|
||||||
results.guardLine.cornerViolations[3] = false;
|
results.guardLine.cornerViolated[3] = false;
|
||||||
|
results.guardLine.cornerPixelsViolated[0] = 0;
|
||||||
|
results.guardLine.cornerPixelsViolated[1] = 0;
|
||||||
|
results.guardLine.cornerPixelsViolated[2] = 0;
|
||||||
|
results.guardLine.cornerPixelsViolated[3] = 0;
|
||||||
results.letterboxWidth = 0;
|
results.letterboxWidth = 0;
|
||||||
results.letterboxOffset = 0;
|
results.letterboxOffset = 0;
|
||||||
results.aspectRatioUpdated = false;
|
results.aspectRatioUpdated = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user