Esempio n. 1
0
        private void RecordFileSettingButton_Click(object sender, EventArgs e)
        {
            var isActive = (bool)this.recordFileSettingButton.Tag;

            if (isActive == false)
            {
                return;
            }

            if (this.Root.Recorder.IsRecording(this._currentRecordType))
            {
                return;
            }

            var dialog = new Fire_Detector.Dialog.RecordDialog();

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            this._currentRecordType = dialog.RecordingType;
            this._currentResolution = dialog.Resolution;
            this.ShowDetectionBoxes = dialog.ShowDetectionBoxes;
            this.ShowGmap           = dialog.ShowGmap;
        }
Esempio n. 2
0
        private void RbChanged(object sender, RoutedEventArgs e)
        {
            RadioButton radio = sender as RadioButton;

            if (radio == null)
            {
                return;
            }
            string text = radio.Content as string;

            if (string.Equals(text, "原画"))
            {
                _tranformSize = new OpenCvSharp.Size(0, 0);
            }
            else if (string.Equals(text, "1080p"))
            {
                _tranformSize = new OpenCvSharp.Size(1920, 1080);
            }
            else if (string.Equals(text, "720p"))
            {
                _tranformSize = new OpenCvSharp.Size(1280, 720);
            }
            else if (string.Equals(text, "480p"))
            {
                _tranformSize = new OpenCvSharp.Size(854, 480);
            }
        }
Esempio n. 3
0
        public µImage(ImageType type, Int32 width, Int32 height)
        {
            var µsize = new OpenCvSharp.Size(); 
            µsize.Width = width;
            µsize.Height = height;

            switch (type) {
                case ImageType.U8:
                    _image = new OpenCvSharp.Mat(µsize, OpenCvSharp.MatType.CV_8U);
                    break;
                case ImageType.U16:
                    _image = new OpenCvSharp.Mat(µsize, OpenCvSharp.MatType.CV_16U);
                    break;
                default:
                    Debug.Fail("Unknown image type!");
                    break;
            }
        }
Esempio n. 4
0
        public void SetInputSize(int width, int height, int inChannels)
        {
            inW  = width; inH = height;
            inCh = inChannels;
            int _outW = 0, _outH = 0;

            Adjustment(width, height, out _outW, out _outH);
            outW = _outW; outH = _outH;

            var inS  = new OpenCvSharp.Size(inW, inH);
            var outS = new OpenCvSharp.Size(outW, outH);

            Input      = new BufferField(GPU, inS, inCh);
            Output     = new BufferField(GPU, outS, outCh);
            Sigma      = new BufferField(GPU, outS, outCh);
            Propagater = new BufferField(GPU, inS, inCh);

            ConfirmField();
        }
