【发布时间】:2021-08-13 18:38:55
【问题描述】:
我在 c++ winform 中使用 opencv,我想使用线程在两个不同的图片框中显示我的网络摄像头。问题是当一个线程启动时另一个线程没有运行,因此其中一个图片框显示网络摄像头实时但另一个是它的静态图片。我想如果我可以同时运行两个线程启动功能,问题就可以解决,但我不知道该怎么做,或者问题只是别的。有人知道怎么做吗使用线程在这两个不同的图片框上显示实时网络摄像头? 任何帮助将不胜感激。
下面是代码
void start_picture_Box1()
{
s1 = true;
VideoCapture cap(0);
while (s1) {
cap >> _frame1;
mat2picture bimapconvert;
this->pictureBox1->Image = bimapconvert.Mat2Bimap(_frame1);
pictureBox1->Refresh();
if (waitKey(1) == 27) {
break;
}
}
}
void start_picture_Box2()
{
s2 = true;
VideoCapture cap1(0);
while (s2) {
cap1 >> _frame2;
mat2picture bimapconvert;
this->pictureBox2->Image = bimapconvert.Mat2Bimap(_frame2);
pictureBox2->Refresh();
if (waitKey(1) == 27) {
break;
}
}
}
public: void picture_Box1()
{
pictureBox1->Invoke(gcnew System::Action(this, &MyForm::start_picture_Box1));
}
public: void picture_Box2()
{
pictureBox2->Invoke(gcnew System::Action(this, &MyForm::start_picture_Box2));
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
ThreadStart^ ThreadMethod1 = gcnew ThreadStart(this, &MyForm::picture_Box1);
ThreadStart^ ThreadMethod2 = gcnew ThreadStart(this, &MyForm::picture_Box2);
Thread^ MyThread1 = gcnew Thread(ThreadMethod1);
Thread^ MyThread2 = gcnew Thread(ThreadMethod2);
MyThread1->Start();
MyThread2->Start();
}
【问题讨论】:
标签: c++ multithreading winforms opencv