Skip to content

Commit

Permalink
Add plate solving
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Corry <kylecorry31@gmail.com>
  • Loading branch information
kylecorry31 committed Dec 21, 2024
1 parent bffefe3 commit c34097e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package com.kylecorry.trail_sense.tools.celestial_navigation
import android.graphics.BitmapFactory
import androidx.test.platform.app.InstrumentationRegistry
import com.kylecorry.andromeda.files.AssetFileSystem
import com.kylecorry.sol.science.astronomy.Astronomy
import com.kylecorry.sol.science.astronomy.stars.AltitudeAzimuth
import com.kylecorry.sol.science.astronomy.stars.Star
import com.kylecorry.trail_sense.tools.celestial_navigation.domain.DifferenceOfGaussiansStarFinder
import com.kylecorry.trail_sense.tools.celestial_navigation.domain.PercentOfMaxStarFinder
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import java.time.ZoneId
import java.time.ZonedDateTime

class StarFinderTest {

Expand All @@ -18,6 +24,20 @@ class StarFinderTest {
"stars/20241215_020631.jpg",
)

val expectedStars = listOf(
emptyList(),
emptyList(),
listOf(
Star.Alnilam,
Star.Mintaka,
Star.Alnitak,
Star.Betelgeuse,
Star.Rigel,
Star.Bellatrix,
Star.Saiph
)
)

for (file in images) {
val assets = AssetFileSystem(InstrumentationRegistry.getInstrumentation().context)
val image = assets.stream(file).use {
Expand All @@ -28,6 +48,24 @@ class StarFinderTest {
// val stars = StandardDeviationStarFinder(5f).findStars(image)
val stars = DifferenceOfGaussiansStarFinder(0.3f).findStars(image)
assert(stars.isNotEmpty())
val starReadings = stars.map {
val xAngle = ((it.x - image.width / 2) / image.width.toFloat()) * 8.566184f
val yAngle = -((it.y - image.height / 2) / image.height.toFloat()) * 6.77276f
AltitudeAzimuth(yAngle, xAngle)
}

val plate =
Astronomy.plateSolve(
starReadings,
ZonedDateTime.of(2024, 12, 15, 2, 0, 0, 0, ZoneId.of("America/New_York")),
tolerance = 0.1f
)

val expected = expectedStars[images.indexOf(file)]
if (expected.isNotEmpty()) {
assertEquals(expected.size, plate.size)
assertTrue(plate.map { it.second }.containsAll(expected))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SimpleStarFinder(private val threshold: Float = 200f) : StarFinder {
val yScale = resized.height.toFloat() / image.height

try {
val pointFinder = GrayscalePointFinder(threshold, 0.5f, Range(0.5f, 1.5f))
val pointFinder = GrayscalePointFinder(threshold, 0.5f, Range(0.5f, 2f))
return pointFinder.getPoints(resized).map {
PixelCoordinate(it.center.x / xScale, it.center.y / yScale)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.kylecorry.sol.math.SolMath.deltaAngle
import com.kylecorry.sol.math.SolMath.map
import com.kylecorry.sol.math.SolMath.square
import com.kylecorry.sol.science.astronomy.Astronomy
import com.kylecorry.sol.science.astronomy.stars.AltitudeAzimuth
import com.kylecorry.sol.science.astronomy.stars.Star
import com.kylecorry.sol.science.astronomy.stars.StarReading
import com.kylecorry.sol.time.Time
Expand Down Expand Up @@ -265,6 +266,24 @@ class CelestialNavigationFragment : BoundFragment<FragmentCelestialNavigationBin
)
}
debugLayer.setMarkers(markers)

// Plate solve
val starReadings = starPixels.map {
val point = binding.arView.toCoordinate(
it,
rotationMatrixOverride = rotationMatrix
)
AltitudeAzimuth(point.elevation, point.bearing)
}

val plate = Astronomy.plateSolve(
starReadings,
ZonedDateTime.now()
)

// TODO: Record all the stars (present this to the user - draw over the image?)
println(plate)
toast("Detected ${plate.size} stars: ${plate.map { it.second.name }}")
}

if (starPixels.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ material = "1.10.0"
luna = "0.3.6"
mockitoKotlin = "5.1.0"
roomVersion = "2.6.1"
sol = "10.0.3"
sol = "10.1.2"
workRuntimeKtx = "2.10.0"
preferenceKtx = "1.2.1"

Expand Down

0 comments on commit c34097e

Please sign in to comment.