Page 1 of 1

How to detect star's center with sub-pixel accuracy

Posted: Thu Apr 22, 2021 1:49 am
by oopfan
Hi Robin,

For years I've been using the following code to detect a star's center:

Code: Select all

from SharpCap.ImageProcessing import OpenCVStarDetector
from System.Drawing import Bitmap

gaussianBlur = 0.8
path = "C:\Users\Brian\Desktop\pec-learn\capture.png"

ocvsd = OpenCVStarDetector(2, 20, 10, gaussian_blur)
SharpCap.SelectedCamera.CaptureSingleFrameTo(path)
bm = Bitmap(path)
stars = ocvsd.Detect(bm)
star = stars[0]
xcenter = star.BoundingBox.X + 0.5 * star.BoundingBox.Width
ycenter = star.BoundingBox.Y + 0.5 * star.BoundingBox.Height
Now that I am a user of PHD2, I see the utility of calculating the position of a star with sub-pixel accuracy. However, star.BoundingBox refers to whole pixels, not fractions.

Is there another API that supports this?

Thanks,
Brian

Re: How to detect star's center with sub-pixel accuracy

Posted: Thu Apr 22, 2021 1:52 pm
by admin
Hi Brian,

yes, you can use star.Position (actually star.Position.X and star.Position.Y) to get the sub-pixel position of the star's center of brightness.

How accurate it is at the sub-pixel level is arguable - although the maths is easy to calculate the center of brightness, you need to remove the background brightness from the image data first, and working out the correct background level is an estimate at best. It will definitely be better than the center of the bounding box though. Probably good to 0.1px in most cases.

cheers,

Robin

Re: How to detect star's center with sub-pixel accuracy

Posted: Tue Feb 27, 2024 11:41 pm
by JacquesTalbot2
Hi
I am new to python and ironpython and tried to do the import
>>> from SharpCap.ImageProcessing import OpenCVStarDetector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Cannot import name OpenCVStarDetector
>>>
I don't know what to do. Can you help me?
Thanks

Re: How to detect star's center with sub-pixel accuracy

Posted: Wed Feb 28, 2024 10:41 am
by admin
Hi,

you probably just need to do this line first before the import

Code: Select all

clr.AddReference("SharpCap.ImageProcessing")
That line tells the python environment that you will be using stuff in the SharpCap.ImageProcessing dll.

cheers,

Robin

Re: How to detect star's center with sub-pixel accuracy

Posted: Wed Feb 28, 2024 1:58 pm
by JacquesTalbot2
Ok thanks it work. (I finally figured it out myself)

Did you documented the SharpCap.ImageProcessing module. Is there other function than OpenCVStarDetector ?

I am trying to use opencv but I don't know how. You mentionned a wrapper but don't how to use/install it.

I am new to Python and I did a script to do the capture for the eclipse and I would like to add some scripting to recenter the sun during the partial phase because it will be hard to get a good polar aligment during the day.
Thanks

Re: How to detect star's center with sub-pixel accuracy

Posted: Wed Feb 28, 2024 10:24 pm
by admin
Hi,

there's no real documentation, since that's really SharpCap internals that I have decided to let people access via scripting. It would take ages to document...

There are a number of .NET wrappers for OpenCV (for instance OpenCVSharp - https://github.com/shimat/opencvsharp), but I have no idea if they would work nicely inside SharpCap scripting, and converting from the image data structures that SharpCap uses to the ones that those libraries require is not going to be simple. Programming that sort of thing inside SharpCap scripting tends to be harder than doing it in C# from visual studio, so it may be best to just save out the image to file and have a separate program do the processing if you want to do anything serious.

cheers,

Robin