From a63a34be8b9f4993abe859bc6cd4ea5248d37222 Mon Sep 17 00:00:00 2001 From: Sebastian Erives Date: Tue, 19 Nov 2024 02:44:55 -0600 Subject: [PATCH] Fix isOpen bug in OpenPnp backend --- .../io/github/deltacv/steve/openpnp/OpenPnpWebcam.kt | 8 ++++++-- build.gradle | 2 +- example/src/main/kotlin/io/github/deltacv/steve/Main.kt | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend-openpnp/src/main/kotlin/io/github/deltacv/steve/openpnp/OpenPnpWebcam.kt b/backend-openpnp/src/main/kotlin/io/github/deltacv/steve/openpnp/OpenPnpWebcam.kt index 264768d..959f14c 100644 --- a/backend-openpnp/src/main/kotlin/io/github/deltacv/steve/openpnp/OpenPnpWebcam.kt +++ b/backend-openpnp/src/main/kotlin/io/github/deltacv/steve/openpnp/OpenPnpWebcam.kt @@ -22,8 +22,10 @@ class OpenPnpWebcam( private var stream: CaptureStream? = null private var reflectStream: ReflectCaptureStream? = null + private var streaming = false + override val isOpen: Boolean - get() = stream != null && stream!!.hasNewFrame() + get() = stream != null && streaming override var resolution = supportedResolutions.getOrElse(0) { throw IllegalStateException("No supported resolutions found for ${device.name}") @@ -87,6 +89,7 @@ class OpenPnpWebcam( ) if (result != OpenpnpCaptureLibrary.CAPRESULT_OK) { + streaming = false throw CaptureException(result); } } @@ -96,7 +99,6 @@ class OpenPnpWebcam( } memory.read(0, bytes, 0, bytes.size) - mat.put(0, 0, bytes) } @@ -106,6 +108,7 @@ class OpenPnpWebcam( synchronized(lock) { stream = device.openStream(format) reflectStream = ReflectCaptureStream(stream!!) + streaming = true } return } @@ -118,6 +121,7 @@ class OpenPnpWebcam( synchronized(lock) { stream?.close() stream = null + streaming = false } } diff --git a/build.gradle b/build.gradle index da41b5d..8a03edb 100644 --- a/build.gradle +++ b/build.gradle @@ -18,5 +18,5 @@ buildscript { subprojects { group 'org.deltacv.steve' - version '1.1.2' + version '1.1.3' } \ No newline at end of file diff --git a/example/src/main/kotlin/io/github/deltacv/steve/Main.kt b/example/src/main/kotlin/io/github/deltacv/steve/Main.kt index c28ef69..88ee5f6 100644 --- a/example/src/main/kotlin/io/github/deltacv/steve/Main.kt +++ b/example/src/main/kotlin/io/github/deltacv/steve/Main.kt @@ -24,7 +24,7 @@ fun main() { val frame = Mat() - while(true) { + while(webcam.isOpen) { webcam.read(frame) Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGB2BGR) HighGui.imshow("Webcam", frame)