Controlling SharpCap from imageJ

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
User avatar
Hibou
Posts: 111
Joined: Thu Jul 05, 2018 3:25 pm
Location: French Alps
Contact:

Controlling SharpCap from imageJ

#1

Post by Hibou »

Using SharpCap's cmd line with scripts I can open, set parameters and capture images using imageJ as a front-end.
I don't know if this will be useful in practice, though it was an interesting excercise to learn about SharpCap scripting :-)

BUT... I don't know how to close SharpCap after it has captured an image e.g. from the Python script ?

My demo imageJ script to control SharpCap is on https://www.neutronoptics.com/soft/DemoBGfilter.txt with instructions
Unfortunately my script hangs while SharpCap and it's cmd window are open. The usual Windows Taskkill cmd isn't executed
status=exec("taskkill /IM SharpCap*"); //Doesn't execute until the window is closed manually :-)

If I open a new Windows cmd task, I can of course Taskkill whatever I want.
Possibly I can set a timer from imageJ to do that before launching SharpCap, which blocks further imageJ script execution.
Or I may have misunderstood how to launch SharpCap from imageJ without imageJ waiting for SharpCap to finish. Work in progress.
BTW, the video capture example that I modelled my script on uses VirtualDub, which has a command-line switch /x to exit after capture.
I think one can even choose not to display the VirtualDub GUI (Headless mode?) which should speed up execution.

Great fun, though I'm getting too old for this micture of 3 scripting languages :-) Cheers, Alan.
archer1960
Posts: 98
Joined: Sun Feb 23, 2025 9:04 pm

Re: Controlling SharpCap from imageJ

#2

Post by archer1960 »

Can you show us the contents of your SharpCap.bat file?
User avatar
Hibou
Posts: 111
Joined: Thu Jul 05, 2018 3:25 pm
Location: French Alps
Contact:

Re: Controlling SharpCap from imageJ

#3

Post by Hibou »

Hi Archer. It's in the header of the script file I posted:
D:ShapCap.bat="C:\\Program Files\\SharpCap 4.1 (64 bit)\\SharpCap.exe" /runscript D:\SharpCap.py
The SharpCap.py file is:
D:SharpCap.py=SharpCap.SelectedCamera.CaptureSingleFrameTo ("D:\image.fits")
User avatar
Hibou
Posts: 111
Joined: Thu Jul 05, 2018 3:25 pm
Location: French Alps
Contact:

Re: Controlling SharpCap from imageJ

#4

Post by Hibou »

Thanks to Michael Schmid for telling me how to continue my imageJ script without waiting for SharpCap.
https://www.neutronoptics.com/soft/DemoBGfilter.txt
The idea is to launch SharpCap from imageJ by left clicking the camera icon, after right clicking the icon to set parameters.
Then click "Continue" after it has acquired an image, for the imageJ processing to continue automatically.
(Or I could ask imageJ to check periodically for the new image and then close SharpCap and continue automatically).
You can again left-click the imageJ camera icon to acquire a new image, eventually with new parameters.
The full imageJ macro would have a complete interface to set all SharpCap parameters, write the SharpCap .bat and .py files etc
Image
User avatar
Hibou
Posts: 111
Joined: Thu Jul 05, 2018 3:25 pm
Location: French Alps
Contact:

Re: Controlling SharpCap from imageJ

#5

Post by Hibou »

I've made a lot of progress with this project, but don't yet fully understand all the basic scripting commands.
For my own interest, I've made a list of those that work for me, with a few that don't. To be updated as I progress.
https://neutronoptics.com/soft/SharpCap ... mmands.txt

Alan
User avatar
Hibou
Posts: 111
Joined: Thu Jul 05, 2018 3:25 pm
Location: French Alps
Contact:

Re: Controlling SharpCap from imageJ

#6

Post by Hibou »

I have a working version of my ImageJ tool for SharpCap described on https://neutronoptics.com/soft/ImageJforSharpCap.pdf

The idea is to launch SharpCap from imageJ, then to use SharpCap scripting to capture an image and return it to imageJ for automatic background filtering and display. A Windows .bat file, also generated by imageJ, is used to launch SharpCap from imageJ:
START /D "C:\Program Files\SharpCap 4.1 (64 bit)" SharpCap.exe /runscript C:\Users\alanh\desktop\temp\SharpCap.py

The SharpCap interface can even be hidden, and the simple imageJ interface used instead, by using the /MIN switch in the .bat file
START /MIN /D "C:\Program Files\SharpCap 4.1 (64 bit)" SharpCap.exe /runscript C:\Users\alanh\desktop\temp\SharpCap.py

A typical SharpCap script, generated by imageJ, is on https://neutronoptics.com/soft/SharpCap ... mmands.txt.

This approach is useful for users who want to do simple repetitive imaging with a minimalist user interface, and to directly use the powerful image manipulation features of imageJ.

BTW. I know that to find whether the exposure time must be specified in seconds or milliseconds I can use:
SharpCap.SelectedCamera.Controls.Exposure.Units
But I couldn't work out the syntax to use that information to decide to input seconds or milliseconds
User avatar
admin
Site Admin
Posts: 17606
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Controlling SharpCap from imageJ

#7

Post by admin »

Hi,

good to hear that you have pretty much managed to build your new tool :)

For the exposure units, it's probably best to ignore that completely and use the 'ExposureMs' property of the exposure control, which allows you to read/set the exposure in milliseconds, taking into account the units behind the scenes. I think there are also max/min values for the ms exposure too.

cheers,

Robin
Post Reply