/** * fun 标签:img-bounding-box-location * * 在完整截图中查找区域截图的位置,返回区域包围框的四个顶点坐标。 */ function matchImageRegionLocation() { return { success: false, error: 'matchImageRegionLocation 需在主进程实现' } } const tagName = 'img-bounding-box-location' const schema = { description: '在完整截图中查找区域截图的位置,返回区域的四个顶点坐标(左上、右上、左下、右下)。', inputs: { screenshot: '完整截图路径(相对于工作流目录)', region: '区域截图路径(相对于工作流目录)', variable: '输出变量名(保存四个顶点坐标)', }, outputs: { variable: '四个顶点坐标对象 {topLeft: {x, y}, topRight: {x, y}, bottomLeft: {x, y}, bottomRight: {x, y}}', }, }; /** * 执行 img-bounding-box-location 功能 */ async function executeImgBoundingBoxLocation({ device, screenshot, region, folderPath }) { let screenshotPath = screenshot; if (screenshot === null) { screenshotPath = '__AUTO_SCREENSHOT__'; } else if (screenshot) { screenshotPath = screenshot.startsWith('/') || screenshot.includes(':') ? screenshot : `${folderPath}/resources/${screenshot}`; } const regionPath = region.startsWith('/') || region.includes(':') ? region : `${folderPath}/resources/${region}`; const result = matchImageRegionLocation(screenshotPath, regionPath, device); if (!result.success) { return { success: false, error: result.error }; } const { x, y, width, height } = result; const corners = { topLeft: { x, y }, topRight: { x: x + width, y }, bottomLeft: { x, y: y + height }, bottomRight: { x: x + width, y: y + height }, }; return { success: true, corners, bounds: { x, y, width, height }, }; } module.exports = { tagName, schema, executeImgBoundingBoxLocation };