Discussions on extending SharpCap using the built in Python scripting functionality
Posts: 5233
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Hi Keith,

Yes, you should be able to achieve this – certainly in SharpCap 3.3 where the following code should point the way

Code: Select all

from time import sleep
def framehandler(sender, args):

SharpCap.SelectedCamera.FrameCaptured += framehandler
sleep(10)
SharpCap.SelectedCamera.FrameCaptured -= framehandler

Basically the code in framehandler gets called as every frame is grabbed from the camera and you can add additional information that will get written into the FITS headers. The code at the end just activates that the 10 seconds and then deactivates it again. The Frame.Info object also has an ExposureMs property that you can read to get the exposure of the frame (this ends up in the EXPTIME header).

Robin
Butterbelly
Posts: 34
Joined: Tue Feb 14, 2017 7:53 pm

I will digest and get back with any further questions - there are a couple straight off the bat but
will ponder so as not to pester you as I imagine you are busy.

cheers Keith
Butterbelly
Posts: 34
Joined: Tue Feb 14, 2017 7:53 pm

Hi Robin
I have sorted out the FITS header entries and think it will work well - i intend to create an equivalent to the snapshot button which will take a snapshot with the fits header extras taken care of - I'm hoping to use the FX Frame Stack (3) assuming the snapshot will take that stacked image!?!? can you confirm - if not I can work round

My next issue is the WCS data from a plate solve which needs also to be in the FITS header - I can do this in Astroimagej and other software but it would be very convenient to have a one shop solution and include it in the script used above for fits headers.

I see there is a solution already been discussed

****************************************************************************************************************************************
* Plate solver viewtopic.php?f=14&t=1993

*
Hi,
There is no direct command to carry out plate solving from the scripting API, but it should be relatively simple to invoke the command line plate solving application in the same way that SharpCap does.
If you run the plate solving from SharpCap by pressing the UI button and then go and look in the log you will see the commandline parameters that are used for the plates solving to give you a starting point. The results of the plate solving procedure can be found in the output of the command line solving tool. Once you have those you should be able to synchronise the mount using this scripting

SharpCap.Mounts.SelectedMount.SyncTo(ra,dec)

****************************************************************************************************************************************
however I see no way to get this WCS data provided by the plate solving into the fits header or am I missing something and is this included in the statement "The results of the plate solving procedure can be found in the output of the command line solving tool."
Any thoughts or suggestions on this

many thanks and hope I'm making sense
Keith
Posts: 5233
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Hi Keith,

the brightening of the image made by the frame stack effects in the FX drop-down only apply to the image has viewed on-screen – they don't change the saved image.

I think you can work around the plate solving issue – you change your setup so that after plate solving SharpCap only synchronises the mount (this is in the plate solving settings page), then read the RA and Dec coordinates back from the mount after the plate solving operation has set them to the correct value.

Cheers, Robin
JesusRL
Posts: 24
Joined: Wed Aug 05, 2020 4:36 pm

Tue Jul 11, 2017 6:13 pm
Hmm, there are useful python tools for this (like AstroPy and OpenCV), but neither will work in IronPython

Fortunately though it's all built in to SharpCap and with a little (undocumented until now) scripting you can get access to it

Code: Select all

import clr
from SharpCap.ImageProcessing import OpenCVStarDetector
ocvsd = OpenCVStarDetector(1,16,100,0.0)
from System.Drawing import Bitmap
bm = Bitmap(640,480)
ocvsd.Detect(bm)

The parameters for creating the OpenCVStarDetector are (minSize, maxSize, maxStarCount, gaussianBlurSigma). The .Detect() method takes a bitmap you want to detect stars in and returns an array of StarInfo (which have Position and Brightness among other useful properties).

cheers,

Robin
Hi Robin, first of all excuse me if I say something incoherent in my request.

Apart of StarDetector, can I access all the other functions of OpenCV within SharpCap.ImageProcesing?

I would like to be able to use: cv2.cvtColor, cv2.GaussianBlur, cv2.Canny, cv2.findContours and cv2.drawContours

T&R
Posts: 5233
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Hi,

sorry, those aren't accessible to you. I only use a small fraction of openCV, and I've set it up so that the bits of code that I don't use aren't even included in the SharpCap binaries. On top of that there's no way to call through to the extra functions (I have to wire up each of the ones that I use manually).

You could try using one of the .Net wrappers around openCV (like https://github.com/shimat/opencvsharp). These should be accessible from IronPython I think.

Cheers, Robin
JesusRL
Posts: 24
Joined: Wed Aug 05, 2020 4:36 pm

Thank you Robin,

Let me explain you what my idea is in any case to know what you think about it. Maybe it makes no sense.

It's all about colimation: my idea is:

* Unfocus your telescope in a very bright star and you will get a single big circle.
* If I capture the image I could find the circles with OpenCV. It would be dinamical new image (possibly moved) new circles. When you colimate ytou move the star.
* Programatically select the bigest one, paint it and paint another one, smaller, as a percentage of the big one.

This small circle (5%) Should be the airy point in a refractor
A bigger small circle (about 60%) should be the doughnut hole in a SC telescope
...

Does it make sense?
Posts: 5233
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Hi,

it sounds as though it might work – I would be tempted to take a few images like the ones you describe and save them. Take some with the collimation exactly right and some with the collimation deliberately wrong and then apply the process by hand (using a paint program or similar) to see if you really can work out from the image where the collimation is correct or not. Only at that point is it worth investing in code to start doing that automatically.

Open CV can certainly detect circles for you - for instance an edge detection transform followed by a HoughCircleTransform should do the job.

Cheers, Robin
JesusRL
Posts: 24
Joined: Wed Aug 05, 2020 4:36 pm

Hi,

First of all please excuse any mistakes I may do in my poor english; I hope they do not confuse the concepts.

Basically my idea would be to analise it in 2 different ways, checking (empirically) which works best.

1) The points founf by cv2.findContours of the external shape adjusted via least squares to a circle function: less residual (closest to a real circle) best colimation

2) Most interested people will be reflector users with doughnut shaped unfocused stars: calculating (similarly as before) the external and internal circles of the doughnut and comparing the central point of both functions: closest points best colimation

If this works you can go much further:

If I am not wrong proper colimation should be 1 screw out (amount x) a 2 screws in (sum of both equals amount x, but could/shoul be both different). At least this is how I have been doing it the last 25 years (telescopes still safe and working)

* Imagen taken and analised
* User should mark the 3 points in the circle corresponding to the 3 screws via "place your hand and see the shadow" naming them as A, B and C. The user will not mark them perfectlly but adjusting the "best" equilater triangle to the 3 points should be more than enough.
* User moves screw A 1/4 of a turn out and, after tha,t screws B and C 1/8 in.

At this point a mathematical model can tell him/her which, and how much, of the screws should go out and how much in should move each of the other 2.

Sounds sensate?

T&R