jeresig/node-pastec

语言: JavaScript

git: https://github.com/jeresig/node-pastec

用于使用Pastec服务器的节点模块。
Node module for using a Pastec server.
README.md (中文)

对不起,c

节点模块,用于与Pastec服务器交互。

var pastec = require("pastec")({
    server: "localhost:4212"
});

pastec.add("test.jpg", "1234", function() {
    pastec.fileSimilar("test.jpg", function(err, matches) {
        console.log("Similar images:");
        matches.forEach(function(item) {
            console.log(" - ", item.filepath);
        });
    });
});

安装

npm install pastec

API

add(fileName,id,callback)

将映像文件上载到Pastec服务器并为其分配指定的ID以供以后检索。例如,如果您要上传:

add("/var/data/test.jpg", "1234")

您应该在Pastec索引中得到ID为1234的文件。

fileSimilar(filePath,callback)

给定图像文件的路径,从数据库返回类似图像的数组(格式与urlSimilar()方法相同)。例如:

pastec.fileSimilar("test.jpg", function(err, matches) {
    matches.forEach(function(match) {
        console.log(match.filepath + " " + match.score + "% match.");
    });
});

图像未添加到Pastec索引。作为匹配返回的对象看起来像这样:

{
    "filepath":"./3107100095036_002.jpg",
    "rects":{"height":636,"width":421,"x":43,"y":62},
    "score":42
}

urlSimilar(url,callback)

给定图像的URL,从数据库返回类似图像的数组(格式与fileSimilar()方法相同)。例如:

pastec.urlSimilar("http://test.com/test.jpg", function(err, matches) {
    matches.forEach(function(match) {
        console.log(match.id + " " + match.score + "% match.");
    });
});

指定URL处的图像未添加到Pastec索引。作为匹配返回的对象看起来像这样:

{
    "id":"./3107100095036_002.jpg",
    "rect":{"height":636,"width":421,"x":43,"y":62},
    "score":42
}

del(ID,回调)

给定指定的Pastec文件ID(例如1234),从索引中删除该特定图像。它将不再在结果中返回。

列表(回调)

返回一个对象,该对象包含当前在索引中的所有ID。

saveIndex(indexFile,callback)

将图像相似性索引保存到指定indexFile位置的服务器。请注意,indexFile的路径是相对于服务器的路径,而不是本地环境。

积分

由John Resig创建。

根据MIT许可证发布。

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

node-pastec

Node module for interacting with a Pastec server.

var pastec = require("pastec")({
    server: "localhost:4212"
});

pastec.add("test.jpg", "1234", function() {
    pastec.fileSimilar("test.jpg", function(err, matches) {
        console.log("Similar images:");
        matches.forEach(function(item) {
            console.log(" - ", item.filepath);
        });
    });
});

Installation

npm install pastec

API

add(fileName, id, callback)

Upload an image file to a Pastec server and assign it the specified ID for later retrieval. For example if you were to upload:

add("/var/data/test.jpg", "1234")

You should end up with a file with an ID of: 1234 in the Pastec index.

fileSimilar(filePath, callback)

Given the path to an image file, return an array of similar images from the database (in the same format as the urlSimilar() method). For example:

pastec.fileSimilar("test.jpg", function(err, matches) {
    matches.forEach(function(match) {
        console.log(match.filepath + " " + match.score + "% match.");
    });
});

The image is not added to the Pastec index. The object returned as a match would look something like this:

{
    "filepath":"./3107100095036_002.jpg",
    "rects":{"height":636,"width":421,"x":43,"y":62},
    "score":42
}

urlSimilar(url, callback)

Given the URL of an image, return an array of similar images from the database (in the same format as the fileSimilar() method). For example:

pastec.urlSimilar("http://test.com/test.jpg", function(err, matches) {
    matches.forEach(function(match) {
        console.log(match.id + " " + match.score + "% match.");
    });
});

The image at the specified URL is not added to the Pastec index. The object returned as a match would look something like this:

{
    "id":"./3107100095036_002.jpg",
    "rect":{"height":636,"width":421,"x":43,"y":62},
    "score":42
}

del(ID, callback)

Given a specified Pastec file ID (for example 1234), delete that particular image from the index. It will no longer be returned in the results.

list(callback)

Returns an object that holds all the IDs that are currently in the index.

saveIndex(indexFile, callback)

Save the image similarity index to the server at the specified indexFile location. Note that the path to the indexFile is to a path relative to the server, not the local environment.

Credits

Created by John Resig.

Released under an MIT license.