Esempio n. 5
0
        public void Confirm(OpenCvSharp.Size sourceSize)
        {
            Layers[0].property.SetInputSize(sourceSize.Width, sourceSize.Height, LearningReader.ReadChannels);
            for (int i = 1; i < Layers.Count; i++)
            {
                Layers[i].property.SetInputSize(
                    Layers[i - 1].property.Output.Width,
                    Layers[i - 1].property.Output.Height,
                    Layers[i - 1].property.Output.Channels);
            }

            for (int i = 0; i < Layers.Count - 1; i++)
            {
                Layers[i + 1].property.Input = Layers[i].property.Output;
                Layers[i].property.Sigma     = Layers[i + 1].property.Propagater;
            }

            if (LearningReader != null)
            {
                LearningReader.ModelReflection(GPU, new Common.ModelEdgeParameter()
                {
                    InputSize      = new OpenCvSharp.Size(Layers[0].property.Input.Width, Layers[0].property.Input.Height),
                    InputChannels  = Layers[0].property.Input.Channels,
                    OutputSize     = new OpenCvSharp.Size(Layers[Layers.Count - 1].property.Output.Width, Layers[Layers.Count - 1].property.Output.Height),
                    OutputChannels = Layers[Layers.Count - 1].property.Output.Channels,
                });
                LearningReader.Start();
            }

            if (InferenceReader != null)
            {
                InferenceReader.ModelReflection(GPU, new Common.ModelEdgeParameter()
                {
                    InputSize      = new OpenCvSharp.Size(Layers[0].property.Input.Width, Layers[0].property.Input.Height),
                    InputChannels  = Layers[0].property.Input.Channels,
                    OutputSize     = new OpenCvSharp.Size(Layers[Layers.Count - 1].property.Output.Width, Layers[Layers.Count - 1].property.Output.Height),
                    OutputChannels = Layers[Layers.Count - 1].property.Output.Channels,
                });
                InferenceReader.Start();
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: imagesimcli <comparison type (inter, intra)> <folder of file 1 .. N>");
            }

            var compare_type = args[0];

            if (compare_type.Equals("inter", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.WriteLine("Enumerating files...");
                var paths = new List <string>();
                foreach (var path in args.Skip(1))
                {
                    PopulateFiles(path, paths);
                }
                if (paths.Count < 2)
                {
                    Console.WriteLine("Error: at least 2 files needed. Aborting.");
                    return;
                }
                Console.WriteLine($"{paths.Count} files found");

                Console.Write($"Calculating hashes: 0 of {paths.Count}");
                var hashes  = new Dictionary <string, ulong>(paths.Count);
                var index   = 0;
                var clampTo = new OpenCvSharp.Size(512, 512);
                foreach (var file in paths)
                {
                    var hash = PHash.DCT.GetImageHash(file, clampTo.Width, clampTo.Height);
                    hashes[file]       = hash;
                    Console.CursorLeft = 0;
                    Console.Write($"Calculating hashes: {++index} of {paths.Count}");
                }
                Console.WriteLine("\nDone");

                /*Console.WriteLine("Running tests...");
                 * var hashList = hashes.ToList();
                 * index = 0;
                 * var results = RunInterTests(hashList, (kv1, kv2) =>
                 * {
                 *  var distance = PHash.DCT.HammingDistance(kv1.Value, kv2.Value);
                 *  return new { Index = index++, Left = kv1.Key, Right = kv2.Key, Distance = distance };
                 * }, selfTest: true);
                 *
                 * Console.WriteLine("Done\nResults:");
                 * foreach (var item in results)
                 * {
                 *  Console.WriteLine($"{item.Index}; {item.Left}; {item.Right}; {item.Distance}");
                 * }*/
                var headers = paths.Select(x => Path.GetFileNameWithoutExtension(x));
                var header  = ";" + string.Join(";", headers);
                Console.WriteLine(header);

                foreach (var left in paths)
                {
                    Console.Write(Path.GetFileNameWithoutExtension(left) + ";");
                    foreach (var right in paths)
                    {
                        var dist = PHash.DCT.HammingDistance(hashes[left], hashes[right]);
                        Console.Write($"{dist};");
                    }
                    Console.WriteLine();
                }
            }
            else if (compare_type.Equals("intra", StringComparison.InvariantCultureIgnoreCase))
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("Usage: imagesimcli intra <folder of file 1> <folder of file 2>");
                }
                var files1 = new List <string>();
                var files2 = new List <string>();
                PopulateFiles(args[1], files1);
                PopulateFiles(args[2], files2);

                files1.Sort();
                files2.Sort();

                var total = files1.Count + files2.Count;
                Console.Write($"Calculating hashes: 0 of {total}");
                var hashes  = new Dictionary <string, ulong>(total);
                var index   = 0;
                var clampTo = new OpenCvSharp.Size(512, 512);
                foreach (var file in files1.Concat(files2))
                {
                    var hash = PHash.DCT.GetImageHash(file, clampTo.Width, clampTo.Height);
                    hashes[file]       = hash;
                    Console.CursorLeft = 0;
                    Console.Write($"Calculating hashes: {++index} of {total}");
                }
                Console.WriteLine("\nDone");

                var headers = files2.Select(x => Path.GetFileNameWithoutExtension(x));
                var header  = ";" + string.Join(";", headers);
                Console.WriteLine(header);

                foreach (var left in files1)
                {
                    Console.Write(Path.GetFileNameWithoutExtension(left) + ";");
                    foreach (var right in files2)
                    {
                        var dist = PHash.DCT.HammingDistance(hashes[left], hashes[right]);
                        Console.Write($"{dist};");
                    }
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Unknown comparison type");
                return;
            }
        }
 public static PythonTuple ToTuple(this OpenCvSharp.Size size)
 {
     return(new PythonTuple(new[] { size.Width, size.Height }));
 }
