OpenCVStarDetector disappeared ...
-
Jean-Francois
- Posts: 859
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
OpenCVStarDetector disappeared ...
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
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
- admin
- Site Admin
- Posts: 17606
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: OpenCVStarDetector disappeared ...
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
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
-
Jean-Francois
- Posts: 859
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
Re: OpenCVStarDetector disappeared ...
Hello Robin,
Thanks ... after several try and crashes ... it works fine.
Regards,
Jean-Francois
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)
Jean-Francois
-
Jean-Francois
- Posts: 859
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
Re: OpenCVStarDetector disappeared ...
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
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
- admin
- Site Admin
- Posts: 17606
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: OpenCVStarDetector disappeared ...
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
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
-
Jean-Francois
- Posts: 859
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
Re: OpenCVStarDetector disappeared ...
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.
Here with the same SelectionRect but at different position. The script sets 1000 stars ... much more than visible in the SelectionRect.
Regards,
Jean-Francois
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.
Regards,
Jean-Francois
- admin
- Site Admin
- Posts: 17606
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: OpenCVStarDetector disappeared ...
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
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
-
Jean-Francois
- Posts: 859
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
Re: OpenCVStarDetector disappeared ...
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
Do you find why the star detection does not find the same stars depending on the position of the red rectangle ?
Jean-Francois
- admin
- Site Admin
- Posts: 17606
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: OpenCVStarDetector disappeared ...
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
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
-
Jean-Francois
- Posts: 859
- Joined: Sun Oct 13, 2019 10:52 am
- Location: Germany
Re: OpenCVStarDetector disappeared ...
Hello Robin,
OK, understood.
I will test in future with more realistic "raw" images (or films).
Jean-Francois
OK, understood.
I will test in future with more realistic "raw" images (or films).
Jean-Francois