Exemple #1
0
        private void Auto_Click(object sender, RoutedEventArgs e)
        {
            //this.listik.Content = "It can take a few moment...";
            int size = w * h;

            ImageData[] images_r = new ImageData[size];
            for (int i = 0; i < size; i++)
            {
                images_r[i] = (ImageData)piccc2.Items[i];
            }
            Exten.heapPermutation(images_r, size, size);
            Dictionary <int, (int, ImageData[])> res = new Dictionary <int, (int, ImageData[])>(Exten.imageDatas1.Count);

            for (int i = 0; i < Exten.imageDatas1.Count; i++)
            {
                res.Add(i, (Check_C(Exten.imageDatas1[i]), Exten.imageDatas1[i]));
            }
            var keyAndValue = res.OrderBy(kvp => kvp.Value.Item1).First();

            this.listik.Content     = "Done"; //+ keyAndValue.Value.Item1;
            this.piccc3.Width       = 100 * w;
            this.piccc3.Height      = 100 * h;
            this.piccc3.ItemsSource = keyAndValue.Value.Item2;
        }
Exemple #2
0
        //public int Check_C(ImageData[] imageDatas)
        //{
        //    int imageWidth = 500;
        //    int imageHeight = 500;
        //    DrawingVisual drawingVisual = new DrawingVisual();
        //    using (DrawingContext drawingContext = drawingVisual.RenderOpen())
        //    {

        //        int num = 0;

        //        for (int i = 0; i < h; i++)
        //        {
        //            for (int j = 0; j < w; j++)
        //            {
        //                drawingContext.DrawImage(imageDatas[num].Images, new Rect(j * imageHeight, i * imageWidth, imageWidth, imageHeight));
        //                num++;
        //            }
        //        }
        //    }
        //    RenderTargetBitmap bmp = new RenderTargetBitmap(imageWidth * w, imageHeight * h, 96, 96, PixelFormats.Pbgra32);
        //    bmp.Render(drawingVisual);

        //    MemoryStream stream = new MemoryStream();
        //    BitmapEncoder encoder = new BmpBitmapEncoder();
        //    encoder.Frames.Add(BitmapFrame.Create(bmp));
        //    encoder.Save(stream);
        //    Bitmap bitmap = new Bitmap(stream);
        //    //System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
        //    //img.Save(@"C:\Users\victo\source\repos\PuzzleDev\PuzzleDev\full_recon.jpg");
        //    Bitmap bmp2 = new Bitmap(startupPath + "\\full.jpg");
        //    Bitmap bmp3 = new Bitmap(bmp2, new System.Drawing.Size(imageWidth * w, imageHeight * h));
        //    bmp3.SetResolution(96, 96);

        //    //bmp3.Save(@"C:\Users\victo\source\repos\PuzzleDevCom\PuzzleDevCom\Pictures\full2.jpg");


        //    List<bool> iHash1 = Exten.GetHash(bitmap);
        //    List<bool> iHash2 = Exten.GetHash(bmp3);

        //    int count = 0;
        //    for (int i = 0; i < iHash1.Count; i++)
        //    {
        //        if (iHash1[i] != iHash2[i])
        //        {
        //            count += 1;
        //        }
        //    }
        //    return count;
        //}

        public int Check_C(ImageData[] arr1)
        {
            Bitmap[] imageDatas = new Bitmap[h * w];
            int      f1         = 0;

            for (int i = 0; i < h * w; i++)
            {
                imageDatas[f1] = Exten.BitmapImage2Bitmap(arr1[f1].Images);
                f1++;
            }
            Bitmap[,] arr = new Bitmap[h, w];
            int num = 0;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    arr[i, j] = imageDatas[num];
                    num++;
                }
            }
            string Hash1 = "";
            string Hash2 = "";

            int count = 0;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    Hash1 += "\n";
                    Hash2 += "\n";
                    if (i - 1 >= 0)
                    {
                        List <bool> iHash1 = Exten.GetHash(arr[i, j], "down");
                        List <bool> iHash2 = Exten.GetHash(arr[i - 1, j], "top");
                        for (int f = 0; f < iHash1.Count; f++)
                        {
                            if (iHash1[f] != iHash2[f])
                            {
                                count += 1;
                            }
                        }
                    }
                    if (j - 1 >= 0)
                    {
                        List <bool> iHash1 = Exten.GetHash(arr[i, j], "left");
                        List <bool> iHash2 = Exten.GetHash(arr[i, j - 1], "right");
                        for (int f = 0; f < iHash1.Count; f++)
                        {
                            Hash1 += iHash1[f].ToString();
                            Hash2 += iHash2[f].ToString();
                            if (iHash1[f] != iHash2[f])
                            {
                                count += 1;
                            }
                        }
                    }
                }
            }

            return(count);
        }
