示例#1
0
        private void Failed(string answer = null)
        {
            bool haveError = false;
            var  fonts     = driver.FindElementsByTagName("font");

            foreach (var font in fonts)
            {
                if (font.Text.Contains("Failed. You did not successfully solve the problem"))
                {
                    driver.FindElementById("loadmore").Click();
                    haveError = true;
                }
            }

            if (!haveError)
            {
                if (bit == null)
                {
                    Screenshot screenshot = ((ITakesScreenshot)this.driver).GetScreenshot();
                    screenshot.SaveAsFile("omg.jpg", ScreenshotImageFormat.Jpeg);
                }

                string hash = bit.GetHashCode().ToString();


                if (db.FindCaptcha(ms) != null)
                {
                    // ok we have already
                }
                else if (answer != null)
                {
                    db.Add(new Captcha()
                    {
                        Hash = ms, Result = answer
                    });

                    Console.WriteLine("*\n saved * \n");
                }
            }


            // save answer
        }
示例#2
0
        /// <summary>
        /// Saves the Bitmap to the disk and adds the filename in the list of frames.
        /// </summary>
        /// <param name="filename">The final filename of the Bitmap.</param>
        /// <param name="bitmap">The Bitmap to save in the disk.</param>
        private void AddFrames(string filename, Bitmap bitmap)
        {
            var mutexLock = new Mutex(false, bitmap.GetHashCode().ToString());
            mutexLock.WaitOne();

            bitmap.Save(filename);
            bitmap.Dispose();

            GC.Collect(1);
            mutexLock.ReleaseMutex();
        }
示例#3
0
        // Gather image statistics
        public void GatherStatistics(Bitmap image)
        {
            // avoid calculation in the case of the same image
            if (image != null)
            {
                if (currentImageHash == image.GetHashCode())
                    return;
                currentImageHash = image.GetHashCode();
            }
            else
            {
                propertyGrid.SelectedObject = null;
                return;
            }

            System.Diagnostics.Debug.WriteLine("--- Gathering stastics");

            // check pixel format
            if (image.PixelFormat == PixelFormat.Format24bppRgb)
            {
                // busy
                Capture = true;
                Cursor = Cursors.WaitCursor;

                ColorImageStatisticsDescription statDesc = new ColorImageStatisticsDescription(image);
                // show statistics
                propertyGrid.SelectedObject = statDesc;
                propertyGrid.ExpandAllGridItems();

                // free
                Cursor = Cursors.Arrow;
                Capture = false;
            }
            else
            {
                propertyGrid.SelectedObject = null;
            }
        }
 public static void ScreenShot()
 {
     Rectangle bounds = Screen.GetBounds(Point.Empty);
     using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
     {
         using (Graphics g = Graphics.FromImage(bitmap))
         {
             g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
         }
         DateTime thisDay = DateTime.Today;
         string data = thisDay.ToString("d");
         string ingName = "..//..//Screenshots//screenshots" + bitmap.GetHashCode() + ".jpg";
         bitmap.Save(ingName, ImageFormat.Jpeg);
         Thread.Sleep(2000);
     }
 }
        public void TestThin(Bitmap bmp)
        {
            var bmpBefore = Binarization(ImageHelper.LoadImage<double>(bmp), bmp.Height, bmp.Width);
            /* open binarized source picture
            var newPic1 = ImageHelper.SaveArrayToBitmap(bmpBefore);
            var name1 = Path.GetTempPath() + bmp.GetHashCode().ToString() + "BEFORE.bmp";
            newPic1.Save(name1, ImageHelper.GetImageFormatFromExtension(name1));
            Process.Start(name1);
            */
            var bmpAfter = Thinner.Thin(bmpBefore, bmp.Width, bmp.Height);

            var newPic = ImageHelper.SaveArrayToBitmap(
                OverlapArrays(bmpAfter, bmpBefore, bmp.Height, bmp.Width)
            );
            var name = Path.GetTempPath() + bmp.GetHashCode().ToString() + "AFTER.bmp";
            newPic.Save(name, ImageHelper.GetImageFormatFromExtension(name));
            Process.Start(name);
        }