Esempio n. 8
0
 public static Size ToSize(this OpenCvSharp.Size s)
 {
     return(new Size(s.Width, s.Height));
 }
Esempio n. 9
0
        private void button3_Click(object sender, EventArgs e)
        {
            System.Environment.CurrentDirectory = apppath + "\\main";

            string directoryName = apppath;
            string fileName      = "temp";
            string extension     = ".png";

            if (openFileDialog1.FileName != "")
            {
                directoryName = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
                fileName      = System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
                extension     = System.IO.Path.GetExtension(openFileDialog1.FileName);
            }

            pictureBox2.Image = CreateImage(string.Format(@"results\calendar\output_{0:D4}" + ".png", 1));
            string outfile = "";

            outfile = directoryName + "\\" + fileName + "_super_res.avi";

            OpenCvSharp.Size sz = new OpenCvSharp.Size(pictureBox2.Image.Width, pictureBox2.Image.Height);
            int codec           = 0; // コーデック(AVI)
            var EncodedFormat   = OpenCvSharp.FourCC.MJPG;

            OpenCvSharp.VideoWriter vw = new OpenCvSharp.VideoWriter(outfile, EncodedFormat, Fps, sz, true);

            DirectoryInfo images  = new DirectoryInfo(@"results\calendar");
            int           filenum = 0;

            foreach (FileInfo file in images.GetFiles())
            {
                filenum++;
            }
            for (int i = 0; i < filenum; i++)
            {
                if (stopping)
                {
                    break;
                }
                string newfile = string.Format(@"results\calendar\output_{0:D4}" + ".png", i);

                if (!System.IO.File.Exists(newfile))
                {
                    continue;
                }
                var img = OpenCvSharp.Cv2.ImRead(newfile, OpenCvSharp.ImreadModes.Color);
                //if (fileName != "temp")
                //{
                //    OpenCvSharp.Cv2.Resize(img, img, OpenCvSharp.Size.Zero, pictureBox1.Width, pictureBox1.Height, OpenCvSharp.InterpolationFlags.Cubic);
                //}

                pictureBox2.Image = CreateImage(newfile);
                newfile           = string.Format(@"LR\calendar\{0:D4}" + ".png", i);
                if (!System.IO.File.Exists(newfile))
                {
                    continue;
                }
                pictureBox1.Image = CreateImage(newfile);
                vw.Write(img);
            }
            vw.Dispose();
            stopping = false;
        }
