Image search in network

To run a reverse image search, use the SearchFirst method of the Searcher class. This method returns the first portion of results as a NetworkImageSearchResult object, which contains the images found in one shard.

To continue the search, the SearchNext method is used, returning the second and subsequent portions of results. Continue the search while the NetworkImageSearchToken property of the result is not null.

The search image object and search options object are the same as those used for single index searches. Images can be found only if image indexing was enabled when the documents were added.

The examples on this page use the master node of a running search network. The following code creates and starts the master node as described on the Search network deployment page; the slave nodes must be started beforehand.

C#

string basePath = @"c:\SearchNetwork\";
int basePort = 49100;

// Loading the search network configuration from a file
Configuration configuration = Configuration.Load(basePath + "Configuration.xml");

// Creating, configuring and starting the master node; the timeouts are specified in milliseconds
SearchNetworkNode node = SearchNetworkNode.CreateMasterNode(
    0,
    basePath + "Node0",
    new TcpSettings(basePort, 3000, 3000, 3000, 1000),
    new FileLogger(basePath + "Log.txt", 4.0),
    configuration);
node.ConfigureAllNodes();
node.Start();

The following code example, which continues the previous one, demonstrates performing a reverse image search on the search network.

C#

// Creating a search image from a file
SearchImage searchImage = SearchImage.Create(@"c:\MyDocuments\Image.png");
int hashDifferences = 8; // The maximum allowed difference between the image hashes

Console.WriteLine("First image search");

Searcher searcher = node.Searcher;
ImageSearchOptions options = new ImageSearchOptions();
options.HashDifferences = hashDifferences;
int total = 0;

NetworkImageSearchResult result = searcher.SearchFirst(searchImage, options);
Console.WriteLine("Images found (shard " + result.ShardIndex + "): " + result.ImageCount);
total += result.ImageCount;

while (result.NetworkImageSearchToken != null)
{
    Console.WriteLine();
    Console.WriteLine("Next image search");

    result = searcher.SearchNext(result.NetworkImageSearchToken);
    Console.WriteLine("Images found (shard " + result.ShardIndex + "): " + result.ImageCount);
    total += result.ImageCount;
}

Console.WriteLine();
Console.WriteLine("Total images found (diffs = " + hashDifferences + "): " + total);

More information about reverse image search can be found on the Reverse image search page.

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.