Mat::clone() issues

asked 2016-09-28 04:52:31 -0500

Phteven gravatar image

Hello,

I am using a method for thinning an image. The method is beeing executed by a single thread.

void applyThreadedThinning(Mat* input) { Mat output = input->clone(); ..... }

I use MSVC 2015 (32bit) and the plugin Image Watch, which lets me see the content of the image while debugging.

After I set a breakpoint do the line with the clone()... i noticed, that the input image looks fine, but the cloned one is a plain image, filled with values 217 (8bit greyscale).

After jumping to the next line in the debugger, both images are "invalid".

Strange thing is, if I execute the method directly in the main method (not using a thread), it works fine. The threaded(std::thread t1(...)) version aborts during runtime.

Why is the clone method not working as intended? Is it something with scopes?

Thanks

edit retag flag offensive close merge delete

Comments

  • do not use pointers to cv::Mat.
  • show us your real code (or at least a minimal testcase, that reproduces your issue.) all your blurb above is essentially useless.
  • why do you think, you need threading at all ?
  • do you know, what a mutex is, and why you need it ?
berak gravatar imageberak ( 2016-09-28 05:19:40 -0500 )edit

can you explain a bit further why not to use pointers to cv::Mat?

the real code is kinda big, I will try to extract a minimum example and post it below.

i dont need it at all. I try to gain speed and tried different things. On this "trying" I came across this issue.

yes

Phteven gravatar imagePhteven ( 2016-09-28 06:22:16 -0500 )edit
1

because it's a refcounted smartpointer already. passing the address of it will defeat its purpose.

berak gravatar imageberak ( 2016-09-28 06:42:08 -0500 )edit

Replacing all cv::Mat* to cv::Mat and minor adaptions for the changed type did the trick. Thank you

Phteven gravatar imagePhteven ( 2016-09-28 07:23:08 -0500 )edit