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

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
User avatar
oopfan
Posts: 1321
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York
Contact:

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

#1

Post 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
User avatar
admin
Site Admin
Posts: 13177
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

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

#2

Post 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
JacquesTalbot2
Posts: 7
Joined: Sun Feb 25, 2024 4:11 pm

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

#3

Post 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
User avatar
admin
Site Admin
Posts: 13177
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

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

#4

Post 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
JacquesTalbot2
Posts: 7
Joined: Sun Feb 25, 2024 4:11 pm

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

#5

Post 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
User avatar
admin
Site Admin
Posts: 13177
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

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

#6

Post 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
Post Reply