示例#6
0
 /// <summary>
 /// Create a texture from a supplie bitmap.
 /// </summary>
 /// <param name="BitmapImage">The already decoded bitmap image.</param>
 /// <param name="FlipY">True if the bitmap should be flipped.</param>
 public Texture(Bitmap BitmapImage, bool FlipY = true)
 {
     this.Filename = BitmapImage.GetHashCode().ToString();
     LoadBitmap(BitmapImage, FlipY);
     Gl.BindTexture(TextureTarget, 0);
 }
示例#7
0
        /// <summary>
        /// Load files in one Folder, then recurse on all contained folders
        /// </summary>
        /// <param name="root">Current Top Level Folder Name</param>
        private void MyLoLoadFolder(DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;
            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to MyLoLoadFolder().
                    try
                    {
                        if (fi.Extension == ".jpg" || fi.Extension == ".JPG")
                        {
                            Photo photo = new Photo();
                            Image.GetThumbnailImageAbort myCallback =
                            new Image.GetThumbnailImageAbort(ThumbnailCallback);
                            Bitmap image = new Bitmap(fi.FullName);
                            Image thumb = image.GetThumbnailImage(100, 100, myCallback, IntPtr.Zero);

                            ImageConverter converter = new ImageConverter();
                            photo.Thumbnail = (byte[])converter.ConvertTo(thumb, typeof(byte[]));

                            // This is for testing only - should switch to more reliable Hash such as SHA-256 or MD5
                            //long CRC = CalculateCRCForFile(fi.FullName);
                            photo.CRC = image.GetHashCode();
                            image.Dispose();

                            JpgPhoto photoJpg = new JpgPhoto(fi.FullName);

                            photo.Uri = fi.FullName;
                            photo.Aperture = photoJpg.Metadata.Aperture;
                            photo.Camera = photoJpg.Metadata.CameraModel;
                            photo.DateTaken = photoJpg.Metadata.DateTaken;
                            photo.PhotoIndexKind = _timeIndexKind;
                            DateTime dat = photoJpg.Metadata.DateTaken.Date;
                            TimeSpan tim = photoJpg.Metadata.DateTaken.TimeOfDay;
                            if (photoJpg.Metadata.GpsPosition.Latitude.IsValidCoordinate)
                            {
                                photo.GpsLat = photoJpg.Metadata.GpsPosition.Latitude.Numeric;
                            }
                            if (photoJpg.Metadata.GpsPosition.Longitude.IsValidCoordinate)
                            {
                                photo.GpsLong = photoJpg.Metadata.GpsPosition.Longitude.Numeric;
                            }
                            photo.Uuid = Guid.NewGuid();

                            //foreach (Tag tag in photo.Metadata.Tags)
                            //{
                            //    Console.WriteLine(tag.FullName);
                            //}
                            long photoId = _myLoStore.AddPhoto(_userId, photo);

                            _count++;

                            // TODO add code to write back GUID and Hash into photo metadata
                        }
                    }
                    catch (MyLoCRCException crcEx)
                    {
                        throw new MyLoException("CRC Calculation Error: Inner exception: " + crcEx);
                    }
                    catch (MyLoDataStoreException dsEx)
                    {
                        throw new MyLoException("DataStore Error: Inner exception: " + dsEx);
                    }
                    catch (Exception ex)
                    {
                        throw new MyLoException("File not Found: " + fi.FullName + " Inner exception: " + ex);
                    }
                    Debug.WriteLine(fi.FullName);
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    MyLoLoadFolder(dirInfo);
                }
            }
        }
示例#8
0
        public static string Recognize(Bitmap bitmap, int series)
        {
            Dictionary <string, int> versions = new Dictionary <string, int>();

            using (ImageClass image = new ImageClass(bitmap))
            {
                for (int i = 0; i < series; i++)
                {
                    string result = "";
                    try
                    {
                        using (Bitmap b = new Bitmap(image.BitImage))
                        {
                            result = Recognize(b);
                        }
                    }
                    catch (RecognitionEngineException exception)
                    {
                        //если ошибка из-за отсутствия текста
                        if (exception.ErrorCode == 6553609)
                        {
                            if (!versions.ContainsKey(result))
                            {
                                versions.Add(result, 1);
                            }
                            break;
                        }
                        //если ошибка из-за отсутствия текста[2]
                        if (exception.ErrorCode == 6684676)
                        {
                            if (!versions.ContainsKey(result))
                            {
                                versions.Add(result, 1);
                            }
                            break;
                        }
                        bitmap.Save(Path.Combine(Application.StartupPath, bitmap.GetHashCode().ToString() + ".png"), ImageFormat.Png);
                        throw;
                    }
                    if (versions.ContainsKey(result))
                    {
                        versions[result]++;
                    }
                    else
                    {
                        versions.Add(result, 1);
                    }
                    image.Resize(0.9);
                }
            }

            int max = 0;
            string sMax = "";
            foreach (KeyValuePair <string, int> pair in versions)
            {
                if (string.IsNullOrEmpty(pair.Key))
                    continue;
                if (pair.Value > max)
                {
                    sMax = pair.Key;
                    max = pair.Value;
                }
            }
            return sMax;
        }
