mirror of
https://github.com/lovell/sharp.git
synced 2025-07-13 04:20:12 +02:00
Improve smartcrop saliency testing/reporting
This commit is contained in:
parent
0144358afb
commit
4cff62258c
@ -7,7 +7,6 @@ const async = require('async');
|
|||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
|
|
||||||
const crops = {
|
const crops = {
|
||||||
centre: sharp.gravity.centre,
|
|
||||||
entropy: sharp.strategy.entropy,
|
entropy: sharp.strategy.entropy,
|
||||||
attention: sharp.strategy.attention
|
attention: sharp.strategy.attention
|
||||||
};
|
};
|
||||||
@ -34,23 +33,35 @@ async.eachLimit(files, concurrency, function (file, done) {
|
|||||||
const salientHeight = userData[file].bottom - userData[file].top;
|
const salientHeight = userData[file].bottom - userData[file].top;
|
||||||
sharp(filename).metadata(function (err, metadata) {
|
sharp(filename).metadata(function (err, metadata) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
|
const marginWidth = metadata.width - salientWidth;
|
||||||
|
const marginHeight = metadata.height - salientHeight;
|
||||||
async.each(Object.keys(crops), function (crop, done) {
|
async.each(Object.keys(crops), function (crop, done) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
// Left edge accuracy
|
// Left edge accuracy
|
||||||
function (done) {
|
function (done) {
|
||||||
sharp(filename).resize(salientWidth, metadata.height).crop(crops[crop]).toBuffer(function (err, data, info) {
|
if (marginWidth) {
|
||||||
const accuracy = Math.round(Math.abs(userData[file].left - info.cropCalcLeft) / (metadata.width - salientWidth) * 100);
|
sharp(filename).resize(salientWidth, metadata.height).crop(crops[crop]).toBuffer(function (err, data, info) {
|
||||||
incrementScore(accuracy, crop);
|
const delta = Math.abs(userData[file].left + info.cropOffsetLeft);
|
||||||
done(err);
|
const accuracy = Math.round(marginWidth / (marginWidth + delta) * 100);
|
||||||
});
|
incrementScore(accuracy, crop);
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// Top edge accuracy
|
// Top edge accuracy
|
||||||
function (done) {
|
function (done) {
|
||||||
sharp(filename).resize(metadata.width, salientHeight).crop(crops[crop]).toBuffer(function (err, data, info) {
|
if (marginHeight) {
|
||||||
const accuracy = Math.round(Math.abs(userData[file].top - info.cropCalcTop) / (metadata.height - salientHeight) * 100);
|
sharp(filename).resize(metadata.width, salientHeight).crop(crops[crop]).toBuffer(function (err, data, info) {
|
||||||
incrementScore(accuracy, crop);
|
const delta = Math.abs(userData[file].top + info.cropOffsetTop);
|
||||||
done(err);
|
const accuracy = Math.round(marginHeight / (marginHeight + delta) * 100);
|
||||||
});
|
incrementScore(accuracy, crop);
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
], done);
|
], done);
|
||||||
}, done);
|
}, done);
|
||||||
@ -60,7 +71,7 @@ async.eachLimit(files, concurrency, function (file, done) {
|
|||||||
Object.keys(scores).forEach(function (accuracy) {
|
Object.keys(scores).forEach(function (accuracy) {
|
||||||
report.push(
|
report.push(
|
||||||
Object.assign({
|
Object.assign({
|
||||||
accuracy: parseInt(accuracy, 10)
|
accuracy: Number(accuracy)
|
||||||
}, scores[accuracy])
|
}, scores[accuracy])
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user