开发者

Threading with .NET and OpenCV?

开发者 https://www.devze.com 2022-12-09 15:30 出处:网络
I am having trouble getting a thread to work with OpenCV. The problem is with the ThreadStart() part of my code.

I am having trouble getting a thread to work with OpenCV. The problem is with the ThreadStart() part of my code.

public ref class circles
{
    public:
        static void circleFind(bool isPhoto, const char *  windowName1, const char *  windowName2, const char * photoName)
        {(stuff)}
};

int main(int argc, char* argv[])
{
    const char *windowName1;
    const char *windowName2;
    const char *photoName;

    windowName1 = "Find Circles";
    windowName2 = "Gray";
    photoName = "Colonies 3.jpg";

    bool isPhoto = false;

    //circles(isPhoto, windowName1, windowName2, photoName);
    Thread^ circleThread = gcnew Thread(
        gcnew ThreadStart (&circles::circleFind(isPhoto, windowName1, windowName2, photoName) ));
    circleThread->Start();

    area(isPhoto, photoName);

    return 0;
}

This is not all of the code but the important part. The errors I get are:

1>..\..\..\..\..\..\..\Program Files (x86)\OpenCV\samples\c\circle dection.cpp(130) : error C2102: '&' requires l-value

开发者_运维百科1>..\..\..\..\..\..\..\Program Files (x86)\OpenCV\samples\c\circle dection.cpp(130) : error C3350: 'System::Threading::ThreadStart' : a delegate constructor expects 2 argument(s)


The problem here is that you are trying to use a function for a ThreadStart delegate which has an incompatible signature. ThreadStart is a delegate which has no arguments and returns no value. You are trying to use a method though which takes 4 arguments. This won't work.

You'll need to instead pass in a method which takes no arguments.

To pass parameters in C++, your best bet is to create a new class which has all of the parameters as fields. Then give it a method which has no parameters and returns no value and use that as the ThreadStart target.

ThreadHelper^ h = gcnew ThreadHelper();
h->Param1 = someValue;
ThreadStart^ threadDelegate = gcnew ThreadStart( h, &ThreadHelper::DoMoreWork );

There is a full example of this on the ThreadStart documentation page

  • http://msdn.microsoft.com/en-us/library/system.threading.threadstart.aspx
0

精彩评论

暂无评论...
验证码 换一张
取 消