Exemple #3
0
        private void Play_Click(object sender, RoutedEventArgs e)
        {
            Play.IsEnabled  = false;
            Check.IsEnabled = true;
            Auto.IsEnabled  = true;
            int fCount = Directory.GetFiles(searchFolder, "*.jpg", SearchOption.TopDirectoryOnly).Length;
            List <BitmapImage> bitmaps = new List <BitmapImage>();

            for (int i = 0; i < fCount; i++)
            {
                string img;
                if (i < 9)
                {
                    img = "img0" + (i + 1) + ".jpg";
                }
                else
                {
                    img = "img" + (i + 1) + ".jpg";
                }
                BitmapImage bitmap = new BitmapImage(new Uri(searchFolder + img));
                bitmaps.Add(bitmap);
            }

            Random rand = new Random();
            var    nums = Enumerable.Range(0, fCount).ToArray();

            for (int i = 0; i < nums.Length; ++i)
            {
                int randomIndex = rand.Next(nums.Length);
                int temp        = nums[randomIndex];
                nums[randomIndex] = nums[i];
                nums[i]           = temp;
            }
            ImageData[] images_r = new ImageData[fCount];
            for (int i = 0; i < fCount; i++)
            {
                images_r[nums[i]] = new ImageData {
                    Images = bitmaps[i]
                };
            }
            //this.SizeToContent = SizeToContent.Height;
            this.SizeToContent      = SizeToContent.Width;
            this.piccc2.Width       = 100 * w;
            this.piccc2.Height      = 100 * h;
            this.piccc2.ItemsSource = images_r;
            ImageData[] images2 = new ImageData[fCount];
            Bitmap      bmp     = new Bitmap(50, 50);

            using (Graphics graph = Graphics.FromImage(bmp))
            {
                System.Drawing.Rectangle ImageSize = new System.Drawing.Rectangle(0, 0, 50, 50);
                graph.FillRectangle(System.Drawing.Brushes.White, ImageSize);
            }
            //for (int i = 0; i < fCount; i++)
            //{
            //    imagesbitTotal[i] = bmp;
            //}
            for (int i = 0; i < fCount; i++)
            {
                images2[i] = new ImageData {
                    Images = Exten.ToBitmapImage(bmp)
                };
            }
            this.piccc3.Width       = 100 * w;
            this.piccc3.Height      = 100 * h;
            this.piccc3.ItemsSource = images2;
            for (int i = 0; i < fCount; i++)
            {
                imagesTotal[i] = (ImageData)piccc3.Items[i];
            }
        }
Exemple #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(HeightText.Text) && String.IsNullOrEmpty(WeightText.Text))
            {
                FileNameLabel.Content = "Enter Height and Width!";
            }
            else
            {
                BrowseButton.IsEnabled = false;
                Check.IsEnabled        = false;
                Auto.IsEnabled         = false;
                Play.IsEnabled         = true;
                System.IO.DirectoryInfo di = new DirectoryInfo(searchFolder);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.InitialDirectory = "c:\\";
                dlg.Filter           = "Image files (*.jpg)|*.jpg|All Files (*.*)|*.*";
                dlg.RestoreDirectory = true;
                if (dlg.ShowDialog() ?? false)
                {
                    string selectedFileName = dlg.FileName;
                    FileNameLabel.Content = "Ready!";
                    filename = selectedFileName;
                    bitmap_t.BeginInit();
                    bitmap_t.UriSource = new Uri(selectedFileName);
                    bitmap_t.EndInit();
                    Exten.Save(bitmap_t, startupPath + "\\full.jpg");
                }
                Heights = double.Parse(HeightText.Text);
                Widths  = double.Parse(WeightText.Text);
                h       = int.Parse(HeightText.Text);
                w       = int.Parse(WeightText.Text);
                List <BitmapImage> l = new List <BitmapImage>();
                int total            = h * w;
                for (int i = 0; i < total; i++)
                {
                    l.Add(Exten.ToBitmapImage(Pictures()[i]));
                    mage.Add(Exten.ToBitmapImage(Pictures()[i]));
                }


                ImageData[] images = new ImageData[total];
                for (int i = 0; i < total; i++)
                {
                    images[i] = new ImageData {
                        Images = l[i]
                    };
                }

                for (int i = 0; i < total; i++)
                {
                    string img;
                    if (i < 9)
                    {
                        img = "img0" + (i + 1) + ".jpg";
                    }
                    else
                    {
                        img = "img" + (i + 1) + ".jpg";
                    }
                    Exten.Save(mage[i], startupPath + "\\Pictures\\" + img);
                }
            }
        }