Page 1 of 2

OpenCVStarDetector disappeared ...

Posted: Sat Apr 18, 2026 3:17 pm
by Jean-Francois
Hello Robin,

is the OpenCVStarDetector() no more accessible ?

Is it now StarDetectorBase() in place of OpenCVStarDetector() ?
Or how can I now do star detection from an image ?


Jean-Francois

Re: OpenCVStarDetector disappeared ...

Posted: Mon Apr 20, 2026 11:34 am
by admin
Hi Jean-Francois,

oh yes, oops... I removed it because nothing was using it internally and there was a better star detector that should be used instead. But I didn't think about scripting usage :(

The current recommended approach is to call DetectStars() directly on the frame - you have to pass a 'StarDetectionParameters' object which you can import from SharpCap.Base.

cheers,

Robin

Re: OpenCVStarDetector disappeared ...

Posted: Mon Apr 20, 2026 4:16 pm
by Jean-Francois
Hello Robin,

Thanks ... after several try and crashes ... it works fine.

Code: Select all

# IronPython Pad. Write code snippets here and F5 to run. If code is selected, only selection is run.


import time
import clr
clr.AddReference("System.Drawing")

from System.Drawing import *
from SharpCap.Base import StarDetectionParameters

detect = StarDetectionParameters()
detect.MaxCount   = 1000
detect.MinSize    = 1
detect.MaxSize    = 10
detect.BlurSigma  = 0.0
detect.FaintStars = True

Radius    = 6       # Circle radius
Length    = 5
pen_color = Pen(Color.FromName("Red"), 2.0)
pen_color2 = Pen(Color.FromName("Red"), 2.0)


def framehandler(sender, args):
    global dumpdata, Radius, pen_color
    if (dumpdata):
        #cutout = args.Frame.CutROI(SharpCap.Transforms.SelectionRect)
        try:
            stars = args.Frame.DetectStars(detect)
            #stars = cutout.DetectStars(detect)
#            print(len(stars))
#            for i in range(0, len(stars)):
#                print("X= ", stars[i].Position.X, " Y= ", stars[i].Position.Y)

            dbitmap = args.Frame.GetAnnotationGraphics("Test")
            for i in range(0, len(stars)):
                Pos_X = stars[i].Position.X + 0.5
                Pos_Y = stars[i].Position.Y + 0.5
                #Pos_X = Pos_X + SharpCap.Transforms.SelectionRect.Location.X
                #Pos_Y = Pos_Y + SharpCap.Transforms.SelectionRect.Location.Y
                dbitmap.DrawEllipse(pen_color2, Pos_X - Radius, Pos_Y - Radius, 2 * Radius, 2 * Radius)
                #dbitmap.DrawLine(pen_color, Pos_X - Length, Pos_Y, Pos_X + Length, Pos_Y)
                #dbitmap.DrawLine(pen_color, Pos_X, Pos_Y - Length, Pos_X, Pos_Y + Length)
            dbitmap.Dispose()

        except:
            print("Error")
        #cutout.Release()


#SharpCap.Transforms.SelectTransform("ROI Selection")

dumpdata = True
SharpCap.SelectedCamera.FrameCaptured += framehandler

time.sleep(5)

dumpdata = False
SharpCap.SelectedCamera.FrameCaptured -= framehandler

#SharpCap.Transforms.SelectTransform(None)
Regards,
Jean-Francois

Re: OpenCVStarDetector disappeared ...

Posted: Tue Apr 21, 2026 8:10 pm
by Jean-Francois
Hello Robin,

Thanks for the DetectStars() function. Yes, it seems to work better that the old OpenCVStarDetector().

I do not remark a difference with the BlurSigma parameter ... I have with 0 or 1 or 10 the same results.

The function can find some faint stars .. that is good (for the next function in my Occultation script).
But I remark that depending on the position of the SelectionRect, some stars are not found each time.

Jean-Francois

Re: OpenCVStarDetector disappeared ...

Posted: Wed Apr 22, 2026 1:37 pm
by admin
Hi,

interesting - you are right about the BlurSigma not being used in the end by the star detection algorithm - there is actually a way to set the noise reduction on the new star detection code, but it is not setup properly by the API you are using - that will be corrected in the next update for 4.1. I will also add a sensitivity parameter in 4.2, as I noticed that was missing from the parameters object.

For the stars not always being found, if the number of stars requested is not enough then you can get just stars from the top of the frame - do you still see the issue if you request 1000+ stars?

cheers,

Robin

Re: OpenCVStarDetector disappeared ...

Posted: Wed Apr 22, 2026 7:23 pm
by Jean-Francois
Hello Robin,

OK, good for new parameter in future version of SharpCap.

If you want to test the same here my last test script. I used the M42 image with gain=1600 and 20 ms exposure.
Change the sleep value (line 99) for longer test.

Code: Select all

import time
import clr
clr.AddReference("System.Drawing")

from System.Drawing import *
from SharpCap.Base import StarDetectionParameters, CoordinateParser, RADecPosition, RADecOffset, Epoch
from SharpCap.Interfaces import PlateSolvePurpose
from System.Threading import CancellationToken


detect = StarDetectionParameters()
print(detect.BlurSigma, detect.FaintStars, detect.MaxCount, detect.MaxSize, detect.MinSize, detect.SuppressHotPixels)
detect.BlurSigma         = 5.0
detect.FaintStars        = True
detect.MaxCount          = 1000
detect.MaxSize           = 10
detect.MinSize           = 2
detect.SuppressHotPixels = True
print(detect.BlurSigma, detect.FaintStars, detect.MaxCount, detect.MaxSize, detect.MinSize, detect.SuppressHotPixels)