示例#9
0
        internal void SetHistograms(Bitmap hostImage, Bitmap secretImage, Bitmap outputImage)
        {
            if (hostImage != null)
            {
                if (hostImageHash == hostImage.GetHashCode())
                {
                    return;
                }
                hostImageHash = hostImage.GetHashCode();
                CreateSeries(ref hostImageSeries, hostImage, "HostImageChartArea");
                hostImageComboBox.Enabled = true;
                hostImageComboBox.SelectedIndex = 0;
            }
            else
            {
                hostImageChart.Series.Clear();
            }

            if (secretImage != null)
            {
                if (secretImageHash == secretImage.GetHashCode())
                {
                    return;
                }
                secretImageHash = secretImage.GetHashCode();
                CreateSeries(ref secretImageSeries, secretImage, "SecretImageChartArea");
                secretImageComboBox.Enabled = true;
                secretImageComboBox.SelectedIndex = 0;
            }
            else
            {
                secretImageChart.Series.Clear();
            }

            if (outputImage != null)
            {
                if (outputImageHash == outputImage.GetHashCode())
                {
                    return;
                }
                outputImageHash = outputImage.GetHashCode();
                CreateSeries(ref outputImageSeries, outputImage, "OutputImageChartArea");
                outputImageComboBox.Enabled = true;
                outputImageComboBox.SelectedIndex = 0;
            }
            else
            {
                outputImageChart.Series.Clear();
            }

            if (hostImage != null && secretImage != null && outputImage != null)
                allImageComboBox.Enabled = true;

            return;
        }
示例#10
0
        // Gather image statistics
        public void GatherStatistics( Bitmap image )
        {
            // avoid calculation in the case of the same image
            if ( image != null )
            {
                if ( currentImageHash == image.GetHashCode( ) )
                    return;
                currentImageHash = image.GetHashCode( );
            }

            if ( image != null )
                System.Diagnostics.Debug.WriteLine( "=== Gathering histogram" );

            // busy
            Capture = true;
            Cursor = Cursors.WaitCursor;

            // get statistics
            stat = ( image == null ) ? null : new ImageStatistics( image );

            // free
            Cursor = Cursors.Arrow;
            Capture = false;

            // clean combo
            channelCombo.Items.Clear( );
            channelCombo.Enabled = false;

            if ( stat != null )
            {
                if ( !stat.IsGrayscale )
                {
                    // RGB picture
                    channelCombo.Items.AddRange( new object[] { "Red", "Green", "Blue" } );
                    channelCombo.Enabled = true;
                }
                else
                {
                    // grayscale picture
                    channelCombo.Items.Add( "Gray" );
                }
                channelCombo.SelectedIndex = 0;
            }
            else
            {
                histogram.Values = null;
                meanLabel.Text = String.Empty;
                stdDevLabel.Text = String.Empty;
                medianLabel.Text = String.Empty;
                minLabel.Text = String.Empty;
                maxLabel.Text = String.Empty;
                levelLabel.Text = String.Empty;
                countLabel.Text = String.Empty;
                percentileLabel.Text = String.Empty;
            }
        }
示例#11
0
文件: Image.cs 项目: nlhepler/mono
		public void GetHashCodeTest () {
			Assert.IsFalse (t.Bitmap.GetHashCode () == 0);
			Bitmap im1 = new Bitmap (10, 20);
			Assert.IsFalse (t.Bitmap.GetHashCode () == im1.GetHashCode ());
		}
