Exemplo n.º 1
0
        public frmMain()
        {
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            InitializeComponent();

            var seamCarvingMethods = ((SeamCarvingMethod[])Enum.GetValues(typeof(SeamCarvingMethod))).ToList();

            try
            {
                SeamCarverGPU.InitGPU();
            }
            catch
            {
                seamCarvingMethods.Remove(SeamCarvingMethod.GPU);
                MessageBox.Show("Unable to detect cuda gpu.");
            }
            foreach (var enumValue in seamCarvingMethods)
            {
                cmbSeamCarvingMethod.Items.Add(enumValue.ToString());
            }
            var energyFuncTypes = Enum.GetValues(typeof(EnergyFuncType));

            foreach (var enumValue in energyFuncTypes)
            {
                cmbEnergyFuncType.Items.Add(enumValue.ToString());
            }
        }
Exemplo n.º 2
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            pbInput.Image = InputBitmap;

            EnergyFuncType    energyFuncType    = (EnergyFuncType)cmbEnergyFuncType.SelectedIndex;
            Bitmap            resultBitmap      = null;
            SeamCarvingMethod seamCarvingMethod = (SeamCarvingMethod)cmbSeamCarvingMethod.SelectedIndex;
            double            widthRatio        = double.Parse(tbWidthRatio.Text);
            double            heightRatio       = double.Parse(tbHeightRatio.Text);

            int newWidth  = (int)Math.Round(widthRatio * InputBitmap.Width);
            int newHeight = (int)Math.Round(heightRatio * InputBitmap.Height);
            var stopwatch = new Stopwatch();

            switch (seamCarvingMethod)
            {
            case SeamCarvingMethod.CAIR:
                Thread.Sleep(100);
                stopwatch.Start();
                SeamCarverCair cairCarver = new SeamCarverCair(energyFuncType, cbHd.Checked, cbForwardEnergy.Checked, cbParallel.Checked, tbCairAppPath.Text);
                resultBitmap = cairCarver.Generate(InputBitmap, newWidth, newHeight);
                stopwatch.Stop();
                break;

            default:
            case SeamCarvingMethod.Standart:
                stopwatch.Start();
                SeamCarverStandart standrtCarver = new SeamCarverStandart(energyFuncType, cbHd.Checked, cbForwardEnergy.Checked, cbParallel.Checked,
                                                                          double.Parse(tbNeighbourCountRatio.Text), int.Parse(tbBlockSize.Text));
                resultBitmap = standrtCarver.Generate(InputBitmap, newWidth, newHeight);
                stopwatch.Stop();
                break;

            case SeamCarvingMethod.GPU:
                stopwatch.Start();
                SeamCarverGPU gpuCarver = new SeamCarverGPU(energyFuncType, cbHd.Checked, cbForwardEnergy.Checked, cbParallel.Checked,
                                                            int.Parse(tbBlockSize.Text));
                resultBitmap = gpuCarver.Generate(InputBitmap, newWidth, newHeight);
                stopwatch.Stop();
                break;
            }
            tbCalculationTime.Text = stopwatch.Elapsed.ToString();

            pbOutput.Image = resultBitmap;
        }
Exemplo n.º 3
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            pbInput.Image = InputBitmap;

            EnergyFuncType energyFuncType = (EnergyFuncType)cmbEnergyFuncType.SelectedIndex;
            Bitmap resultBitmap = null;
            SeamCarvingMethod seamCarvingMethod = (SeamCarvingMethod)cmbSeamCarvingMethod.SelectedIndex;
            double widthRatio = double.Parse(tbWidthRatio.Text);
            double heightRatio = double.Parse(tbHeightRatio.Text);

            int newWidth = (int)Math.Round(widthRatio * InputBitmap.Width);
            int newHeight = (int)Math.Round(heightRatio * InputBitmap.Height);
            var stopwatch = new Stopwatch();
            switch (seamCarvingMethod)
            {
                case SeamCarvingMethod.CAIR:
                    Thread.Sleep(100);
                    stopwatch.Start();
                    SeamCarverCair cairCarver = new SeamCarverCair(energyFuncType, cbHd.Checked, cbForwardEnergy.Checked, cbParallel.Checked, tbCairAppPath.Text);
                    resultBitmap = cairCarver.Generate(InputBitmap,newWidth, newHeight);
                    stopwatch.Stop();
                    break;
                default:
                case SeamCarvingMethod.Standart:
                    stopwatch.Start();
                    SeamCarverStandart standrtCarver = new SeamCarverStandart(energyFuncType, cbHd.Checked, cbForwardEnergy.Checked, cbParallel.Checked,
                        double.Parse(tbNeighbourCountRatio.Text), int.Parse(tbBlockSize.Text));
                    resultBitmap = standrtCarver.Generate(InputBitmap, newWidth, newHeight);
                    stopwatch.Stop();
                    break;
                case SeamCarvingMethod.GPU:
                    stopwatch.Start();
                    SeamCarverGPU gpuCarver = new SeamCarverGPU(energyFuncType, cbHd.Checked, cbForwardEnergy.Checked, cbParallel.Checked,
                        int.Parse(tbBlockSize.Text));
                    resultBitmap = gpuCarver.Generate(InputBitmap, newWidth, newHeight);
                    stopwatch.Stop();
                    break;
            }
            tbCalculationTime.Text = stopwatch.Elapsed.ToString();

            pbOutput.Image = resultBitmap;
        }