Radius = 5       # Circle radius
Length = 3

if (SharpCap.ZoomPercent < 125):
    pen_red    = Pen(Color.FromName("Red"), 2.0)
    pen_green  = Pen(Color.FromName("Green"), 2.0)
    pen_blue   = Pen(Color.FromName("Blue"), 2.0)
    pen_yellow = Pen(Color.FromName("Yellow"), 2.0)
    print("2.0")
elif (SharpCap.ZoomPercent < 200):
    pen_red    = Pen(Color.FromName("Red"), 1.5)
    pen_green  = Pen(Color.FromName("Green"), 1.5)
    pen_blue   = Pen(Color.FromName("Blue"), 1.5)
    pen_yellow = Pen(Color.FromName("Yellow"), 1.5)
    print("1.5")
elif (SharpCap.ZoomPercent < 300):
    pen_red    = Pen(Color.FromName("Red"), 1.0)
    pen_green  = Pen(Color.FromName("Green"), 1.0)
    pen_blue   = Pen(Color.FromName("Blue"), 1.0)
    pen_yellow = Pen(Color.FromName("Yellow"), 1.0)
    print("1.0")
else:
    pen_red    = Pen(Color.FromName("Red"), 0.5)
    pen_green  = Pen(Color.FromName("Green"), 0.5)
    pen_blue   = Pen(Color.FromName("Blue"), 0.5)
    pen_yellow = Pen(Color.FromName("Yellow"), 0.5)
    print("0.5")


result = SharpCap.BlindSolver.Solve(PlateSolvePurpose.Annotation, CancellationToken())
print("Result", result)

Target = RADecPosition(5.6165, -4.8716667, Epoch.J2000)
#Target = RADecPosition(5.6040, -4.8377778, Epoch.J2000)
#Target = RADecPosition(5.6085278, -5.7166667, Epoch.J2000)

print("Target", Target)
star_coordinate = SharpCap.PixelPositionProvider.MapCoordinate(Target)

W = 100
H = 100

SharpCap.Transforms.SelectTransform("ROI Selection")
SharpCap.Transforms.SelectionRect = Rectangle(int(star_coordinate.X - W + 0), int(star_coordinate.Y - H + 0), 2 * W + 1, 2 * H + 1)


def framehandler(sender, args):
    global dumpdata, Radius, pen_color
    if (dumpdata):
        cutout = args.Frame.CutROI(SharpCap.Transforms.SelectionRect)
        try:
            #stars = args.Frame.DetectStars(detect)
            stars = cutout.DetectStars(detect)
#            print(len(stars))
#            for i in range(0, len(stars)):
#                print("X= ", stars[i].Position.X, " Y= ", stars[i].Position.Y)

            dbitmap = args.Frame.GetAnnotationGraphics("Test")
            for i in range(0, len(stars)):
                Pos_X = stars[i].Position.X + 0.5
                Pos_Y = stars[i].Position.Y + 0.5
                Pos_X = Pos_X + SharpCap.Transforms.SelectionRect.Location.X
                Pos_Y = Pos_Y + SharpCap.Transforms.SelectionRect.Location.Y
                dbitmap.DrawEllipse(pen_red, Pos_X - Radius, Pos_Y - Radius, 2 * Radius, 2 * Radius)
                dbitmap.DrawLine(pen_yellow, Pos_X - Length, Pos_Y, Pos_X + Length, Pos_Y)
                dbitmap.DrawLine(pen_yellow, Pos_X, Pos_Y - Length, Pos_X, Pos_Y + Length)
            dbitmap.Dispose()

        except:
            print("Error")
        cutout.Release()



dumpdata = True
SharpCap.SelectedCamera.FrameCaptured += framehandler

time.sleep(30)

dumpdata = False
SharpCap.SelectedCamera.FrameCaptured -= framehandler

SharpCap.Transforms.SelectTransform(None)

Here with the same SelectionRect but at different position. The script sets 1000 stars ... much more than visible in the SelectionRect.
Detect_stars_some_missing.jpg
Detect_stars_some_missing.jpg (954.91 KiB) Viewed 674 times

Regards,
Jean-Francois

Re: OpenCVStarDetector disappeared ...

Posted: Thu Apr 23, 2026 10:49 am
by admin
Hi Jean-Francois,

I'll have to dig into that a bit - it's not a great image to test with as it is already processed *and* the underlying data is only 8 bit, which can cause problems, but even allowing for that there are some stars missed that I would have expected to be detected. I had a play in the new version and the sensitivity helps a bit, but doesn't explain everything.

cheers,

Robin

Re: OpenCVStarDetector disappeared ...

Posted: Sun May 31, 2026 5:28 pm
by Jean-Francois
Hello Robin,

Do you find why the star detection does not find the same stars depending on the position of the red rectangle ?

Jean-Francois

Re: OpenCVStarDetector disappeared ...

Posted: Mon Jun 01, 2026 2:15 pm
by admin
Hi,

to some extent, yes - part of the detection is an auto-stretch of the image to help bring out the faint objects, and that uses the histogram data of the selected area to calculate the stretch, so a different selection means a different stretch, means that the detection then runs differently from that point in the algorithm.

The deep sky camera sample image isn't really a great one for testing this sort of thing, as it has already been processed (including non-linear stretching), so it doesn't really behave in the same way that an individual deep sky frame would.

cheers,

Robin

Re: OpenCVStarDetector disappeared ...

Posted: Mon Jun 01, 2026 4:41 pm
by Jean-Francois
Hello Robin,

OK, understood.
I will test in future with more realistic "raw" images (or films).

Jean-Francois