Message Boards Message Boards

Automate camera with RunScheduleTask command h?

I am trying to automate the camera to take an image every 3 seconds for the next 30 seconds and then to append the image to list.

dev = DeviceOpen["Camera"]
DeviceRead[dev]
AppendTo[snapshots, DeviceRead[dev]]
RunScheduledTask[AppendTo[snapshots, DeviceRead[dev]], {3, 10}]

But the code is not responding as wanted.

POSTED BY: Jose Calderon
5 Replies

Jose,

Make sure you are waiting to close the device:

dev = DeviceOpen["Camera"];
snapshots = {};
tsk = RunScheduledTask[AppendTo[snapshots, DeviceRead[dev]], {3, 10}];
RunScheduledTask[DeviceClose[dev], {35}];

or do a Pause[35] before closing the device

Follow this with:

RemoveScheduledTask[ScheduledTasks[]];
Partition[snapshots, 2] // TableForm

This runs for me on a Mac with 11.1.0

POSTED BY: Neil Singer

I am on "11.1.0 for Mac OS X x86 (64-bit) (March 16, 2017)".
I retrieved the images after entering the list. The only issue left is that the camera hang-up on. I added the DeviceClose["Camera"] , but this closes the camera before taken the 10 images.

I know that this is a separate issue, but it is very important for a automation task since I will have multiple cameras doing different task and will need the code to turn off the camera when finished with the images.

POSTED BY: Jose Calderon

Hi Jose,

I suppose the problem is that you haven't initialised the variable "snapshots".

dev = DeviceOpen["Camera"];
snapshots = {};
RunScheduledTask[AppendTo[snapshots, DeviceRead[dev]], {3, 10}];

Then you should remove the scheduled task(s):

RemoveScheduledTask /@ ScheduledTasks[]

Cheers,

Marco

POSTED BY: Marco Thiel

Sorry.. but you code does to produce any result not the list of the 10 images taken 3 seconds apart.

POSTED BY: Jose Calderon

Hi Jose,

what system are you on. For me it does work:

dev = DeviceOpen["Camera"];
snapshots = {};
RunScheduledTask[AppendTo[snapshots, DeviceRead[dev]], {3, 10}];
Partition[snapshots, 2] // TableForm

enter image description here

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract