In this sample, we:
use an existing MediaCollection to select a MediaObject to use as a source for the search
perform the search
retrieve and display the resulting images.
// create
a MediaCollection object to hold the MediaCollection on disk
MediaCollection
mediaCollection = (MediaCollection) Eve.newMediaCollection();
try
{
// open the collection and get the keys
mediaCollection.open ("\\temp\\myCollection");
long results[] = mediaCollection.getKeys();
// make a MediaObject to hold the query image
MediaObject mediaObject = (MediaObject) Eve.newMediaObject();
mediaObject = mediaCollection.getMediaObject (results[0]);
// make a SearchParameters object
SearchParameters searchParameters = (SearchParameters) Eve.newSearchParameters();
// set the parameters to do a 50-50 shape and texture search
searchParameters.setSearch(Eve.SHAPE, true, 0.5);
searchParameters.setSearch(Eve.TEXTURE, true, 0.5);
// make a SearchResults object
SearchResults searchResults[] = mediaCollection.search
(mediaObject, searchParameters);
// iterate through the results and output the filenames
for (i = 0; i < searchResults.length; i++)
{
MediaObject temp = mediaCollection.getMediaObject
(searchResults[i].getKey());
String filename = (String) temp.getProperty("originalFile");
System.out.println(
"Target: " + i + " File: " + filename +
" : " + searchResults[i]);
// if everything checks out, raise the flag
if (mediaObject.getKey() == searchResults[i].getKey())
flag = true;
}
// close the collection
mediaCollection.close();
// report our final status
if (flag)
System.out.println("EDFSearchTest: OK");
else
System.out.println("EDFSearchTest: Error: Find Failed");
}
catch
(Exception e)
{
System.out.println("Error: " + e);
e.printStackTrace();
System.out.println("EDFSearchTest: Error");
try
{
// always try to close the collection
mediaCollection.close();
}
catch (Exception ignore)
{
}
}