I am trying to write a nice little program to help me and colleagues draw outlines of objects in images
I came up with the following code which allowed me to click and hold down the primary mouse button to draw a shape:
imgs = {ConstantImage[0, {500, 500}], ConstantImage[0, {500, 500}]};
DynamicModule[{outlines = {{{}}, {{}}}, i = {1, 1}, n = 1, tmp,
labelimgs = imgs},
EventHandler[
Dynamic@
Show[labelimgs[[n]],
Graphics[{Magenta, Opacity[.5], Polygon /@ outlines[[n]], White,
Line@outlines[[n, i[[n]]]]}], ImageSize -> Large],
{
{"MouseDragged",
1} :> (AppendTo[outlines[[n, i[[n]]]],
MousePosition["Graphics"]];),
{"MouseUp", 1} :>
If[Length@outlines[[n, i[[n]]]] > 1,
AppendTo[outlines[[n, i[[n]]]], outlines[[n, i[[n]], 1]]];
AppendTo[outlines[[n]], {}];
i[[n]]++],
"RightArrowKeyDown" :> If[n < Length@labelimgs, (n++;)],
"LeftArrowKeyDown" :> If[n > 1, (n--;)]
}]]
This works good enough in a notebook. Next I tried to evaluate the cell in a public cloud notebook (colleagues do not have Mathematica installed) which was unusable because every Dynamic step seems to be sent to the cloud and back.
Am I doing something wrong or is the cloud not intended to be used like this?
Locators
where you can Ctrl-click to make a new locator and you define the shape as the shortest tour through them. This won’t allow for perfect outlines, but can be made to be as good an approximation as you have the patience for. $\endgroup$