示例#12
0
        internal void SetProperties(Bitmap hostImage, Bitmap secretImage, Bitmap outputImage)
        {
            if (hostImage != null)
            {
                if (hostImageHash == hostImage.GetHashCode())
                {
                    return;
                }
                hostImageHash = hostImage.GetHashCode();
                hostImgPropertyGrid.SelectedObject = new ImageProperties(hostImage);
                hostImgPropertyGrid.ExpandAllGridItems();
            }
            else
            {
                hostImgPropertyGrid.SelectedObject = null;
            }

            if (secretImage != null)
            {
                if (secretImageHash == secretImage.GetHashCode())
                {
                    return;
                }
                secretImageHash = secretImage.GetHashCode();
                secretImgPropertyGrid.SelectedObject = new ImageProperties(secretImage);
                secretImgPropertyGrid.ExpandAllGridItems();
            }
            else
            {
                secretImgPropertyGrid.SelectedObject = null;
            }

            if (outputImage != null)
            {
                if (outputImageHash == outputImage.GetHashCode())
                {
                    return;
                }
                outputImageHash = outputImage.GetHashCode();
                outputImgPropertyGrid.SelectedObject = new ImageProperties(outputImage);
                outputImgPropertyGrid.ExpandAllGridItems();
            }
            else
            {
                outputImgPropertyGrid.SelectedObject = null;
            }

            return;
        }
示例#13
0
        private static Bitmap MakeOpaque(Bitmap original, string path, double opacity)
        {
            if (CachedOpaque.ContainsKey(original.GetHashCode())) return CachedOpaque[original.GetHashCode()];

            Bitmap bmp = (Bitmap)original.Clone();

            // Specify a pixel format.
            PixelFormat pxf = PixelFormat.Format32bppArgb;

            // Lock the bitmap's bits.
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);

            // Get the address of the first line.
            IntPtr ptr = bmpData.Scan0;

            // Declare an array to hold the bytes of the bitmap.
            // This code is specific to a bitmap with 32 bits per pixels
            // (32 bits = 4 bytes, 3 for RGB and 1 byte for alpha).
            int numBytes = bmp.Width * bmp.Height * 4;
            byte[] argbValues = new byte[numBytes];

            // Copy the ARGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, numBytes);

            // Manipulate the bitmap, such as changing the
            // RGB values for all pixels in the the bitmap.
            for (int counter = 0; counter < argbValues.Length; counter += 4)
            {
                // argbValues is in format BGRA (Blue, Green, Red, Alpha)

                // If 100% transparent, skip pixel
                if (argbValues[counter + 4 - 1] == 0)
                    continue;

                int pos = 0;
                pos++; // B value
                pos++; // G value
                pos++; // R value

                argbValues[counter + pos] = (byte)(argbValues[counter + pos] * opacity);
            }

            // Copy the ARGB values back to the bitmap
            System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, numBytes);

            // Unlock the bits.
            bmp.UnlockBits(bmpData);

            // Cache
            CachedOpaque[original.GetHashCode()] = bmp;
            return bmp;
        }
示例#14
0
        /// <summary>
        /// Return green filter for specific image
        /// </summary>
        /// <param name="Image"></param>
        /// <returns></returns>
        public static Bitmap GreenFilter(Bitmap Image)
        {
            if (CachedOverlay.ContainsKey(Image.GetHashCode())) return CachedOverlay[Image.GetHashCode()];

            ColorMatrixBitmap TempMatrix = new ColorMatrixBitmap();
            TempMatrix.Matrix = new float[][]{
                       new float[] {0, 0, 0, 0, 0},
                       new float[] {0, 1, 0, 0, 0},
                       new float[] {0, 0, 0, 0, 0},
                       new float[] {0, 0, 0, 1, 0},
                       new float[] {0, 0, 0, 0, 1}
                   };
             var bmp = TempMatrix.Apply(Image);
             CachedOverlay[Image.GetHashCode()] = bmp;
             return bmp;
        }
示例#15
-1
        internal void SetPSNR(Bitmap hostImage, Bitmap outputImage)
        {
            if (outputImage != null)
            {
                if (outputImageHash == outputImage.GetHashCode())
                {
                    return;
                }
                outputImageHash = outputImage.GetHashCode();
                outputImgPropertyGrid.SelectedObject = new PSNR(hostImage, outputImage);
                outputImgPropertyGrid.ExpandAllGridItems();
            }
            else
            {
                outputImgPropertyGrid.SelectedObject = null;
            }

            return;
        }