Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var wb = OpenCvSharp.XPhoto.SimpleWB.Create();

            wb.P         = 0.2f;
            wb.OutputMin = 8.0f;

            var decodedFramesBlock = new TransformBlock <OpenCvSharp.Mat, OpenCvSharp.Mat>(
                mat =>
            {
                return(Task.Run(() => { wb.BalanceWhite(mat, mat); return mat; }));
            },
                new ExecutionDataflowBlockOptions
            {
                BoundedCapacity        = 10,
                MaxDegreeOfParallelism = 10,
                EnsureOrdered          = true,
            }
                );

            // var inputVideo = new OpenCvSharp.VideoCapture("2017_0928_105336_023.MOV");
            var inputVideo  = new OpenCvSharp.VideoCapture("YI004801.mp4");
            var outputVideo = new OpenCvSharp.VideoWriter("out_lina.mp4", "avc1", inputVideo.Fps, new OpenCvSharp.Size(inputVideo.FrameWidth, inputVideo.FrameHeight));

            ConcurrentQueue <OpenCvSharp.Mat> decodedFramesQueue = new ConcurrentQueue <OpenCvSharp.Mat>();

            // decoder
            Task decodeTask = Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    var mat = inputVideo.RetrieveMat();
                    if (mat.Height == 0)
                    {
                        Console.WriteLine("DECODED");
                        decodedFramesBlock.Complete();
                        break;
                    }
                    decodedFramesBlock.SendAsync(mat).Wait();
                }
            });

            Task writeTask = Task.Factory.StartNew(() =>
            {
                int c = 0;
                OpenCvSharp.Mat mat;
                while (!decodedFramesBlock.Completion.IsCompleted)
                {
                    ++c;
                    mat = decodedFramesBlock.Receive();
                    outputVideo.Write(mat);
                    mat.Dispose();
                    Console.WriteLine("Frame " + c + " of " + inputVideo.FrameCount);
                }
            });

            decodeTask.Wait();
            writeTask.Wait();

            Console.WriteLine("ready!");
            outputVideo.Release();

            /*
             * var channels = img.Split();
             * channels = channels.Select(c => c.EqualizeHist()).ToArray();
             * foreach(var channel in channels)
             * {
             *  channel.ConvertTo(channel, channel.Type(), 0.9, 0);
             * }
             * OpenCvSharp.Cv2.Merge(channels, img);
             */
        }
Exemplo n.º 3
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
        }