C++ openCV3.0 windows form


#1

can you help me with some suff?
I’m creating a visualc++ windows form app using CLR Form and opencv that takkes input as vedio from web cam and shows in the picture box frame by frame but I’m unable to stop the video
once the loop starts I cant control it I tried threading but CLR does not support threading
what should I do?

a part of my code

//code
{
private: System::Void button2_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if (button2->Text == “Stop”)
{
button2->Text = “Start”;

	}
	else if (button2->Text == "Start")
	{
		button2->Text = "Stop";

	}
	
	thread t1(vid);
	t1.detach();
	
	
}

		
		 private:  void vid()
		 {
			 VideoCapture capture(0);
			 Mat frame;

			 while (button2->Text == "Stop")
			 {
				 capture.read(frame);
				 System::Drawing::Graphics^ graphics2 = pictureBox1->CreateGraphics();
				 System::IntPtr ptr2(frame.ptr());
				 System::Drawing::Bitmap^ b2 = gcnew System::Drawing::Bitmap(frame.cols,
					 frame.rows, frame.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr2);
				 System::Drawing::RectangleF rect2(0, 0, pictureBox1->Width, pictureBox1->Height);
				 graphics2->DrawImage(b2, rect2);

			 }
		 }

};

My email is muhammadbinali96@gmail.com