Skip to content

Commit

Permalink
Fix isOpen bug in OpenPnp backend
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Nov 19, 2024
1 parent b8dca6b commit a63a34b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -87,6 +89,7 @@ class OpenPnpWebcam(
)

if (result != OpenpnpCaptureLibrary.CAPRESULT_OK) {
streaming = false
throw CaptureException(result);
}
}
Expand All @@ -96,7 +99,6 @@ class OpenPnpWebcam(
}

memory.read(0, bytes, 0, bytes.size)

mat.put(0, 0, bytes)
}

Expand All @@ -106,6 +108,7 @@ class OpenPnpWebcam(
synchronized(lock) {
stream = device.openStream(format)
reflectStream = ReflectCaptureStream(stream!!)
streaming = true
}
return
}
Expand All @@ -118,6 +121,7 @@ class OpenPnpWebcam(
synchronized(lock) {
stream?.close()
stream = null
streaming = false
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ buildscript {

subprojects {
group 'org.deltacv.steve'
version '1.1.2'
version '1.1.3'
}
2 changes: 1 addition & 1 deletion example/src/main/kotlin/io/github/deltacv/steve/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a63a34b

Please sign in to comment.