Skip to content

Commit adce3b0

Browse files
authored
Merge pull request #152 from watson-developer-cloud/de-430-similaritySearch
De 430 similarity search
2 parents ac2e850 + c6c2a50 commit adce3b0

File tree

5 files changed

+2196
-405
lines changed

5 files changed

+2196
-405
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
Change Log
22
==========
3+
## Version 0.10.0
4+
_2016_09_23_
5+
6+
* New: Added `similarity search` to the `Visual Recognition` service.
7+
* Fix: `Touch Widget` improvmements.
8+
* Fix: Disabled 3rd Party plugin warnings.
9+
* Fix: Removed `Conversation` Message overload method that takes only input and conversationID.
10+
* Fix: Rewrote `Conversation` example script to show how to create MessageRequest object.
11+
312
## Version 0.9.0
413
_2016-08-26_
514

README.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,251 @@ private void OnRecognizeText(TextRecogTopLevelMultiple multipleImages)
729729
}
730730
```
731731

732+
#### Similarity Search
733+
Beta. You can create and add images to a collection and then search that collection with your own image to find similar images.
734+
735+
##### List Collections
736+
Beta. List all custom collections.
737+
738+
```cs
739+
void Start()
740+
{
741+
m_VisualRecognition.GetCollections(OnGetCollections);
742+
}
743+
744+
private void OnGetCollections(GetCollections collections, string customData)
745+
{
746+
if(collections != null)
747+
{
748+
foreach (CreateCollection collection in collections.collections)
749+
{
750+
Log.Debug("VisualRecognitionExample", "collectionID: {0} | collection name: {1} | number of images: {2}", collection.collection_id, collection.name, collection.images);
751+
}
752+
}
753+
else
754+
{
755+
Log.Debug("VisualRecognitionExample", "Get Collections failed!");
756+
}
757+
}
758+
```
759+
760+
##### Create Collection
761+
Beta. Create a new collection of images to search. You can create a maximum of 5 collections.
762+
763+
```cs
764+
void Start()
765+
{
766+
m_VisualRecognition.CreateCollection(OnCreateCollection, "unity-integration-test-collection");
767+
}
768+
769+
private void OnCreateCollection(CreateCollection collection, string customData)
770+
{
771+
if(collection != null)
772+
{
773+
Log.Debug("VisualRecognitionExample", "Create Collection succeeded!");
774+
Log.Debug("VisualRecognitionExample", "collectionID: {0} | collection name: {1} | collection images: {2}", collection.collection_id, collection.name, collection.images);
775+
}
776+
else
777+
{
778+
Log.Debug("VisualRecognitionExample", "Create Collection failed!");
779+
}
780+
}
781+
```
782+
783+
##### Get collection details
784+
Beta. Retrieve information about a specific collection.
785+
786+
```cs
787+
void Start()
788+
{
789+
m_VisualRecognition.GetCollection(OnGetCollection, m_CreatedCollectionID);
790+
}
791+
792+
private void OnGetCollection(CreateCollection collection, string customData)
793+
{
794+
if (collection != null)
795+
{
796+
Log.Debug("VisualRecognitionExample", "Get Collection succeded!");
797+
Log.Debug("VisualRecognitionExample", "collectionID: {0} | collection name: {1} | collection images: {2}", collection.collection_id, collection.name, collection.images);
798+
}
799+
else
800+
{
801+
Log.Debug("VisualRecognitionExample", "Get Collection failed!");
802+
803+
}
804+
}
805+
```
806+
807+
##### Add images to a collection
808+
Beta. Add images to a collection. Each collection can contain 1000000 images.
809+
810+
```cs
811+
void Start()
812+
{
813+
string m_collectionImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg";
814+
Dictionary<string, string> imageMetadata = new Dictionary<string, string>();
815+
imageMetadata.Add("key1", "value1");
816+
imageMetadata.Add("key2", "value2");
817+
imageMetadata.Add("key3", "value3");
818+
m_VisualRecognition.AddCollectionImage(OnAddImageToCollection, m_CreatedCollectionID, m_collectionImagePath, imageMetadata);
819+
}
820+
private void OnAddImageToCollection(CollectionsConfig images, string customData)
821+
{
822+
if(images != null)
823+
{
824+
Log.Debug("VisualRecognitionExample", "Add image to collection succeeded!");
825+
m_CreatedCollectionImage = images.images[0].image_id;
826+
Log.Debug("VisualRecognitionExample", "images processed: {0}", images.images_processed);
827+
foreach (CollectionImagesConfig image in images.images)
828+
Log.Debug("VisualRecognitionExample", "imageID: {0} | image_file: {1} | image metadata: {1}", image.image_id, image.image_file, image.metadata.ToString());
829+
}
830+
else
831+
{
832+
Log.Debug("VisualRecognitionExample", "Add image to collection failed!");
833+
}
834+
}
835+
```
836+
837+
##### List images in a collection
838+
Beta. List the first 100 images in a collection. Each collection can contain 1000000 images.
839+
840+
```cs
841+
void Start()
842+
{
843+
m_VisualRecognition.GetCollectionImages(OnGetCollectionImages, m_CreatedCollectionID);
844+
}
845+
846+
private void OnGetCollectionImages(GetCollectionImages collections, string customData)
847+
{
848+
if(collections != null)
849+
{
850+
Log.Debug("VisualRecognitionExample", "Get Collections succeded!");
851+
foreach(GetCollectionsBrief collection in collections.images)
852+
Log.Debug("VisualRecognitionExample", "imageID: {0} | image file: {1} | image metadataOnGetCollections: {2}", collection.image_id, collection.image_file, collection.metadata.ToString());
853+
}
854+
else
855+
{
856+
Log.Debug("VisualRecognitionExample", "Get Collections failed!");
857+
}
858+
}
859+
```
860+
861+
##### List image details
862+
Beta. List details about a specific image in a collection.
863+
```cs
864+
void Start()
865+
{
866+
m_VisualRecognition.GetImage(OnGetImage, m_CreatedCollectionID, m_CreatedCollectionImage);
867+
}
868+
869+
private void OnGetImage(GetCollectionsBrief image, string customData)
870+
{
871+
if(image != null)
872+
{
873+
Log.Debug("VisualRecognitionExample", "GetImage succeeded!");
874+
Log.Debug("VisualRecognitionExample", "imageID: {0} | created: {1} | image_file: {2} | metadata: {3}", image.image_id, image.created, image.image_file, image.metadata);
875+
}
876+
else
877+
{
878+
Log.Debug("VisualRecognitionExample", "GetImage failed!");
879+
}
880+
}
881+
```
882+
883+
##### List image metadata
884+
Beta. View the metadata for a specific image in a collection.
885+
886+
```cs
887+
void Start()
888+
{
889+
m_VisualRecognition.GetMetadata(OnGetMetadata, m_CreatedCollectionID, m_CreatedCollectionImage);
890+
}
891+
892+
private void OnGetMetadata(object responseObject, string customData)
893+
{
894+
if(responseObject != null)
895+
Log.Debug("VisualRecognitionExample", "ResponseObject: {0}", responseObject);
896+
}
897+
```
898+
899+
##### Find similar images
900+
Beta. Upload an image to find similar images in your custom collection.
901+
902+
```cs
903+
void Start()
904+
{
905+
m_VisualRecognition.FindSimilar(OnFindSimilar, m_CreatedCollectionID, m_collectionImagePath);
906+
}
907+
908+
private void OnFindSimilar(SimilarImagesConfig images, string customData)
909+
{
910+
if(images != null)
911+
{
912+
Log.Debug("VisualRecognitionExample", "GetSimilar succeeded!");
913+
Log.Debug("VisualRecognitionExample", "images processed: {0}", images.images_processed);
914+
foreach (SimilarImageConfig image in images.similar_images)
915+
Log.Debug("VisualRecognitionExample", "image ID: {0} | image file: {1} | score: {2} | metadata: {3}", image.image_id, image.image_file, image.score, image.metadata.ToString());
916+
}
917+
else
918+
{
919+
Log.Debug("VisualRecognitionExample", "GetSimilar failed!");
920+
}
921+
}
922+
```
923+
924+
##### Delete image metadata
925+
Beta. Delete all metadata associated with an image.
926+
927+
```cs
928+
void Start()
929+
{
930+
m_VisualRecognition.DeleteCollectionImageMetadata(OnDeleteMetadata, m_CreatedCollectionID, m_CreatedCollectionImage);
931+
}
932+
933+
private void OnDeleteMetadata(bool success, string customData)
934+
{
935+
if (success)
936+
Log.Debug("VisualRecognitionExample", "Delete image metadata succeeded!");
937+
else
938+
Log.Debug("VisualRecognitionExample", "Delete image metadata failed!");
939+
}
940+
```
941+
942+
##### Delete an image
943+
Beta. Delete an image from a collection.
944+
945+
```cs
946+
void Start()
947+
{
948+
m_VisualRecognition.DeleteCollectionImage(OnDeleteCollectionImage, m_CreatedCollectionID, m_CreatedCollectionImage);
949+
}
950+
951+
private void OnDeleteCollectionImage(bool success, string customData)
952+
{
953+
if (success)
954+
Log.Debug("VisualRecognitionExample", "Delete collection image succeeded!");
955+
else
956+
Log.Debug("VisualRecognitionExample", "Delete collection image failed!");
957+
}
958+
```
959+
960+
##### Delete a collection
961+
Beta. Delete a user created collection.
962+
963+
```cs
964+
void Start()
965+
{
966+
m_VisualRecognition.DeleteCollection(OnDeleteCollection, m_CreatedCollectionID);
967+
}
968+
969+
private void OnDeleteCollection(bool success, string customData)
970+
{
971+
if(success)
972+
Log.Debug("VisualRecognitionExample", "Delete Collection succeeded!");
973+
else
974+
Log.Debug("VisualRecognitionExample", "Delete Collection failed!");
975+
}
976+
```
732977

733978
### Alchemy Language
734979
Use the [Alchemy Language][alchemy_language] service to extract semantic meta-data from content such as information on people, places, companies, topics, facts, relationships, authors and languages.

0 commit comments

Comments
 (0)