@@ -62,21 +62,6 @@ public VisualRecognitionServiceExample(string apikey)
6262 IsClassifierReady ( _createdClassifierId ) ;
6363 autoEvent . WaitOne ( ) ;
6464 UpdateClassifier ( ) ;
65- //GetCollections();
66-
67- //DeleteDotnetCollections();
68-
69- //CreateCollection();
70- //GetCollection();
71- //GetCollectionImages();
72- //AddCollectionImages();
73- //GetCollectionImage();
74- //GetCollectionImageMetadata();
75- //AddCollectionImageMetadata();
76- //DeleteCollectionImageMetadata();
77- //FindSimilar();
78- //DeleteCollectionImage();
79- //DeleteCollection();
8065 DeleteClassifier ( ) ;
8166
8267 Console . WriteLine ( "\n \n Operation complete" ) ;
@@ -330,282 +315,6 @@ private void UpdateClassifier()
330315 }
331316 }
332317
333- private void GetCollections ( )
334- {
335- Console . WriteLine ( "\n Calling GetCollections()..." ) ;
336-
337- var result = _visualRecognition . GetCollections ( ) ;
338-
339- if ( result != null )
340- {
341- if ( result . Collections != null && result . Collections . Count > 0 )
342- {
343- foreach ( CreateCollection collection in result . Collections )
344- Console . WriteLine ( string . Format ( "name: {0} | collection id: {1} | status: {2}" , collection . Name , collection . CollectionId , collection . Status ) ) ;
345- }
346- else
347- {
348- Console . WriteLine ( "There are no collections." ) ;
349- }
350- }
351- else
352- {
353- Console . WriteLine ( "Result is null." ) ;
354- }
355- }
356-
357- private void CreateCollection ( )
358- {
359- Console . WriteLine ( string . Format ( "\n Calling CreateCollection(\" {0}\" )..." , _collectionNameToCreate ) ) ;
360-
361- var result = _visualRecognition . CreateCollection ( _collectionNameToCreate ) ;
362-
363- if ( result != null )
364- {
365- Console . WriteLine ( string . Format ( "name: {0} | collection id: {1} | status: {2}" , result . Name , result . CollectionId , result . Status ) ) ;
366-
367- _createdCollectionId = result . CollectionId ;
368- }
369- else
370- {
371- Console . WriteLine ( "Result is null." ) ;
372- }
373- }
374-
375- private void DeleteCollection ( )
376- {
377- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
378- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
379-
380- Console . WriteLine ( string . Format ( "\n Calling DeleteCollection(\" {0}\" )..." , _createdCollectionId ) ) ;
381-
382- var result = _visualRecognition . DeleteCollection ( _createdCollectionId ) ;
383-
384- if ( result != null )
385- Console . WriteLine ( string . Format ( "Collection {0} deleted." , _createdCollectionId ) ) ;
386- }
387-
388- private void GetCollection ( )
389- {
390- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
391- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
392-
393- Console . WriteLine ( string . Format ( "\n Calling GetCollection(\" {0}\" )..." , _createdCollectionId ) ) ;
394-
395- var result = _visualRecognition . GetCollection ( _createdCollectionId ) ;
396-
397- if ( result != null )
398- {
399- Console . WriteLine ( string . Format ( "name: {0} | collection id: {1} | status: {2}" , result . Name , result . CollectionId , result . Status ) ) ;
400- }
401- else
402- {
403- Console . WriteLine ( "Result is null." ) ;
404- }
405- }
406-
407- private void GetCollectionImages ( )
408- {
409- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
410- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
411-
412- Console . WriteLine ( string . Format ( "\n Calling GetCollectionImages(\" {0}\" )..." , _createdCollectionId ) ) ;
413-
414- var result = _visualRecognition . GetCollectionImages ( _createdCollectionId ) ;
415-
416- if ( result != null )
417- {
418- if ( result . Images != null && result . Images . Count > 0 )
419- {
420- foreach ( GetCollectionsBrief image in result . Images )
421- Console . WriteLine ( string . Format ( "imageId: {0} | imageFile: {1} | created: {2} | metadata{3}" , image . ImageId , image . ImageFile , image . Created , image . Metadata ) ) ;
422- }
423- else
424- {
425- Console . WriteLine ( "There are no images." ) ;
426- }
427- }
428- else
429- {
430- Console . WriteLine ( "Result is null." ) ;
431- }
432- }
433-
434- private void AddCollectionImages ( )
435- {
436- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
437- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
438-
439- using ( FileStream imageStream = File . OpenRead ( _localGiraffeFilePath ) , metadataStream = File . OpenRead ( _localImageMetadataPath ) )
440- {
441- Console . WriteLine ( string . Format ( "\n Calling AddImage(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _localGiraffeFilePath ) ) ;
442-
443- var result = _visualRecognition . AddImage ( _createdCollectionId , imageStream . ReadAllBytes ( ) , Path . GetFileName ( _localGiraffeFilePath ) , metadataStream . ReadAllBytes ( ) ) ;
444-
445- if ( result != null )
446- {
447- Console . WriteLine ( "Number of images processed: {0}" , result . ImagesProcessed ) ;
448- foreach ( CollectionImagesConfig image in result . Images )
449- {
450- Console . WriteLine ( "file: {0} | id: {1}" , image . ImageFile , image . ImageId ) ;
451-
452- if ( image . Metadata != null && image . Metadata . Count > 0 )
453- {
454- foreach ( KeyValuePair < string , string > kvp in image . Metadata )
455- Console . WriteLine ( "\t {0} : {1}" , kvp . Key , kvp . Value ) ;
456- }
457- else
458- {
459- Console . WriteLine ( "There is no metadata for this image." ) ;
460- }
461-
462- _addedImageId = image . ImageId ;
463- }
464- }
465- else
466- {
467- Console . WriteLine ( "Result is null." ) ;
468- }
469- }
470- }
471-
472- private void DeleteCollectionImage ( )
473- {
474- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
475- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
476-
477- if ( string . IsNullOrEmpty ( _addedImageId ) )
478- throw new ArgumentNullException ( nameof ( _addedImageId ) ) ;
479-
480- Console . WriteLine ( string . Format ( "\n Calling DeleteImage(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _addedImageId ) ) ;
481-
482- var result = _visualRecognition . DeleteImage ( _createdCollectionId , _addedImageId ) ;
483-
484- if ( result != null )
485- Console . WriteLine ( string . Format ( "Image {0} deleted from collection {1}." , _addedImageId , _createdCollectionId ) ) ;
486- }
487-
488- private void GetCollectionImage ( )
489- {
490- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
491- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
492-
493- if ( string . IsNullOrEmpty ( _addedImageId ) )
494- throw new ArgumentNullException ( nameof ( _addedImageId ) ) ;
495-
496- Console . WriteLine ( string . Format ( "\n Calling GetCollectionImages(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _addedImageId ) ) ;
497-
498- var result = _visualRecognition . GetImage ( _createdCollectionId , _addedImageId ) ;
499-
500- if ( result != null )
501- {
502- Console . WriteLine ( string . Format ( "imageId: {0} | imageFile: {1} | created: {2} | metadata{3}" , result . ImageId , result . ImageFile , result . Created , result . Metadata ) ) ;
503- }
504- else
505- {
506- Console . WriteLine ( "Result is null." ) ;
507- }
508- }
509-
510- private void DeleteCollectionImageMetadata ( )
511- {
512- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
513- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
514-
515- if ( string . IsNullOrEmpty ( _addedImageId ) )
516- throw new ArgumentNullException ( nameof ( _addedImageId ) ) ;
517-
518- Console . WriteLine ( string . Format ( "\n Calling DeleteImageMetadata(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _addedImageId ) ) ;
519-
520- var result = _visualRecognition . DeleteImageMetadata ( _createdCollectionId , _addedImageId ) ;
521- }
522-
523- private void GetCollectionImageMetadata ( )
524- {
525- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
526- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
527-
528- if ( string . IsNullOrEmpty ( _addedImageId ) )
529- throw new ArgumentNullException ( nameof ( _addedImageId ) ) ;
530-
531- Console . WriteLine ( string . Format ( "\n Calling GetMetadata(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _addedImageId ) ) ;
532-
533- var result = _visualRecognition . GetMetadata ( _createdCollectionId , _addedImageId ) ;
534-
535- if ( result != null )
536- {
537- foreach ( KeyValuePair < string , string > item in result )
538- Console . WriteLine ( string . Format ( "\t Metadata: {0}, {1}" , item . Key , item . Value ) ) ;
539- }
540- else
541- {
542- Console . WriteLine ( "Result is null." ) ;
543- }
544- }
545-
546- private void AddCollectionImageMetadata ( )
547- {
548- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
549- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
550-
551- if ( string . IsNullOrEmpty ( _addedImageId ) )
552- throw new ArgumentNullException ( nameof ( _addedImageId ) ) ;
553-
554- using ( FileStream metadataStream = File . OpenRead ( _localImageMetadataPath ) )
555- {
556- Console . WriteLine ( string . Format ( "\n Calling AddMetadata(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _addedImageId ) ) ;
557-
558- var result = _visualRecognition . AddImageMetadata ( _createdCollectionId , _addedImageId , metadataStream . ReadAllBytes ( ) ) ;
559-
560- if ( result != null && result . Count > 0 )
561- {
562- foreach ( KeyValuePair < string , string > kvp in result )
563- Console . WriteLine ( "\t {0} : {1}" , kvp . Key , kvp . Value ) ;
564- }
565- else
566- {
567- Console . WriteLine ( "Result is null." ) ;
568- }
569- }
570-
571- }
572-
573- private void FindSimilar ( )
574- {
575- if ( string . IsNullOrEmpty ( _createdCollectionId ) )
576- throw new ArgumentNullException ( nameof ( _createdCollectionId ) ) ;
577-
578- using ( FileStream imageStream = File . OpenRead ( _localTurtleFilePath ) )
579- {
580- Console . WriteLine ( string . Format ( "\n Calling FindSimilar(\" {0}\" , \" {1}\" )..." , _createdCollectionId , _localTurtleFilePath ) ) ;
581-
582- var result = _visualRecognition . FindSimilar ( _createdCollectionId , imageStream . ReadAllBytes ( ) , Path . GetFileName ( _localGiraffeFilePath ) ) ;
583-
584- if ( result != null )
585- {
586- Console . WriteLine ( "Number of images processed: {0}" , result . ImagesProcessed ) ;
587- foreach ( SimilarImageConfig image in result . SimilarImages )
588- {
589- Console . WriteLine ( "file: {0} | id: {1} | score: {2}" , image . ImageFile , image . ImageId , image . Score ) ;
590-
591- if ( image . Metadata != null && image . Metadata . Count > 0 )
592- {
593- foreach ( KeyValuePair < string , string > kvp in image . Metadata )
594- Console . WriteLine ( "\t {0} : {1}" , kvp . Key , kvp . Value ) ;
595- }
596- else
597- {
598- Console . WriteLine ( "There is no metadata for this image." ) ;
599- }
600- }
601- }
602- else
603- {
604- Console . WriteLine ( "Result is null." ) ;
605- }
606- }
607- }
608-
609318 private void DeleteAllClassifiers ( )
610319 {
611320 Console . WriteLine ( "Getting classifiers" ) ;
@@ -647,38 +356,6 @@ private bool IsClassifierReady(string classifierId)
647356 return result . Status . ToLower ( ) == "ready" ;
648357 }
649358
650- private void DeleteDotnetCollections ( )
651- {
652- Console . WriteLine ( "\n Getting all collections" ) ;
653- List < string > collectionIdsToDelete = new List < string > ( ) ;
654-
655- var collections = _visualRecognition . GetCollections ( ) ;
656-
657- foreach ( CreateCollection collection in collections . Collections )
658- {
659- string name = collection . Name ;
660- string id = collection . CollectionId ;
661- Console . WriteLine ( string . Format ( "name: {0} | id: {1}" , name , id ) ) ;
662-
663- if ( name == _collectionNameToCreate )
664- collectionIdsToDelete . Add ( id ) ;
665- }
666-
667- if ( collectionIdsToDelete . Count > 0 )
668- {
669- foreach ( string collectionIdToDelete in collectionIdsToDelete )
670- {
671- Console . WriteLine ( string . Format ( "Deleting collection {0}." , collectionIdToDelete ) ) ;
672- _visualRecognition . DeleteCollection ( collectionIdToDelete ) ;
673- Console . WriteLine ( string . Format ( "\t Collection {0} deleted." , collectionIdToDelete ) ) ;
674- }
675- }
676- else
677- {
678- Console . WriteLine ( "There are no matching collections to delete." ) ;
679- }
680- }
681-
682359 #region Delay
683360 // Introducing a delay because of a known issue with Visual Recognition where newly created classifiers
684361 // will disappear without being deleted if a delete is attempted less than ~10 seconds after creation.
0 commit comments