Helpful IronPython libraries
Helpful IronPython libraries
Hi Robin,
I am in the process of upgrading a 50-year old GEM with a stepper motor on the RA axis. Previously it used a synchronous motor at a fixed rate determined by the power line frequency. Even with precise polar alignment the tracking suffers from periodic error in the worm gear. In my stepper motor solution I've written Python code to correct for periodic error but it requires me to enter "learning mode". For eight minutes my life is hell as I tell the drive to speed-up and slow-down as I endeavor to keep a star centered in crosshairs. It is exhausting work. It sure would be nice if I could automate this.
I've browsed the docs and see that I can command SC to capture a frame. That is great. I also see that I can open that file and write annotations. Super! So what I would like to do through script is to open the file and read a 50x50 pixel square at the center of the image, and then find a disc that qualifies as a star. I want to determine the (x,y) coordinates of the center of the disc, and record it to a file. Then, one second later I want to capture a new frame, and use the coordinates of the disc's center from the previous frame to look for a disc with a 50x50 pixel square around that center point. (I hope I am making sense.) Clearly, I could do this entirely offline using most any programming language. Since SC has a Python automation interface, it seems like something I might want to try first.
So my question is: Do you know of any third party Python libraries that can do a lot of the work of finding the star's disc? I could write it myself but if there is already something out there then I would like to use it.
Thank you!
I am in the process of upgrading a 50-year old GEM with a stepper motor on the RA axis. Previously it used a synchronous motor at a fixed rate determined by the power line frequency. Even with precise polar alignment the tracking suffers from periodic error in the worm gear. In my stepper motor solution I've written Python code to correct for periodic error but it requires me to enter "learning mode". For eight minutes my life is hell as I tell the drive to speed-up and slow-down as I endeavor to keep a star centered in crosshairs. It is exhausting work. It sure would be nice if I could automate this.
I've browsed the docs and see that I can command SC to capture a frame. That is great. I also see that I can open that file and write annotations. Super! So what I would like to do through script is to open the file and read a 50x50 pixel square at the center of the image, and then find a disc that qualifies as a star. I want to determine the (x,y) coordinates of the center of the disc, and record it to a file. Then, one second later I want to capture a new frame, and use the coordinates of the disc's center from the previous frame to look for a disc with a 50x50 pixel square around that center point. (I hope I am making sense.) Clearly, I could do this entirely offline using most any programming language. Since SC has a Python automation interface, it seems like something I might want to try first.
So my question is: Do you know of any third party Python libraries that can do a lot of the work of finding the star's disc? I could write it myself but if there is already something out there then I would like to use it.
Thank you!
- admin
- Site Admin
- Posts: 13520
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Helpful IronPython libraries
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
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
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
clr.AddReference("SharpCap.ImageProcessing")
from SharpCap.ImageProcessing import OpenCVStarDetector
ocvsd = OpenCVStarDetector(1,16,100,0.0)
clr.AddReference("System.Drawing")
from System.Drawing import Bitmap
bm = Bitmap(640,480)
ocvsd.Detect(bm)
cheers,
Robin
Re: Helpful IronPython libraries
Wow that's awesome, Robin! (That's what I was hoping you were going to say but I did not want to be too forward by asking.)
Re: Helpful IronPython libraries
Hi Robin,
Should I be concerned with what image file format I store the images in? I've got an ASI120MC. Will OpenCVStarDetector work equally well when processing RGB24, RAW8, and MONO8? Although color is unimportant to me for what I aim to do, it would be nice to capture in color for some unforeseen reason down the road.
Thanks,
Brian
Should I be concerned with what image file format I store the images in? I've got an ASI120MC. Will OpenCVStarDetector work equally well when processing RGB24, RAW8, and MONO8? Although color is unimportant to me for what I aim to do, it would be nice to capture in color for some unforeseen reason down the road.
Thanks,
Brian
- admin
- Site Admin
- Posts: 13520
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Helpful IronPython libraries
If you save in RAW formats then the star detection probably won't work as well as it should because of the grid pattern superimposed on the image by the Bayer matrix. One possible workaround for this would be to reduce the image size by a factor of 2 in each direction after loading and before star detecting (average out the grid pattern).
Colour or mono doesn't matter - the image is turned to mono anyway before the star detection algorithm is used.
cheers,
Robin
Colour or mono doesn't matter - the image is turned to mono anyway before the star detection algorithm is used.
cheers,
Robin
Re: Helpful IronPython libraries
Hi Robin,
I've developed a number of useful scripts based on calls to OpenCVStarDetector. The problem I am having is that it is not very sensitive at all. I can send you snapshots but I can summarize by saying that I clearly see 7 stars but it struggles to find 3 maybe 4 if it is lucky. Here is how I've been calling it:
ocvsd = OpenCVStarDetector(1,20,1000,0.0)
SharpCap.SelectedCamera.CaptureSingleFrameTo(path)
bm = Bitmap(path)
stars = ocvsd.Detect(bm)
Tonight, I played around with the last argument: gaussianBlurSigma, using numbers between 0.0 and 0.9 but it only seemed to make things marginally better.
Is there a way to make the detector more sensitive? I don't mind getting false positives -- my algorithm is fairly robust.
Perhaps there are functions that I can call on the bitmap to digitally boost the gain? I am already using gain 100 on my camera with a 2 second exposure. These are exactly the settings I use for polar alignment and it finds many more stars. For my application I was hoping to operate at 0.5 second exposure, so I am a long way away from that goal.
Thank you,
Brian
I've developed a number of useful scripts based on calls to OpenCVStarDetector. The problem I am having is that it is not very sensitive at all. I can send you snapshots but I can summarize by saying that I clearly see 7 stars but it struggles to find 3 maybe 4 if it is lucky. Here is how I've been calling it:
ocvsd = OpenCVStarDetector(1,20,1000,0.0)
SharpCap.SelectedCamera.CaptureSingleFrameTo(path)
bm = Bitmap(path)
stars = ocvsd.Detect(bm)
Tonight, I played around with the last argument: gaussianBlurSigma, using numbers between 0.0 and 0.9 but it only seemed to make things marginally better.
Is there a way to make the detector more sensitive? I don't mind getting false positives -- my algorithm is fairly robust.
Perhaps there are functions that I can call on the bitmap to digitally boost the gain? I am already using gain 100 on my camera with a 2 second exposure. These are exactly the settings I use for polar alignment and it finds many more stars. For my application I was hoping to operate at 0.5 second exposure, so I am a long way away from that goal.
Thank you,
Brian
Re: Helpful IronPython libraries
Hi Robin,
I think that you mentioned that the documentation of the "SharpCap.ImageProcessing" assembly is a work-in-progress. Do you know if there is anything in there that would allow me to stretch an image? Hopefully that will give OpenCVStarDetector more meat to sink its teeth into.
Thanks
I think that you mentioned that the documentation of the "SharpCap.ImageProcessing" assembly is a work-in-progress. Do you know if there is anything in there that would allow me to stretch an image? Hopefully that will give OpenCVStarDetector more meat to sink its teeth into.
Thanks
- admin
- Site Admin
- Posts: 13520
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Helpful IronPython libraries
Hi,
I'm afraid I'm away at the moment and don't have access to the source code to check on this for you. Will have a look when I get back at the end of the week.
Cheers.
Robin
I'm afraid I'm away at the moment and don't have access to the source code to check on this for you. Will have a look when I get back at the end of the week.
Cheers.
Robin
Re: Helpful IronPython libraries
No worries, Robin. I got some very helpful advice from Dave. With some luck the skies will be clear tonight. I am going to play around with the camera's brightness and gamma settings to try to get OpenCVStarDetector to see more stars.
-
- Posts: 38
- Joined: Tue Feb 14, 2017 7:53 pm
Re: Helpful IronPython libraries
Hi Robin have been looking at a problem with fits headers I have.admin wrote: ↑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
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).Code: Select all
import clr clr.AddReference("SharpCap.ImageProcessing") from SharpCap.ImageProcessing import OpenCVStarDetector ocvsd = OpenCVStarDetector(1,16,100,0.0) clr.AddReference("System.Drawing") from System.Drawing import Bitmap bm = Bitmap(640,480) ocvsd.Detect(bm)
cheers,
Robin
I have researched the sharpcap forums and cannot find an answer - the closest was the post above.
My Problem
I am a member of the AAVSO so have an interest in photometry which I'm on a learning curve with at the moment -
The software used by AAVSO to produce light curves requires some additional FITS Header keywords to properly load in the fits image
These are
EXPOSURE
FILTER - "TB"
CALSTAT - "BF"
TELSCOP - "CelEvo"
At the moment I use AstroImageJ to batch process every image to add these to the fits file - also to plate solve and add WCS data to the FITS header.
Astropy has functions to edit ammend and save fits headers and files and Im looking at that.
based on the post quoted are there any ways to access similar functions in sharpcap - this would enable me to produce VPHOT(AAVSO software for light curve generation) ready fits files directly from Sharpcap script.
WCS data could still be done from Astroimagej BUT is there anyway to do this from sharpcap scripts
Apologise for long list of requests but this hobby is complicated
cheers Keith Butterworth