Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
namespace mgfmf {
Mat src; // Need to creat a Mat type for the src image.
/// <summary>
/// </summary>
public:
MainForm(void)
{
InitializeComponent();
//
//
protected:
/// <summary>
/// </summary>
~MainForm()
if (components)
delete components;
protected:
private:
/// <summary>
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// </summary>
void InitializeComponent(void)
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbSource))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbGray))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbGaussian))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbBinary))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbAdaptive))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbR))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbB))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbG))->BeginInit();
this->SuspendLayout();
//
// btnBrowser
//
this->btnBrowser->Name = L"btnBrowser";
this->btnBrowser->TabIndex = 0;
this->btnBrowser->Text = L"Browse";
this->btnBrowser->UseVisualStyleBackColor = true;
//
// btnProcess
//
this->btnProcess->Name = L"btnProcess";
this->btnProcess->TabIndex = 1;
this->btnProcess->Text = L"Process";
this->btnProcess->UseVisualStyleBackColor = true;
//
// ptbSource
//
this->ptbSource->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbSource->Name = L"ptbSource";
this->ptbSource->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbSource->TabIndex = 2;
this->ptbSource->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Name = L"label1";
this->label1->TabIndex = 3;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Name = L"label2";
this->label2->TabIndex = 3;
this->label2->Text = L"Size";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Name = L"label3";
this->label3->TabIndex = 3;
this->label3->Text = L"Size";
//
// ptbGray
//
this->ptbGray->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbGray->Name = L"ptbGray";
this->ptbGray->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbGray->TabIndex = 2;
this->ptbGray->TabStop = false;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Name = L"label4";
this->label4->TabIndex = 3;
//
// ptbGaussian
//
this->ptbGaussian->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbGaussian->Name = L"ptbGaussian";
this->ptbGaussian->Size = System::Drawing::Size(270, 174);
this->ptbGaussian->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbGaussian->TabIndex = 2;
this->ptbGaussian->TabStop = false;
//
// label7
//
this->label7->AutoSize = true;
this->label7->Name = L"label7";
this->label7->TabIndex = 3;
//
// ptbBinary
//
this->ptbBinary->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbBinary->Name = L"ptbBinary";
this->ptbBinary->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbBinary->TabIndex = 2;
this->ptbBinary->TabStop = false;
//
// ptbAdaptive
//
this->ptbAdaptive->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbAdaptive->Name = L"ptbAdaptive";
this->ptbAdaptive->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbAdaptive->TabIndex = 2;
this->ptbAdaptive->TabStop = false;
//
// label8
//
this->label8->AutoSize = true;
this->label8->Name = L"label8";
this->label8->TabIndex = 3;
//
// label9
//
this->label9->AutoSize = true;
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(113, 13);
this->label9->TabIndex = 3;
//
// ptbR
//
this->ptbR->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbR->Name = L"ptbR";
this->ptbR->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbR->TabIndex = 2;
this->ptbR->TabStop = false;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Name = L"label5";
this->label5->TabIndex = 3;
//
// ptbB
//
this->ptbB->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbB->Name = L"ptbB";
this->ptbB->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->ptbB->TabIndex = 2;
this->ptbB->TabStop = false;
//
// label6
//
this->label6->AutoSize = true;
this->label6->Name = L"label6";
this->label6->TabIndex = 3;
//
// ptbG
//
this->ptbG->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;
this->ptbG->Name = L"ptbG";
this->ptbG->TabIndex = 2;
this->ptbG->TabStop = false;
//
// label10
//
this->label10->AutoSize = true;
this->label10->Name = L"label10";
this->label10->TabIndex = 3;
//
// MainForm
//
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::Control;
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label9);
this->Controls->Add(this->label7);
this->Controls->Add(this->label10);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label8);
this->Controls->Add(this->label4);
this->Controls->Add(this->label1);
this->Controls->Add(this->ptbAdaptive);
this->Controls->Add(this->ptbG);
this->Controls->Add(this->ptbB);
this->Controls->Add(this->ptbR);
this->Controls->Add(this->ptbBinary);
this->Controls->Add(this->ptbGaussian);
this->Controls->Add(this->ptbGray);
this->Controls->Add(this->ptbSource);
this->Controls->Add(this->btnProcess);
this->Controls->Add(this->btnBrowser);
this->Name = L"MainForm";
this->Text = L"MainForm";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbSource))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbGray))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbGaussian))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbBinary))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbAdaptive))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbR))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbB))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this-
>ptbG))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
#pragma endregion
if (dgOpen->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
return;
ptbSource->Image = bmpSrc;
ptbSource->Refresh();
return str2;
Mat gray;
Mat red;
Mat blue;
Mat green;
Mat rorate;
Mat binary;
Mat adaptivebinary;
Mat resizeimg;
gaussianimg = GaussianFiltering(src);
medianimg - MedianFiltering(src);
0, 1, 1 };
double m2[3][3] = { 1, 1, 1,
1,-7,1,
1, 1, 1 };
-1,8,-1,
-1, -1, -1 };
//
Img1 = Filter(src,m);
resizeimg = ToResize(src);
gaussianimg = GaussianFiltering(resizeimg);
binary = ToBinary(gray);
DrawCVImage(ptbBinary, binary);
adaptivebinary = ToAdaptiveBinary(gray);
DrawCVImage(ptbAdaptive, adaptivebinary);
//Now goto show rorate image
DrawCVImage(ptbRotate, rorate);
red = ToHistogram(resizeimg)[0];
green = ToHistogram(resizeimg)[1];
blue = ToHistogram(resizeimg)[2];
DrawCVImage(ptbR, red);
DrawCVImage(ptbG, green);
DrawCVImage(ptbB, blue);
Mat dst;
cvtColor(src, dst, CV_RGB2GRAY); // You can check all detail method by move
over mouse to the cvtColor method. Same with other methods.
Mat dst;
return dst;
Mat dst;
return dst;
Mat dst;
resize(src, dst, cv::Size(320, 240), 0, 0, 1); // we need to define new size onn
cv:Sizze(width, height)
return dst;
private: Mat ToRotate(Mat src, double angle, double scale) { // Rotate image with center
poit define: Point2f center(src.cols / 2, src.rows / 2);
Mat dst;
return dst;
convertScaleAbs(dst, dst2);
return dst2;
convertScaleAbs(dst, dst2);
return dst2;
}
private: vector<Mat> ToHistogram(Mat src) { // This method will draw histogram of 3
colors R,G,B
vector<Mat> result;
vector<Mat> img_rgb;
result.push_back(disp_r);
result.push_back(disp_g);
result.push_back(disp_b);
return result;
// For the Windows Form picture box, to show Mat image we need
bellow method (This method you can see on OpenCV website)
System::IntPtr ptr(colorImage.ptr());
System::Drawing::Bitmap^ b;
switch (colorImage.type())
System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
break;
System::Drawing::Imaging::PixelFormat::Format8bppIndexed,
ptr);
break;
default:
// error message
break;
graphics->DrawImage(b, rect);
};
}