0

I am writing a plug-in where the user must place an ROI on the image (live image-feed from a camera on the microscope), and once this ROI is placed, the program must perform an action on this ROI.

I have tried the

new WaitForUserDialog("Please place the Rectangle-ROI to begin, then click OK.").show();

But this requires the user to actually press the OK button after placing the ROI. I want to bypass the pressing of the OK button.

How can I write my code, so that the program asks the user to place the ROI (on the image (live images from a camera acquisition) and as soon as the the ROI is placed, triggers the program to continue (without pressing an OK button).

My objective is to help the user avoid loss of time between placing ROI and pressing the OK button. This is because the image will be live and changing, and by the time the user presses OK, perhaps the ROI is no longer at the place of interest.

Thanks in advance! would be great if someone could point me in the right direction.

Sarala

Sara
  • 3
  • 3
  • Scan the image in regular intervals (e.g. every second). If the scanned image contains ROI, save it and raise an event that will start the action you currently do on OK button press. – Tadija Bagarić Mar 29 '18 at 07:18
  • Hi Tadija, Thanks for your reply. How can I set to scan the image at regular intervals? Then I assume I must use a Boolean to set to true if ROI is found. And then if the value is true proceed with the rest of the program and do action on ROI? – Sara Apr 04 '18 at 09:04

1 Answers1

0

You may want to consider a Semaphore for this problem.

You can initialize a semaphore which is shared between your main code and your event handler:

Semaphore sem = new Semaphore(0);

Your logic code will wait on the semaphore until a permit is available:

sem.acquire();

And your event handler (where you detect the ROI having been drawn) will release the semaphore, unblocking the other thread:

sem.release();

NOTE: I am assuming that your logic thread (the one on which you call acquire) is not the main thread. If it is, then you're going to block indefinitely.

Joe C
  • 15,324
  • 8
  • 38
  • 50