Esempio n. 10
0
        private void finalProc()
        {
            System.Environment.CurrentDirectory = apppath;

            if (File.Exists(apppath + @"\tecoGAN.mp4"))
            {
                File.Delete(apppath + @"\tecoGAN.mp4");
            }
            var app = new System.Diagnostics.ProcessStartInfo();

            app.FileName        = "cmd.exe";
            app.UseShellExecute = true;
            app.Arguments       = " /c png2Video_run.bat";
            if (!checkBox1.Checked)
            {
                app.Arguments += " (1/" + numericUpDown1.Value.ToString() + ") ";
            }
            else
            {
                app.Arguments += " " + numericUpDown1.Value.ToString();
            }
            var png2Video = System.Diagnostics.Process.Start(app);

            png2Video.EnableRaisingEvents = true;
            png2Video.WaitForExit();
            MessageBox.Show("finished");
            MessageBox.Show("finished");

            if (File.Exists(apppath + @"\tecoGAN.mp4"))
            {
                Form2 video = new Form2();
                video.axWindowsMediaPlayer1.URL = apppath + @"\tecoGAN.mp4";
                video.Show();
            }

#if false
            System.Environment.CurrentDirectory = apppath + "\\main";

            string directoryName = apppath;
            string fileName      = "temp";
            string extension     = ".png";

            if (openFileDialog1.FileName != "")
            {
                directoryName = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
                fileName      = System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
                extension     = System.IO.Path.GetExtension(openFileDialog1.FileName);
            }

            pictureBox2.Image = CreateImage(string.Format(@"tecoGAN\results\calendar\output_{0:D4}" + ".png", 1));
            string outfile = "";
            outfile = directoryName + "\\" + fileName + "_super_res.avi";
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }

            OpenCvSharp.Size sz        = new OpenCvSharp.Size(pictureBox2.Image.Width, pictureBox2.Image.Height);
            int codec                  = 0; // コーデック(AVI)
            var EncodedFormat          = OpenCvSharp.FourCC.MJPG;
            OpenCvSharp.VideoWriter vw = new OpenCvSharp.VideoWriter(outfile, EncodedFormat, Fps, sz, true);

            DirectoryInfo images  = new DirectoryInfo(@"tecoGAN\results\calendar");
            int           filenum = 0;
            foreach (FileInfo file in images.GetFiles())
            {
                filenum++;
            }

            progressBar1.Value   = 0;
            progressBar1.Maximum = filenum;
            for (int i = 0; i < filenum; i++)
            {
                if (stopping)
                {
                    break;
                }
                string newfile = string.Format(@"tecoGAN\results\calendar\output_{0:D4}" + ".png", i);

                if (!System.IO.File.Exists(newfile))
                {
                    continue;
                }
                var img = OpenCvSharp.Cv2.ImRead(newfile, OpenCvSharp.ImreadModes.Color);
                if (!checkBox1.Checked)
                {
                    OpenCvSharp.Cv2.Resize(img, img, new OpenCvSharp.Size((int)((float)img.Width * (float)numericUpDown1.Value), (int)((float)img.Height * (float)numericUpDown1.Value)), 0, 0);
                }
                else
                {
                    OpenCvSharp.Cv2.Resize(img, img, new OpenCvSharp.Size((int)(0.5f + (float)img.Width / (float)numericUpDown1.Value), (int)(0.5f + (float)img.Height / (float)numericUpDown1.Value)), 0, 0);
                }
                pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(img);

                //pictureBox2.Image = CreateImage(newfile);
                newfile = string.Format(@"tecoGAN\LR\calendar\{0:D4}" + ".png", i);
                if (!System.IO.File.Exists(newfile))
                {
                    continue;
                }
                pictureBox1.Image = CreateImage(newfile);
                vw.Write(img);
                progressBar1.Value++;
                progressBar1.Refresh();
                Application.DoEvents(); // 非推奨
            }
            vw.Dispose();
            stopping = false;
            MessageBox.Show("finished");

            if (File.Exists(outfile))
            {
                Form2 video = new Form2();
                video.axWindowsMediaPlayer1.URL = outfile;
                video.Show();
            }
            progressBar1.Value = 0;
#endif
        }
Esempio n. 11
0
 public Vector2(OpenCvSharp.Size size) : this(size.Width, size.Height)
 {
 }
