NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true") NOT_TRAVIS <- !identical(Sys.getenv("TRAVIS"), "true") NOT_APPVEYOR <- !identical(Sys.getenv("APPVEYOR"), "True") RUN_CHUNK <- all(NOT_CRAN, NOT_TRAVIS, NOT_APPVEYOR)
Pastec is an open-source image matching engine that does Google-images-esque fuzzy searching of a database of images that you compile. It is very good at finding close-but-not-exact matches, such as different versions of a photograph, or rotated, cropped, or resized versions of images.
PastecR provides a wrapper around the Pastec API, which can be particularly useful when parsing the results returned by an image search request.
library(PastecR) # open_pastec_server defaults to the same port defaults as Pastec ops <- open_pastec_server(url = "localhost", port = 4212) # You can find the index_id and auth_key for your api.pastec.io account at # <https://api.pastec.io/manager/apiPage> hps <- hosted_pastec_server(index_id = "XXXXXXXXXXXXXXXXXXXX", auth_key = "XXXXXXXXXXXXXXXXXXXX")
We'll be using a number of artowrks for this example, including three different versions of a print.
Once you have established either your own instance of Pastec, or an account at https://api.pastec.io, you may add images with the
You must set an integer
image_id when adding.
# Get image paths erasmus1 <- system.file("img", "RP-P-1906-1485.jpg", package = "PastecR") erasmus2 <- system.file("img", "RP-P-1906-1486.jpg", package = "PastecR") erasmus3 <- system.file("img", "RP-P-1906-1487.jpg", package = "PastecR") nightwatch <- system.file("img", "SK-C-5.jpg", package = "PastecR") add_image(erasmus1, 1, ops) add_image(erasmus2, 2, ops) add_image(erasmus3, 3, ops) add_image(nightwatch, 4, ops) # Images can also be removed by index remove_image(4, ops)
Once your index is loaded, you can search for similar images, and parse the results with a number of helper commands.
search_result <- search_image(erasmus1, ops) results_as_data_frame(search_result)
?pastec_response for other parsing functions.
To clear the index, use
On the open, self-hosted version of Pastec, you can also save and load index files to disk by using
At the moment, these commands are not available for the SaaS version of pasted, and will throw an error.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.