I have an application where I need to pass a cv::Mat into a Windows Form to be displayed on a PictureBox control. The cv::Mat is being passed into the Form from a separate thread from the one that the Form resides in. I have used the thread-safe method below for passing information into Forms from other threads quite often, but it has always been reference types that I have passed. Here's what I'm trying to accomplish, but the cv::Mat can't be converted to a System::Object:
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.
ReceiveFrameDelegate^ d = gcnew ReceiveFrameDelegate(this, &Reader::receiveFrame);
array<System::Object^>^myArray = gcnew array<System::Object^>(3);
myArray = frame; // Compile fails: No type conversion exists for cv::Mat
myArray = field;
myArray = bIsRecording;
// Do what needs to be done
Is there a way to cast a cv::Mat to a System::Object? Can I cast a cv::Mat to a reference type and then to a System::Object? Since cv::Mat is not inherited from System::Object, I'm not sure how to do this. Is there another thread-safe way to pass a cv::Mat from another thread? Thanks for any help!