1. Add a PictureBox in the toolbox to the interface.
2. Find the definition code for the PictureBox control you just added in the code snippet generated by the Windows window designer XXXXX.Designer.cs:
Modified to:
This allows you to display an image (image, Mat) to the control in the main program through code.
3. Add a TextBox control to display the picture path, and change it to "read-only" in the property.
4. Add a control OpenFileDialog to open the file.
5. Add a button to open the image and add the following code to the calling function:
DialogResult result = openfiledialog1.showdialog (); if (Result = = DialogResult.OK | | result = = Dialogresult.yes) { = openfiledialog1.filename; }
The above code OPENFILEDIALOG1 and textBox1 based on actual modifications.
6. Add code to read in and display the image
Public voidperformshapedetection () {if(TextBox1.Text! = String.Empty)//determine if the address in the text box is empty{StringBuilder Msgbuilder=NewStringBuilder ("Performance:"); //Load the image from file and resize it for displayImage < Bgr,byte> img =NewIMAGE<BGR,byte>(TextBox1.Text). Resize (814,539, Emgu.CV.CvEnum.Inter.Linear,true);//the size of the image is determined by the actual size of the control//Mat srcimg = Cvinvoke.imread (TextBox1.Text);pictureBox1.Image = img;//display image to control This. Text =msgbuilder.tostring ();
7. When the address changes in the Add text box control, the calling code of the image code is displayed.
Private void textbox1_textchanged (object sender, EventArgs e) { performshapedetection (); }
This New System.EventHandler (this. textbox1_textchanged)//In the code snippet generated by the Windows window designer in XXXXX.Designer.cs
Use EMGUCV's Imagebox () to open and display a pair of images in C #