j4ggi

AsciiArtEmguCv

Jul 28th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 39.74 KB | None | 0 0
  1. ////////////////////////////////////////////////////
  2. //FORM1
  3. ///////////////////////////////////////////////////
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Threading;
  13. using System.Windows.Forms;
  14. using Emgu.CV;
  15. using Emgu.Util;
  16. using Emgu.CV.Structure;
  17. using System.IO;
  18. using System.Drawing.Drawing2D;
  19.  
  20. namespace AsciiArtEmguCv
  21. {
  22.     public partial class Form1 : Form
  23.     {
  24.         String[] chars = File.ReadAllLines("c.txt");
  25.         Image img, scaled;
  26.         Image<Gray, Byte>gray;
  27.         Capture camera;
  28.         int sizex = 200, sizey = 200;
  29.         Form3 f3 = new Form3();
  30.         Form2 f2 = new Form2(), f22 = new Form2();
  31.         double gamma = 1.0, thresh = 1, threshlink = 1;
  32.         public Form1()
  33.         {
  34.             InitializeComponent();
  35.             trackBar1.Value = (int)(gamma*25);
  36.  
  37.             numericUpDown1.Value = sizex;
  38.             numericUpDown2.Value = sizey;
  39.             numericUpDown3.Value = timer1.Interval;
  40.         }
  41.  
  42.  
  43.         private void otwórzToolStripMenuItem_Click(object sender, EventArgs e)
  44.         {
  45.             openFileDialog1.ShowDialog();
  46.             try
  47.             {
  48.                 camera = new Capture(openFileDialog1.FileName);
  49.                 timer1.Enabled = true;
  50.             }
  51.             catch (TypeInitializationException e1)
  52.             {
  53.                 MessageBox.Show("Nie można otworzyć pliku!");
  54.             }
  55.             catch (NullReferenceException e2)
  56.             {
  57.                 MessageBox.Show("Nie można otworzyć pliku!");
  58.             }
  59.             catch (ArgumentException e3) { }
  60.         }
  61.         public static Image resize(Image img, Size maxsize, bool keepscale = true)
  62.         {
  63.             double scale;
  64.             double maxsize_scale = maxsize.Width / (double)(maxsize.Height);
  65.             double img_scale = img.Width / (double)(img.Height);
  66.             if (maxsize_scale >= img_scale)
  67.             {
  68.                 scale = maxsize.Height / (double)(img.Height);
  69.             }
  70.             else scale = maxsize.Width / (double)(img.Width);
  71.             if (!keepscale)
  72.                 return (Image)(new Bitmap(img, maxsize));
  73.             else return (Image)(new Bitmap(img, new Size((int)(img.Width * scale), (int)(img.Height * scale))));
  74.         }
  75.         private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
  76.         {
  77.             Application.Exit();
  78.         }
  79.  
  80.         private void otwórzObrazToolStripMenuItem_Click(object sender, EventArgs e)
  81.         {
  82.             openFileDialog1.ShowDialog();
  83.             try
  84.             {
  85.                 img = new Bitmap(openFileDialog1.FileName);
  86.                 checkBox5.Checked = true;
  87.                 imgs();
  88.                 button6.Enabled = true;
  89.             }
  90.             catch (NullReferenceException e2)
  91.             {
  92.                 MessageBox.Show("Nie można otworzyć pliku!");
  93.             }
  94.             catch (ArgumentException e1) { }
  95.         }
  96.  
  97.         private void użyjKameryToolStripMenuItem_Click(object sender, EventArgs e)
  98.         {
  99.             try
  100.             {
  101.                 camera = new Capture();
  102.                 timer1.Enabled = true;
  103.             }
  104.             catch (TypeInitializationException e1)
  105.             {
  106.                 MessageBox.Show("Nie można otworzyć pliku!");
  107.             }
  108.             catch (NullReferenceException e2)
  109.             {
  110.                 MessageBox.Show("Nie można otworzyć pliku!");
  111.             }
  112.             catch (ArgumentException e3) { }
  113.         }
  114.  
  115.         private void imgs()
  116.         {
  117.             scaled = resize(img, new Size(sizex, sizey));
  118.             gray = new Image<Gray, Byte>(new Bitmap(scaled));
  119.             gray._GammaCorrect(gamma);
  120.             if (checkBox6.Checked)
  121.                 if (radioButton2.Checked)
  122.                     gray = gray.Xor(gray.Canny(thresh, threshlink));
  123.                 else
  124.                     gray = gray.Canny(thresh, threshlink);
  125.             if(checkBox2.Checked)
  126.                 gray._EqualizeHist();
  127.             if (checkBox1.Checked)
  128.                 gray._Not();
  129.             if (checkBox3.Checked)
  130.                 gray._Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL);
  131.             if (checkBox4.Checked)
  132.                 gray._Flip(Emgu.CV.CvEnum.FLIP.VERTICAL);
  133.             if (f2.IsDisposed)
  134.                 f2 = new Form2(img);
  135.             else f2.rysuj(img);
  136.             f2.Show();
  137.             if (f22.IsDisposed)
  138.                 f22= new Form2(gray.ToBitmap());
  139.             else f22.rysuj(gray.ToBitmap());
  140.             f22.Show();
  141.             analyze();
  142.         }
  143.         private char getchar(double c)
  144.         {
  145.             int n = 0;
  146.             double c1=0;
  147.             while((c1+=(255/chars.Length))<c)
  148.             {
  149.                 n++;
  150.             }
  151.             n = chars.Length - n;
  152.             while (n < 0) n++;
  153.             while (n >= chars.Length) n--;
  154.             return chars[n][0];            
  155.         }        
  156.         private void analyze()
  157.         {
  158.             if (f3.IsDisposed)
  159.                 f3 = new Form3();
  160.             string ascii = "";
  161.             double c = 0;
  162.             for (int i = 0; i < gray.Height-3; i+=3)
  163.             {
  164.                 for (int j = 0; j < gray.Width-2; j+=2 )
  165.                 {
  166.                     c = gray.GetSubRect(new Rectangle(new Point(j, i), new Size(2, 3))).GetAverage().Intensity;
  167.                     ascii += getchar(c);
  168.                   //  ascii += getchar(c);
  169.                 }
  170.                 ascii += "\n";
  171.             }
  172.             f3.label1.Text = ascii;
  173.             if (checkBox5.Checked)
  174.                 Clipboard.SetText(ascii);
  175.             f3.Show();
  176.         }
  177.  
  178.         private void button1_Click(object sender, EventArgs e)
  179.         {
  180.             fontDialog1.FixedPitchOnly = true;
  181.             fontDialog1.ShowDialog();
  182.             f3.label1.Font = fontDialog1.Font;
  183.         }
  184.  
  185.         private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  186.         {
  187.             sizex = (int)(numericUpDown1.Value);
  188.         }
  189.  
  190.         private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  191.         {
  192.             sizey = (int)(numericUpDown2.Value);
  193.         }
  194.  
  195.         private void numericUpDown3_ValueChanged(object sender, EventArgs e)
  196.         {
  197.             timer1.Interval = (int)(numericUpDown3.Value);
  198.         }
  199.  
  200.         private void timer1_Tick(object sender, EventArgs e)
  201.         {
  202.             try
  203.             {
  204.                 img = camera.QueryFrame().ToBitmap();
  205.                 imgs();
  206.             }
  207.             catch (NullReferenceException e1) { timer1.Enabled = false; }
  208.         }
  209.  
  210.         private void button2_Click(object sender, EventArgs e)
  211.         {
  212.             if (!timer1.Enabled)
  213.                 timer1.Enabled = true;
  214.             else
  215.                 timer1.Enabled = false;
  216.         }
  217.  
  218.         private void trackBar1_Scroll(object sender, EventArgs e)
  219.         {
  220.             gamma = trackBar1.Value / 25.0;
  221.         }
  222.  
  223.         private void button6_Click(object sender, EventArgs e)
  224.         {
  225.             imgs();
  226.         }
  227.  
  228.         private void checkBox6_CheckedChanged(object sender, EventArgs e)
  229.         {
  230.             if (checkBox6.Checked)
  231.                 groupBox1.Enabled = true;
  232.             else
  233.                 groupBox1.Enabled = false;
  234.         }
  235.  
  236.         private void trackBar2_Scroll(object sender, EventArgs e)
  237.         {
  238.             thresh = trackBar2.Value;
  239.         }
  240.  
  241.         private void trackBar3_Scroll(object sender, EventArgs e)
  242.         {
  243.             threshlink = trackBar3.Value;
  244.         }
  245.     }
  246. }
  247.  
  248. ////////////////////////////////////////////////////////////////////
  249. //Form1.designer
  250.  
  251. namespace AsciiArtEmguCv
  252. {
  253.     partial class Form1
  254.     {
  255.         /// <summary>
  256.         /// Required designer variable.
  257.         /// </summary>
  258.         private System.ComponentModel.IContainer components = null;
  259.  
  260.         /// <summary>
  261.         /// Clean up any resources being used.
  262.         /// </summary>
  263.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  264.         protected override void Dispose(bool disposing)
  265.         {
  266.             if (disposing && (components != null))
  267.             {
  268.                 components.Dispose();
  269.             }
  270.             base.Dispose(disposing);
  271.         }
  272.  
  273.         #region Windows Form Designer generated code
  274.  
  275.         /// <summary>
  276.         /// Required method for Designer support - do not modify
  277.         /// the contents of this method with the code editor.
  278.         /// </summary>
  279.         private void InitializeComponent()
  280.         {
  281.             this.components = new System.ComponentModel.Container();
  282.             this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  283.             this.menuStrip1 = new System.Windows.Forms.MenuStrip();
  284.             this.plikToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  285.             this.otwórzObrazToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  286.             this.otwórzToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  287.             this.użyjKameryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  288.             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
  289.             this.zamknijToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  290.             this.label1 = new System.Windows.Forms.Label();
  291.             this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  292.             this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  293.             this.label2 = new System.Windows.Forms.Label();
  294.             this.label3 = new System.Windows.Forms.Label();
  295.             this.fontDialog1 = new System.Windows.Forms.FontDialog();
  296.             this.button1 = new System.Windows.Forms.Button();
  297.             this.checkBox1 = new System.Windows.Forms.CheckBox();
  298.             this.timer1 = new System.Windows.Forms.Timer(this.components);
  299.             this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
  300.             this.label4 = new System.Windows.Forms.Label();
  301.             this.button2 = new System.Windows.Forms.Button();
  302.             this.trackBar1 = new System.Windows.Forms.TrackBar();
  303.             this.label5 = new System.Windows.Forms.Label();
  304.             this.checkBox2 = new System.Windows.Forms.CheckBox();
  305.             this.button3 = new System.Windows.Forms.Button();
  306.             this.button4 = new System.Windows.Forms.Button();
  307.             this.button5 = new System.Windows.Forms.Button();
  308.             this.checkBox3 = new System.Windows.Forms.CheckBox();
  309.             this.checkBox4 = new System.Windows.Forms.CheckBox();
  310.             this.button6 = new System.Windows.Forms.Button();
  311.             this.checkBox5 = new System.Windows.Forms.CheckBox();
  312.             this.checkBox6 = new System.Windows.Forms.CheckBox();
  313.             this.groupBox1 = new System.Windows.Forms.GroupBox();
  314.             this.radioButton1 = new System.Windows.Forms.RadioButton();
  315.             this.radioButton2 = new System.Windows.Forms.RadioButton();
  316.             this.trackBar2 = new System.Windows.Forms.TrackBar();
  317.             this.trackBar3 = new System.Windows.Forms.TrackBar();
  318.             this.label6 = new System.Windows.Forms.Label();
  319.             this.label7 = new System.Windows.Forms.Label();
  320.             this.menuStrip1.SuspendLayout();
  321.             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  322.             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  323.             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
  324.             ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  325.             this.groupBox1.SuspendLayout();
  326.             ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit();
  327.             ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
  328.             this.SuspendLayout();
  329.             //
  330.             // openFileDialog1
  331.             //
  332.             this.openFileDialog1.FileName = "openFileDialog1";
  333.             //
  334.             // menuStrip1
  335.             //
  336.             this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  337.             this.plikToolStripMenuItem});
  338.             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
  339.             this.menuStrip1.Name = "menuStrip1";
  340.             this.menuStrip1.Size = new System.Drawing.Size(368, 24);
  341.             this.menuStrip1.TabIndex = 0;
  342.             this.menuStrip1.Text = "menuStrip1";
  343.             //
  344.             // plikToolStripMenuItem
  345.             //
  346.             this.plikToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  347.             this.otwórzObrazToolStripMenuItem,
  348.             this.otwórzToolStripMenuItem,
  349.             this.użyjKameryToolStripMenuItem,
  350.             this.toolStripSeparator1,
  351.             this.zamknijToolStripMenuItem});
  352.             this.plikToolStripMenuItem.Name = "plikToolStripMenuItem";
  353.             this.plikToolStripMenuItem.Size = new System.Drawing.Size(38, 20);
  354.             this.plikToolStripMenuItem.Text = "Plik";
  355.             //
  356.             // otwórzObrazToolStripMenuItem
  357.             //
  358.             this.otwórzObrazToolStripMenuItem.Name = "otwórzObrazToolStripMenuItem";
  359.             this.otwórzObrazToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
  360.             this.otwórzObrazToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
  361.             this.otwórzObrazToolStripMenuItem.Text = "Otwórz Obraz";
  362.             this.otwórzObrazToolStripMenuItem.Click += new System.EventHandler(this.otwórzObrazToolStripMenuItem_Click);
  363.             //
  364.             // otwórzToolStripMenuItem
  365.             //
  366.             this.otwórzToolStripMenuItem.Name = "otwórzToolStripMenuItem";
  367.             this.otwórzToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
  368.             this.otwórzToolStripMenuItem.Text = "Otwórz Wideo";
  369.             this.otwórzToolStripMenuItem.Click += new System.EventHandler(this.otwórzToolStripMenuItem_Click);
  370.             //
  371.             // użyjKameryToolStripMenuItem
  372.             //
  373.             this.użyjKameryToolStripMenuItem.Name = "użyjKameryToolStripMenuItem";
  374.             this.użyjKameryToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
  375.             this.użyjKameryToolStripMenuItem.Text = "Użyj kamery";
  376.             this.użyjKameryToolStripMenuItem.Click += new System.EventHandler(this.użyjKameryToolStripMenuItem_Click);
  377.             //
  378.             // toolStripSeparator1
  379.             //
  380.             this.toolStripSeparator1.Name = "toolStripSeparator1";
  381.             this.toolStripSeparator1.Size = new System.Drawing.Size(186, 6);
  382.             //
  383.             // zamknijToolStripMenuItem
  384.             //
  385.             this.zamknijToolStripMenuItem.Name = "zamknijToolStripMenuItem";
  386.             this.zamknijToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Q)));
  387.             this.zamknijToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
  388.             this.zamknijToolStripMenuItem.Text = "Zamknij";
  389.             this.zamknijToolStripMenuItem.Click += new System.EventHandler(this.zamknijToolStripMenuItem_Click);
  390.             //
  391.             // label1
  392.             //
  393.             this.label1.AutoSize = true;
  394.             this.label1.Location = new System.Drawing.Point(15, 101);
  395.             this.label1.Name = "label1";
  396.             this.label1.Size = new System.Drawing.Size(45, 13);
  397.             this.label1.TabIndex = 1;
  398.             this.label1.Text = "Rozmiar";
  399.             //
  400.             // numericUpDown1
  401.             //
  402.             this.numericUpDown1.Location = new System.Drawing.Point(38, 126);
  403.             this.numericUpDown1.Maximum = new decimal(new int[] {
  404.             1000,
  405.             0,
  406.             0,
  407.             0});
  408.             this.numericUpDown1.Name = "numericUpDown1";
  409.             this.numericUpDown1.Size = new System.Drawing.Size(71, 20);
  410.             this.numericUpDown1.TabIndex = 2;
  411.             this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  412.             //
  413.             // numericUpDown2
  414.             //
  415.             this.numericUpDown2.Location = new System.Drawing.Point(38, 152);
  416.             this.numericUpDown2.Maximum = new decimal(new int[] {
  417.             1000,
  418.             0,
  419.             0,
  420.             0});
  421.             this.numericUpDown2.Name = "numericUpDown2";
  422.             this.numericUpDown2.Size = new System.Drawing.Size(71, 20);
  423.             this.numericUpDown2.TabIndex = 2;
  424.             this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  425.             //
  426.             // label2
  427.             //
  428.             this.label2.AutoSize = true;
  429.             this.label2.Location = new System.Drawing.Point(15, 128);
  430.             this.label2.Name = "label2";
  431.             this.label2.Size = new System.Drawing.Size(17, 13);
  432.             this.label2.TabIndex = 1;
  433.             this.label2.Text = "X:";
  434.             //
  435.             // label3
  436.             //
  437.             this.label3.AutoSize = true;
  438.             this.label3.Location = new System.Drawing.Point(15, 154);
  439.             this.label3.Name = "label3";
  440.             this.label3.Size = new System.Drawing.Size(17, 13);
  441.             this.label3.TabIndex = 1;
  442.             this.label3.Text = "Y:";
  443.             //
  444.             // fontDialog1
  445.             //
  446.             this.fontDialog1.FixedPitchOnly = true;
  447.             //
  448.             // button1
  449.             //
  450.             this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  451.             this.button1.Location = new System.Drawing.Point(18, 188);
  452.             this.button1.Name = "button1";
  453.             this.button1.Size = new System.Drawing.Size(94, 42);
  454.             this.button1.TabIndex = 3;
  455.             this.button1.Text = "Czcionka Ascii Art";
  456.             this.button1.UseVisualStyleBackColor = true;
  457.             this.button1.Click += new System.EventHandler(this.button1_Click);
  458.             //
  459.             // checkBox1
  460.             //
  461.             this.checkBox1.AutoSize = true;
  462.             this.checkBox1.Location = new System.Drawing.Point(201, 129);
  463.             this.checkBox1.Name = "checkBox1";
  464.             this.checkBox1.Size = new System.Drawing.Size(94, 17);
  465.             this.checkBox1.TabIndex = 4;
  466.             this.checkBox1.Text = "Odwróć kolory";
  467.             this.checkBox1.UseVisualStyleBackColor = true;
  468.             //
  469.             // timer1
  470.             //
  471.             this.timer1.Interval = 30;
  472.             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
  473.             //
  474.             // numericUpDown3
  475.             //
  476.             this.numericUpDown3.Location = new System.Drawing.Point(15, 273);
  477.             this.numericUpDown3.Maximum = new decimal(new int[] {
  478.             1000,
  479.             0,
  480.             0,
  481.             0});
  482.             this.numericUpDown3.Name = "numericUpDown3";
  483.             this.numericUpDown3.Size = new System.Drawing.Size(94, 20);
  484.             this.numericUpDown3.TabIndex = 5;
  485.             this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged);
  486.             //
  487.             // label4
  488.             //
  489.             this.label4.AutoSize = true;
  490.             this.label4.Location = new System.Drawing.Point(15, 248);
  491.             this.label4.Name = "label4";
  492.             this.label4.Size = new System.Drawing.Size(161, 13);
  493.             this.label4.TabIndex = 1;
  494.             this.label4.Text = "Interwał stopera (wideo/kamera)";
  495.             //
  496.             // button2
  497.             //
  498.             this.button2.Location = new System.Drawing.Point(201, 250);
  499.             this.button2.Name = "button2";
  500.             this.button2.Size = new System.Drawing.Size(94, 43);
  501.             this.button2.TabIndex = 6;
  502.             this.button2.Text = "Pauza (wideo/kamera)";
  503.             this.button2.UseVisualStyleBackColor = true;
  504.             this.button2.Click += new System.EventHandler(this.button2_Click);
  505.             //
  506.             // trackBar1
  507.             //
  508.             this.trackBar1.LargeChange = 10;
  509.             this.trackBar1.Location = new System.Drawing.Point(15, 336);
  510.             this.trackBar1.Maximum = 50;
  511.             this.trackBar1.Minimum = 1;
  512.             this.trackBar1.Name = "trackBar1";
  513.             this.trackBar1.Size = new System.Drawing.Size(269, 45);
  514.             this.trackBar1.TabIndex = 7;
  515.             this.trackBar1.Value = 1;
  516.             this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
  517.             //
  518.             // label5
  519.             //
  520.             this.label5.AutoSize = true;
  521.             this.label5.Location = new System.Drawing.Point(15, 320);
  522.             this.label5.Name = "label5";
  523.             this.label5.Size = new System.Drawing.Size(43, 13);
  524.             this.label5.TabIndex = 1;
  525.             this.label5.Text = "Gamma";
  526.             //
  527.             // checkBox2
  528.             //
  529.             this.checkBox2.AutoSize = true;
  530.             this.checkBox2.Location = new System.Drawing.Point(201, 152);
  531.             this.checkBox2.Name = "checkBox2";
  532.             this.checkBox2.Size = new System.Drawing.Size(106, 17);
  533.             this.checkBox2.TabIndex = 8;
  534.             this.checkBox2.Text = "Zwiększ kontrast";
  535.             this.checkBox2.UseVisualStyleBackColor = true;
  536.             //
  537.             // button3
  538.             //
  539.             this.button3.Location = new System.Drawing.Point(15, 38);
  540.             this.button3.Name = "button3";
  541.             this.button3.Size = new System.Drawing.Size(75, 23);
  542.             this.button3.TabIndex = 9;
  543.             this.button3.Text = "Obraz";
  544.             this.button3.UseVisualStyleBackColor = true;
  545.             this.button3.Click += new System.EventHandler(this.otwórzObrazToolStripMenuItem_Click);
  546.             //
  547.             // button4
  548.             //
  549.             this.button4.Location = new System.Drawing.Point(117, 38);
  550.             this.button4.Name = "button4";
  551.             this.button4.Size = new System.Drawing.Size(75, 23);
  552.             this.button4.TabIndex = 9;
  553.             this.button4.Text = "Wideo";
  554.             this.button4.UseVisualStyleBackColor = true;
  555.             this.button4.Click += new System.EventHandler(this.otwórzToolStripMenuItem_Click);
  556.             //
  557.             // button5
  558.             //
  559.             this.button5.Location = new System.Drawing.Point(219, 38);
  560.             this.button5.Name = "button5";
  561.             this.button5.Size = new System.Drawing.Size(75, 23);
  562.             this.button5.TabIndex = 9;
  563.             this.button5.Text = "Kamera";
  564.             this.button5.UseVisualStyleBackColor = true;
  565.             this.button5.Click += new System.EventHandler(this.użyjKameryToolStripMenuItem_Click);
  566.             //
  567.             // checkBox3
  568.             //
  569.             this.checkBox3.AutoSize = true;
  570.             this.checkBox3.Location = new System.Drawing.Point(201, 175);
  571.             this.checkBox3.Name = "checkBox3";
  572.             this.checkBox3.Size = new System.Drawing.Size(117, 17);
  573.             this.checkBox3.TabIndex = 8;
  574.             this.checkBox3.Text = "Odbicie w poziomie";
  575.             this.checkBox3.UseVisualStyleBackColor = true;
  576.             //
  577.             // checkBox4
  578.             //
  579.             this.checkBox4.AutoSize = true;
  580.             this.checkBox4.Location = new System.Drawing.Point(201, 198);
  581.             this.checkBox4.Name = "checkBox4";
  582.             this.checkBox4.Size = new System.Drawing.Size(102, 17);
  583.             this.checkBox4.TabIndex = 8;
  584.             this.checkBox4.Text = "Odbicie w pione";
  585.             this.checkBox4.UseVisualStyleBackColor = true;
  586.             //
  587.             // button6
  588.             //
  589.             this.button6.Enabled = false;
  590.             this.button6.Location = new System.Drawing.Point(15, 67);
  591.             this.button6.Name = "button6";
  592.             this.button6.Size = new System.Drawing.Size(75, 23);
  593.             this.button6.TabIndex = 9;
  594.             this.button6.Text = "Odśwież";
  595.             this.button6.UseVisualStyleBackColor = true;
  596.             this.button6.Click += new System.EventHandler(this.button6_Click);
  597.             //
  598.             // checkBox5
  599.             //
  600.             this.checkBox5.AutoSize = true;
  601.             this.checkBox5.Location = new System.Drawing.Point(18, 376);
  602.             this.checkBox5.Name = "checkBox5";
  603.             this.checkBox5.Size = new System.Drawing.Size(246, 17);
  604.             this.checkBox5.TabIndex = 8;
  605.             this.checkBox5.Text = "Kopiuj AsciiArt do schowka po wygenerowaniu";
  606.             this.checkBox5.UseVisualStyleBackColor = true;
  607.             //
  608.             // checkBox6
  609.             //
  610.             this.checkBox6.AutoSize = true;
  611.             this.checkBox6.Location = new System.Drawing.Point(18, 418);
  612.             this.checkBox6.Name = "checkBox6";
  613.             this.checkBox6.Size = new System.Drawing.Size(123, 17);
  614.             this.checkBox6.TabIndex = 10;
  615.             this.checkBox6.Text = "Wykrywaj krawędzie";
  616.             this.checkBox6.UseVisualStyleBackColor = true;
  617.             this.checkBox6.CheckedChanged += new System.EventHandler(this.checkBox6_CheckedChanged);
  618.             //
  619.             // groupBox1
  620.             //
  621.             this.groupBox1.Controls.Add(this.radioButton2);
  622.             this.groupBox1.Controls.Add(this.radioButton1);
  623.             this.groupBox1.Controls.Add(this.trackBar3);
  624.             this.groupBox1.Controls.Add(this.trackBar2);
  625.             this.groupBox1.Controls.Add(this.label7);
  626.             this.groupBox1.Controls.Add(this.label6);
  627.             this.groupBox1.Enabled = false;
  628.             this.groupBox1.Location = new System.Drawing.Point(18, 441);
  629.             this.groupBox1.Name = "groupBox1";
  630.             this.groupBox1.Size = new System.Drawing.Size(319, 250);
  631.             this.groupBox1.TabIndex = 11;
  632.             this.groupBox1.TabStop = false;
  633.             //
  634.             // radioButton1
  635.             //
  636.             this.radioButton1.AutoSize = true;
  637.             this.radioButton1.Checked = true;
  638.             this.radioButton1.Location = new System.Drawing.Point(20, 19);
  639.             this.radioButton1.Name = "radioButton1";
  640.             this.radioButton1.Size = new System.Drawing.Size(74, 17);
  641.             this.radioButton1.TabIndex = 11;
  642.             this.radioButton1.TabStop = true;
  643.             this.radioButton1.Text = "Krawędzie";
  644.             this.radioButton1.UseVisualStyleBackColor = true;
  645.             //
  646.             // radioButton2
  647.             //
  648.             this.radioButton2.AutoSize = true;
  649.             this.radioButton2.Location = new System.Drawing.Point(20, 42);
  650.             this.radioButton2.Name = "radioButton2";
  651.             this.radioButton2.Size = new System.Drawing.Size(41, 17);
  652.             this.radioButton2.TabIndex = 11;
  653.             this.radioButton2.TabStop = true;
  654.             this.radioButton2.Text = "Xor";
  655.             this.radioButton2.UseVisualStyleBackColor = true;
  656.             //
  657.             // trackBar2
  658.             //
  659.             this.trackBar2.LargeChange = 10;
  660.             this.trackBar2.Location = new System.Drawing.Point(20, 112);
  661.             this.trackBar2.Maximum = 100;
  662.             this.trackBar2.Minimum = 1;
  663.             this.trackBar2.Name = "trackBar2";
  664.             this.trackBar2.Size = new System.Drawing.Size(269, 45);
  665.             this.trackBar2.TabIndex = 7;
  666.             this.trackBar2.Value = 1;
  667.             this.trackBar2.Scroll += new System.EventHandler(this.trackBar2_Scroll);
  668.             //
  669.             // trackBar3
  670.             //
  671.             this.trackBar3.LargeChange = 10;
  672.             this.trackBar3.Location = new System.Drawing.Point(16, 187);
  673.             this.trackBar3.Maximum = 100;
  674.             this.trackBar3.Minimum = 1;
  675.             this.trackBar3.Name = "trackBar3";
  676.             this.trackBar3.Size = new System.Drawing.Size(269, 45);
  677.             this.trackBar3.TabIndex = 7;
  678.             this.trackBar3.Value = 1;
  679.             this.trackBar3.Scroll += new System.EventHandler(this.trackBar3_Scroll);
  680.             //
  681.             // label6
  682.             //
  683.             this.label6.AutoSize = true;
  684.             this.label6.Location = new System.Drawing.Point(13, 86);
  685.             this.label6.Name = "label6";
  686.             this.label6.Size = new System.Drawing.Size(91, 13);
  687.             this.label6.TabIndex = 1;
  688.             this.label6.Text = "Próg znajdowania";
  689.             //
  690.             // label7
  691.             //
  692.             this.label7.AutoSize = true;
  693.             this.label7.Location = new System.Drawing.Point(13, 160);
  694.             this.label7.Name = "label7";
  695.             this.label7.Size = new System.Drawing.Size(73, 13);
  696.             this.label7.TabIndex = 1;
  697.             this.label7.Text = "Próg łączenia";
  698.             //
  699.             // Form1
  700.             //
  701.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  702.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  703.             this.ClientSize = new System.Drawing.Size(368, 734);
  704.             this.MinimumSize = this.ClientSize;
  705.             this.MaximumSize = this.ClientSize;
  706.             this.Controls.Add(this.groupBox1);
  707.             this.Controls.Add(this.button5);
  708.             this.Controls.Add(this.checkBox6);
  709.             this.Controls.Add(this.button4);
  710.             this.Controls.Add(this.button6);
  711.             this.Controls.Add(this.button3);
  712.             this.Controls.Add(this.checkBox5);
  713.             this.Controls.Add(this.checkBox4);
  714.             this.Controls.Add(this.checkBox3);
  715.             this.Controls.Add(this.checkBox2);
  716.             this.Controls.Add(this.trackBar1);
  717.             this.Controls.Add(this.button2);
  718.             this.Controls.Add(this.numericUpDown3);
  719.             this.Controls.Add(this.checkBox1);
  720.             this.Controls.Add(this.button1);
  721.             this.Controls.Add(this.numericUpDown2);
  722.             this.Controls.Add(this.numericUpDown1);
  723.             this.Controls.Add(this.label3);
  724.             this.Controls.Add(this.label2);
  725.             this.Controls.Add(this.label4);
  726.             this.Controls.Add(this.label5);
  727.             this.Controls.Add(this.label1);
  728.             this.Controls.Add(this.menuStrip1);
  729.             this.MainMenuStrip = this.menuStrip1;
  730.             this.Name = "Form1";
  731.             this.Text = "Form1";
  732.             this.menuStrip1.ResumeLayout(false);
  733.             this.menuStrip1.PerformLayout();
  734.             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  735.             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  736.             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
  737.             ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  738.             this.groupBox1.ResumeLayout(false);
  739.             this.groupBox1.PerformLayout();
  740.             ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit();
  741.             ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
  742.             this.ResumeLayout(false);
  743.             this.PerformLayout();
  744.  
  745.         }
  746.  
  747.         #endregion
  748.  
  749.         private System.Windows.Forms.OpenFileDialog openFileDialog1;
  750.         private System.Windows.Forms.MenuStrip menuStrip1;
  751.         private System.Windows.Forms.ToolStripMenuItem plikToolStripMenuItem;
  752.         private System.Windows.Forms.ToolStripMenuItem otwórzToolStripMenuItem;
  753.         private System.Windows.Forms.ToolStripMenuItem zamknijToolStripMenuItem;
  754.         private System.Windows.Forms.ToolStripMenuItem otwórzObrazToolStripMenuItem;
  755.         private System.Windows.Forms.ToolStripMenuItem użyjKameryToolStripMenuItem;
  756.         private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
  757.         private System.Windows.Forms.Label label1;
  758.         private System.Windows.Forms.NumericUpDown numericUpDown1;
  759.         private System.Windows.Forms.NumericUpDown numericUpDown2;
  760.         private System.Windows.Forms.Label label2;
  761.         private System.Windows.Forms.Label label3;
  762.         private System.Windows.Forms.Button button1;
  763.         public System.Windows.Forms.FontDialog fontDialog1;
  764.         private System.Windows.Forms.CheckBox checkBox1;
  765.         private System.Windows.Forms.Timer timer1;
  766.         private System.Windows.Forms.NumericUpDown numericUpDown3;
  767.         private System.Windows.Forms.Label label4;
  768.         private System.Windows.Forms.Button button2;
  769.         private System.Windows.Forms.TrackBar trackBar1;
  770.         private System.Windows.Forms.Label label5;
  771.         private System.Windows.Forms.CheckBox checkBox2;
  772.         private System.Windows.Forms.Button button3;
  773.         private System.Windows.Forms.Button button4;
  774.         private System.Windows.Forms.Button button5;
  775.         private System.Windows.Forms.CheckBox checkBox3;
  776.         private System.Windows.Forms.CheckBox checkBox4;
  777.         private System.Windows.Forms.Button button6;
  778.         private System.Windows.Forms.CheckBox checkBox5;
  779.         private System.Windows.Forms.CheckBox checkBox6;
  780.         private System.Windows.Forms.GroupBox groupBox1;
  781.         private System.Windows.Forms.RadioButton radioButton2;
  782.         private System.Windows.Forms.RadioButton radioButton1;
  783.         private System.Windows.Forms.TrackBar trackBar3;
  784.         private System.Windows.Forms.TrackBar trackBar2;
  785.         private System.Windows.Forms.Label label7;
  786.         private System.Windows.Forms.Label label6;
  787.     }
  788. }
  789.  
  790. ////////////////////////////////////////////////////////////////
  791. //FORM2
  792. ///////////////////////////////////////////////////////////////
  793. using System;
  794. using System.Collections.Generic;
  795. using System.ComponentModel;
  796. using System.Data;
  797. using System.Drawing;
  798. using System.Linq;
  799. using System.Text;
  800. using System.Threading.Tasks;
  801. using System.Windows.Forms;
  802. using Emgu.CV;
  803. using Emgu.Util;
  804. using Emgu.CV.Structure;
  805.  
  806. namespace AsciiArtEmguCv
  807. {
  808.     public partial class Form2 : Form
  809.     {
  810.         public Form2()
  811.         {
  812.             InitializeComponent();
  813.         }
  814.         public Form2(Image img)
  815.         {
  816.             InitializeComponent();
  817.             if (img.Size.Width > 1600 || img.Size.Height > 900)
  818.                 pictureBox1.Image = Form1.resize(img, new Size(1600, 900));
  819.             else
  820.                 pictureBox1.Image = img;
  821.         }
  822.         public void rysuj(Image img)
  823.         {
  824.             if (img.Size.Width > 1600 || img.Size.Height > 900)
  825.                 pictureBox1.Image = Form1.resize(img, new Size(1600, 900));
  826.             else
  827.                 pictureBox1.Image = img;
  828.         }
  829.     }
  830. }
  831. /////////////////////////////////////////////////
  832. //Form2.desinger
  833. namespace AsciiArtEmguCv
  834. {
  835.     partial class Form2
  836.     {
  837.         /// <summary>
  838.         /// Required designer variable.
  839.         /// </summary>
  840.         private System.ComponentModel.IContainer components = null;
  841.  
  842.         /// <summary>
  843.         /// Clean up any resources being used.
  844.         /// </summary>
  845.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  846.         protected override void Dispose(bool disposing)
  847.         {
  848.             if (disposing && (components != null))
  849.             {
  850.                 components.Dispose();
  851.             }
  852.             base.Dispose(disposing);
  853.         }
  854.  
  855.         #region Windows Form Designer generated code
  856.  
  857.         /// <summary>
  858.         /// Required method for Designer support - do not modify
  859.         /// the contents of this method with the code editor.
  860.         /// </summary>
  861.         private void InitializeComponent()
  862.         {
  863.             this.pictureBox1 = new System.Windows.Forms.PictureBox();
  864.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  865.             this.SuspendLayout();
  866.             //
  867.             // pictureBox1
  868.             //
  869.             this.pictureBox1.Location = new System.Drawing.Point(0, 0);
  870.             this.pictureBox1.MaximumSize = new System.Drawing.Size(1600, 900);
  871.             this.pictureBox1.Name = "pictureBox1";
  872.             this.pictureBox1.Size = new System.Drawing.Size(381, 334);
  873.             this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
  874.             this.pictureBox1.TabIndex = 0;
  875.             this.pictureBox1.TabStop = false;
  876.             //
  877.             // Form2
  878.             //
  879.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  880.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  881.             this.AutoSize = true;
  882.             this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
  883.             this.ClientSize = new System.Drawing.Size(381, 334);
  884.             this.Controls.Add(this.pictureBox1);
  885.             this.Name = "Form2";
  886.             this.Text = "Bitmap";
  887.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  888.             this.ResumeLayout(false);
  889.             this.PerformLayout();
  890.  
  891.         }
  892.  
  893.         #endregion
  894.  
  895.         private System.Windows.Forms.PictureBox pictureBox1;
  896.     }
  897. }
  898. //////////////////////////////////////////////////////
  899. //Form3.desinger
  900. /////////////////////////////////////////////////////
  901. namespace AsciiArtEmguCv
  902. {
  903.     partial class Form3
  904.     {
  905.         /// <summary>
  906.         /// Required designer variable.
  907.         /// </summary>
  908.         private System.ComponentModel.IContainer components = null;
  909.  
  910.         /// <summary>
  911.         /// Clean up any resources being used.
  912.         /// </summary>
  913.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  914.         protected override void Dispose(bool disposing)
  915.         {
  916.             if (disposing && (components != null))
  917.             {
  918.                 components.Dispose();
  919.             }
  920.             base.Dispose(disposing);
  921.         }
  922.  
  923.         #region Windows Form Designer generated code
  924.  
  925.         /// <summary>
  926.         /// Required method for Designer support - do not modify
  927.         /// the contents of this method with the code editor.
  928.         /// </summary>
  929.         private void InitializeComponent()
  930.         {
  931.             this.label1 = new System.Windows.Forms.Label();
  932.             this.SuspendLayout();
  933.             //
  934.             // label1
  935.             //
  936.             this.label1.AutoSize = true;
  937.             this.label1.Font = new System.Drawing.Font("Lucida Console", 6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(238)));
  938.             this.label1.Location = new System.Drawing.Point(10, 6);
  939.             this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  940.             this.label1.Name = "label1";
  941.             this.label1.Size = new System.Drawing.Size(0, 6);
  942.             this.label1.TabIndex = 0;
  943.             //
  944.             // Form3
  945.             //
  946.             this.AutoScaleDimensions = new System.Drawing.SizeF(5F, 8F);
  947.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  948.             this.AutoSize = true;
  949.             this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
  950.             this.ClientSize = new System.Drawing.Size(236, 161);
  951.             this.Controls.Add(this.label1);
  952.             this.Font = new System.Drawing.Font("Lucida Console", 6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
  953.             this.Margin = new System.Windows.Forms.Padding(2);
  954.             this.Name = "Form3";
  955.             this.Text = "AsciiArt";
  956.             this.ResumeLayout(false);
  957.             this.PerformLayout();
  958.  
  959.         }
  960.  
  961.         #endregion
  962.  
  963.         public System.Windows.Forms.Label label1;
  964.  
  965.     }
  966. }
Advertisement
Add Comment
Please, Sign In to add comment