我有一个从视频中检索帧的应用程序,这些帧很多。我想使用批量图像标注来优化性能,但它是否也具有成本效益? 批量图像注释http请求= 1个事务或批次中的图像数量?
我目前正在使用谷歌云视觉网络检测功能,该功能会发送所有图像的单独 api 请求,它对我来说效果很好。但我正在寻找更具成本效益的选择。
exports.analyzemultipleFrames = async fileList => {
let cloudVisionFrames = [];
const filteredFramesToVision = fileList.filter((file, index) => {
let filterFrame = false;
if (index % appConstants.frameCountAnalyse == 0) {
filterFrame = true;
}
return filterFrame;
});
const analyzeFramesPromise = await filteredFramesToVision.map(async file => {
const imageAnalysisout = await analyzeFrame(file.fullPath);
cloudVisionFrames.push(file.fileName);
return imageAnalysisout;
});
const frameAnalysisResult = await Promise.all(analyzeFramesPromise);
return {
cloudVisionFrames: cloudVisionFrames,
frameAnalysisResult: frameAnalysisResult
};
};
exports.analyzeResubmittedFrames = async (framesArr) => {
let cloudVisionFrames = [];
const analyzeFramesPromise = await framesArr.map(async file => {
const imageAnalysisout = await analyzeSingleFrame(file);
cloudVisionFrames.push(file);
return imageAnalysisout;
});
const frameAnalysisResult = await Promise.all(analyzeFramesPromise);
return {
cloudVisionFrames: cloudVisionFrames,
frameAnalysisResult: frameAnalysisResult
};
}
async function analyzeFrame(file) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async resolve => {
fs.readFile(file, async (err, data) => {
if (err) {
resolve({ frameAnalysis: {}, frame: file });
}
let base64String = Buffer.from(data).toString("base64");
let request = {
image: { content: base64String },
features: appConstants.cloudVisionFeatures
};
try {
const [result] = await visionAnnotateClient.annotateImage(request);
resolve({ frameAnalysis: result, frame: file });
} catch (err) {
logger("Vision Error" + err);
resolve({ frameAnalysis: {}, frame: file });
}
//implement google cloud vision logic to getch files
});
});
}
async function analyzeSingleFrame(file) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async resolve => {
let request = {
image: { source: { imageUri: file } },
features: appConstants.cloudVisionFeatures
};
try {
const [result] = await visionAnnotateClient.annotateImage(request);
resolve({ frameAnalysis: result, frame: file });
} catch (err) {
logger("Single Frame Vision ERROR" + err);
resolve({ frameAnalysis: {}, frame: file });
}
//implement google cloud vision logic to getch files
});
};
发送到 API 的每张图片均需付费。