Jump to content

Call to OpenCV dll returns different results when wrapper DLL set to run in UI thread or any thread


Recommended Posts

Hello,

I originally posted this on the NI forums, here, but it hasn't had a response so I'm posting it here too.

I'm writing a wrapper DLL to handle calls to the OpenCV 2.1 image processing library. When using the OpenCV function 'cv::matchTemplate'. I get different results depending on if the wrapper DLL is set to run in the UI thread or any thread.

When set to the UI thread I get incorrect results (see attachement resultUI.png).

When set to Run in any thread I get correct results (see attachment resultAny.png).

I've created a minimal DLL which shows this behaviour, see below.

Why do I get different results?

Is there a way to get the 'Run in UI thread' version to return the correct results (I'm not sure that my wrapper DLL or indeed the OpenCV dlls are thread safe).

Thanks in advance,

Dave

#include <cv.h>#include <highgui.h>extern "C" __declspec(dllexport) int matchTest(int a);BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved){	switch (ul_reason_for_call)	{	case DLL_PROCESS_ATTACH:	case DLL_THREAD_ATTACH:	case DLL_THREAD_DETACH:	case DLL_PROCESS_DETACH:		break;	}	return TRUE;}extern "C" __declspec(dllexport) int matchTest(int a){	cv::Mat srcImg, templateImg, result32Img, result8Img;	cv::Size resultSize;	srcImg= cv::imread("source.bmp", 0);	templateImg = cv::imread("template.bmp", 0);	resultSize.width = srcImg.size().width - templateImg.size().width + 1;        resultSize.height = srcImg.size().height - templateImg.size().height + 1;		result32Img = cv::Mat(resultSize, CV_32FC1);	result8Img = cv::Mat(resultSize, CV_8UC1);	cv::matchTemplate(srcImg, templateImg, result32Img, CV_TM_CCOEFF_NORMED);	//returns different results	        //convert to 8 bit and write to file	result32Img.convertTo(result8Img, CV_8UC1, 256);	cv::imwrite("result.png", result8Img);	return a;}  

source.zip

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.