Esempio n. 12
0
        public static void µReadDICONDEFile(µImage destination, string fileName)
        {
            string aFileName = fileName;

            var mIOD = (new IOD(aFileName));

            int mColumnCount = DICONDEParserUtility.GetDICONDEAttributeAsInt(mIOD.XDocument, "(0028,0011)");          //width
            int mRowCount    = DICONDEParserUtility.GetDICONDEAttributeAsInt(mIOD.XDocument, "(0028,0010)");          //height

            bool aPixelPaddingValueExist = DICONDEParserUtility.DoesDICONDEAttributeExist(mIOD.XDocument, "(0028,0120)");
            int  aPixelPaddingValue      = DICONDEParserUtility.GetDICONDEAttributeAsInt(mIOD.XDocument, "(0028,0120)");

            int aPixelBitsAllocated = DICONDEParserUtility.GetDICONDEAttributeAsInt(mIOD.XDocument, "(0028,0100)");

            ushort aPixelPaddingValue16;

            aPixelPaddingValue16 = 0;

            int aWindowCenter = DICONDEParserUtility.GetDICONDEAttributeAsInt(mIOD.XDocument, "(0028,1050)");
            int aWindowWidth  = DICONDEParserUtility.GetDICONDEAttributeAsInt(mIOD.XDocument, "(0028,1051)");

            var aPixelDataQuery = from Element in mIOD.XDocument.Descendants("DataElement")
                                  where Element.Attribute("Tag").Value.Equals("(7FE0,0010)")
                                  select Element;

            // Get the start position of the stream for the pixel data attribute
            long aStreamPosition = Convert.ToInt64(aPixelDataQuery.Last().Attribute("StreamPosition").Value);

            BinaryReader aBinaryReader = new BinaryReader(File.Open(aFileName, FileMode.Open, FileAccess.Read, FileShare.Read));

            // Set the stream position of the binary reader to first pixel
            aBinaryReader.BaseStream.Position = aStreamPosition;

            OpenCvSharp.Mat image = null;

            var size = new OpenCvSharp.Size();

            size.Width  = mColumnCount;
            size.Height = mRowCount;

            long length = aBinaryReader.BaseStream.Length;             //! Important to get length outside of the cycle, otherwise too sloooow

            if (16 == aPixelBitsAllocated)
            {
                image = new OpenCvSharp.Mat(size, OpenCvSharp.MatType.CV_16U);
                var mat16   = new OpenCvSharp.Mat <ushort>(image);
                var indexer = mat16.GetIndexer();

                for (int aRowIndex = 0; aRowIndex < mRowCount; aRowIndex++)
                {
                    for (int aColumnIndex = 0; aColumnIndex < mColumnCount; aColumnIndex++)
                    {
                        // For some images, the pixel buffer is smaller than '2Byte * RowCount * ColumnCount'
                        // That's why we need the check...
                        if (aBinaryReader.BaseStream.Position - 2 < length)
                        {
                            byte   aByte0      = aBinaryReader.ReadByte();
                            byte   aByte1      = aBinaryReader.ReadByte();
                            ushort aPixelValue = Convert.ToUInt16((aByte1 << 8) + aByte0);
                            // Check for Pixel Padding Value
                            if ((aPixelPaddingValueExist) && (aPixelValue == aPixelPaddingValue16))
                            {
                                aPixelValue = UInt16.MinValue;
                            }
                            indexer[aRowIndex, aColumnIndex] = aPixelValue;
                            // Rescale handling
                            //aPixelValue = aPixelValue * aRescaleSlope + aRescaleIntercept;
                            // Value of the voxel is stored in Hounsfield Units
                            //mHounsfieldPixelBuffer[aRowIndex, aColumnIndex] = aPixelValue;
                        }
                    }
                }
                OpenCvSharp.Cv2.CopyTo(mat16, destination._image);
            }
            else
            {
                image = new OpenCvSharp.Mat(size, OpenCvSharp.MatType.CV_8U);
                var mat8    = new OpenCvSharp.Mat <byte>(image);
                var indexer = mat8.GetIndexer();
                for (int aRowIndex = 0; aRowIndex < mRowCount; aRowIndex++)
                {
                    for (int aColumnIndex = 0; aColumnIndex < mColumnCount; aColumnIndex++)
                    {
                        if (aBinaryReader.BaseStream.Position - 2 < length)
                        {
                            byte aPixelValue = aBinaryReader.ReadByte();
                            if ((aPixelPaddingValueExist) && (aPixelValue == aPixelPaddingValue16))
                            {
                                aPixelValue = 0;
                            }
                            indexer[aRowIndex, aColumnIndex] = aPixelValue;
                        }
                    }
                }
                OpenCvSharp.Cv2.CopyTo(mat8, destination._image);
            }
        }