我有一个应用程序,我需要将cv :: Mat传递到Windows窗体中以显示在PictureBox控件上。 cv :: Mat从一个单独的线程传递到Form中,而不是Form所在的那个。我使用下面的线程安全方法将信息经常传递给其他线程的Forms,但它一直是引用我通过的类型。这是我想要完成的,但是cv :: Mat无法转换为System :: Object:
class Reader
{
delegate void ReceiveFrameDelegate(cv::Mat frame, Field field, bool bIsRecording);
void receiveFrame(cv::Mat frame, Field field, bool bIsRecording)
{
//InvokeRequired compares the thread ID of the
//calling thread to the thread ID of the creating thread.
//If these threads are different, it returns true.
if (this->InvokeRequired)
{
ReceiveFrameDelegate^ d = gcnew ReceiveFrameDelegate(this, &Reader::receiveFrame);
array<System::Object^>^myArray = gcnew array<System::Object^>(3);
myArray[0] = frame; // Compile fails: No type conversion exists for cv::Mat
myArray[1] = field;
myArray[2] = bIsRecording;
this->Invoke(d, myArray);
}
else
{
// Do what needs to be done
....
}
}
有没有办法将cv :: Mat强制转换为System :: Object?我可以将cv :: Mat转换为引用类型,然后转换为System :: Object吗?由于cv :: Mat不是从System :: Object继承的,所以我不知道如何做到这一点。是否有另一种线程安全的方法从另一个线程传递cv :: Mat?谢谢你的帮助!