Example #1
0
        private KeyValuePair <Point, double> findAnswerPoint(Problem pro)
        {
            Bitmap[] bmps =
            {
                Crop(pro.branchA),
                Crop(pro.branchB),
                Crop(pro.branchC),
                Crop(pro.branchD),
            };
            Bitmap ans = new Bitmap(pro.Id + "_1");
            Dictionary <int, double> similarity = new Dictionary <int, double>();

            for (int i = 0; i < bmps.Count(); ++i)
            {
                double sim = ImageAnalysis.getVerticalSimilarity(bmps[i], ans);
                similarity.Add(i, sim);
            }
            KeyValuePair <int, double> index = similarity.First(item => item.Value == similarity.Values.Min());
            double sum        = similarity.Sum(item => item.Value);
            double confidence = 1 - 3 * index.Value / (sum - index.Value);

            if (confidence != 1)
            {
                for (int i = 0; i < bmps.Count(); ++i)
                {
#if DEBUG
                    //MessageBox.Show(sim.ToString());
#else
                    ImageAnalysis.getVerticalSimilarity(bmps[i], ans, true);
#endif
                }
            }
            switch (index.Key)
            {
            case 0:
                return(new KeyValuePair <Point, double>(pro.A, confidence));

            case 1:
                return(new KeyValuePair <Point, double>(pro.B, confidence));

            case 2:
                return(new KeyValuePair <Point, double>(pro.C, confidence));

            case 3:
                return(new KeyValuePair <Point, double>(pro.D, confidence));

            default:
                throw new Exception("Internal Error!");
            }
        }
Example #2
0
        private string findProblemId(Problem pro)
        {
            string[] files = Directory.GetFiles("Download");
            Dictionary <string, double> similarity = new Dictionary <string, double>();

            foreach (string file in files)
            {
                if (file.IndexOf('.') == -1 && file.IndexOf('_') >= 0)
                {
                    Bitmap   bmp = new Bitmap(file);
                    string[] str = file.Split('_');
                    Debug.WriteLine(str[0] + str[1]);
                    if (str[3] == "0")
                    {
                        similarity.Add(string.Join("_", new string[] { str[0], str[1], str[2] }), ImageAnalysis.getVerticalSimilarity(bmp, Crop(pro.stem)));
                    }
                }
            }
#if DEBUG
            //MessageBox.Show(similarity.First(item => item.Value == similarity.Values.Min()).Key);
#endif
            return(similarity.First(item => item.Value == similarity.Values.Min()).Key);
        }