示例#1
0
        public void backgroundWorkerBing_DoWork(object sender, DoWorkEventArgs e)
        {
            string targetImageClass = MatchingHelper.matchedClass;

            //check if it is a reranking
            if (toRerank)
            {
                double[] rerankedImages = MatchingHelper.SearchSimilar(MatchingHelper.rerankingImageName, numberOfImagesToRetrieve);
                backgroundWorkerBing.ReportProgress(50, rerankedImages);
                return;
            }

            //check if the class of the image is covered by our similarity matching, then retrieve from our own database
            for (int catNum = 0; catNum < 20; catNum++)
            {
                string command = VoiceControlHelper.voiceCommands[catNum];
                if (targetImageClass == command)
                {
                    toRerank = true;
                    List <double> randomChosedImages = new List <double>();
                    Random        randomGen          = new Random();
                    for (int k = 0; k < numberOfImagesToRetrieve; k++)
                    {
                        double imageNum = 0;
                        do
                        {
                            imageNum = catNum * 25 + randomGen.Next(1, 26);
                        } while (randomChosedImages.Contains(imageNum));
                        randomChosedImages.Add(imageNum);
                    }
                    backgroundWorkerBing.ReportProgress(50, randomChosedImages.ToArray());
                    return;
                }
            }

            //to retrieve images from the network if the target image class is not covered by our similarity matrix
            toRerank = false;
            // this is the service root uri for the Bing search service
            var serviceRootUri = new Uri("https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1");

            // this is the Account Key generated for this app
            var accountKey = "TG4vg/aL3DjSYJVl25mmyPVHhCCLCuObnR26ggQZhWc=";

            // the BingSearchContainer gives us access to the Bing services
            BingSearchContainer bsc = new BingSearchContainer(serviceRootUri);

            // Give the BingSearchContainer access to the subscription
            bsc.Credentials = new NetworkCredential(accountKey, accountKey);

            // building the query
            var imageQuery = bsc.Image(targetImageClass, null, null, "Strict", null, null, "Size:Medium");

            IEnumerable <ImageResult> imageResults = imageQuery.Execute();

            backgroundWorkerBing.ReportProgress(99, imageResults);
        }
示例#2
0
 public void backgroundWorkerMatch_DoWork(object sender, DoWorkEventArgs e)
 {
     MessageBox.Show("start match");
     MatchingHelper.matchClass();
 }