private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int threshold_value = 0;
int threshold_type = 3;
int const max_value = 255;
int const max_type = 4;
int const max_BINARY_value = 255;
Mat srcimg;
Mat grayimg;
srcimg = imread("D:\\1.png", IMREAD_COLOR);
if (srcimg.empty())
{
MessageBox::Show("No Image");
Application::Exit();
}
DrawCVImage(pictureBox1, srcimg);
cvtColor(srcimg, grayimg, COLOR_BGR2GRAY);
Mat dst;
threshold(grayimg, dst, trackBar1->Value, max_BINARY_value, trackBar2->Value);
DrawCVImage(pictureBox2, dst);
}
void DrawCVImage(Control^ control, Mat& image)
{
Graphics^ graphic = control->CreateGraphics();
IntPtr ptr(image.ptr());
Bitmap^ b = gcnew Bitmap(image.cols, image.rows, image.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
RectangleF rec(0, 0, control->Width, control->Height);
graphic->DrawImage(b, rec);
}
private: System::Void trackBar1_Scroll(System::Object^ sender, System::EventArgs^ e)
{
button1->PerformClick();
label1->Text = trackBar1->Value.ToString();
}
private: System::Void trackBar2_Scroll(System::Object^ sender, System::EventArgs^ e)
{
button1->PerformClick();
label3->Text = trackBar2->Value.ToString();
}
};
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น