Home Converting cv::mat to System::Object
Reply: 0

Converting cv::mat to System::Object

user1745 Published in July 16, 2018, 6:47 am

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:

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);
            // 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!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309757 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO