OpenCV Frame Grabber 在 MacOS Catalina 上无法工作。

huangapple go评论58阅读模式
英文:

OpenCV Frame Grabber not work on MacOS Catalina

问题

在macOS Catalina终端中输入以下命令时,会获得以下结果:

java -jar test-1.0-SNAPSHOT.jar

结果如下:

启动应用程序
zsh: 中止         java -jar test-1.0-SNAPSHOT.jar

更多细节:

我的应用程序的主要功能基于摄像头捕捉,我有一个要求是应用程序需要在Windows 10、Linux和MacOS上运行。这就是为什么我决定选择JavaCV来处理摄像头捕捉。在Windows和Linux上一切正常。然而,在MacOS上无法正常工作。为了在Mac上测试应用程序,我正在使用VirtualBox 6.1和macOS Catalina 10.15.5。在项目中,我还使用了Gradle和Kotlin。

我还检查了虚拟机是否有权限访问摄像头,并且摄像头在系统应用程序中正常工作。我怀疑应用程序由于摄像头权限问题而无法正常工作。

我还要补充说明,macOS Catalina已经更新到最新版本。

基本代码:

build.gradle:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.72'
    id 'application'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.3'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

jar {
    manifest {
        attributes "Main-Class": "App"
    }
    from {
        configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }

    exclude('META-INF/*.SF')
    exclude('META-INF/*.DSA')
    exclude('META-INF/*.RSA')
    exclude('module-info.class')
}
mainClassName = 'App'

App.kt:

import org.bytedeco.javacv.OpenCVFrameGrabber

class App {
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            println("启动应用")
            val grabber: OpenCVFrameGrabber = OpenCVFrameGrabber(0)
            grabber.start()
        }
    }
}

为了创建可执行的JAR文件,我在Mac终端中输入以下命令:

sudo ./gradlew clean build
英文:

Short version:

when I'm type this command in macOS Catalina terminal:

java -jar test-1.0-SNAPSHOT.jar

gets the result:

Start App
zsh: abort         java -jar test-1.0-SNAPSHOT.jar

More details:

My main feature in app is based on webcam capture and I have a requirement for the application to work on Windows 10, Linux and MacOS. That's why I decided to choose JavaCV to handle webcam capturning. Everything works fine on windows and linux. However, it doesn't work properly on MacOS. For testing the application on a Mac, I'm using virtual box 6.1 and macOS Catalina 10.15.5. In project I'm also using gradle and kotlin.

I also checked if I have access to the camera from virtual machine and the camera works correctly in system applications. I suspect that the application is not working due to camera permissions.

I will also add that the macOS Catalina is up to date

Basic code

build.gradle:

plugins {
    id &#39;java&#39;
    id &#39;org.jetbrains.kotlin.jvm&#39; version &#39;1.3.72&#39;
    id &#39;application&#39;
}

group &#39;org.example&#39;
version &#39;1.0-SNAPSHOT&#39;

repositories {
    mavenCentral()
}

dependencies {
    implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk8&quot;
    testCompile group: &#39;junit&#39;, name: &#39;junit&#39;, version: &#39;4.12&#39;

    compile group: &#39;org.bytedeco&#39;, name: &#39;javacv-platform&#39;, version: &#39;1.5.3&#39;
}

compileKotlin {
    kotlinOptions.jvmTarget = &quot;1.8&quot;
}
compileTestKotlin {
    kotlinOptions.jvmTarget = &quot;1.8&quot;
}

jar {
    manifest {
        attributes &quot;Main-Class&quot;: &quot;App&quot;
    }
    from {
        configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }

    exclude(&#39;META-INF/*.SF&#39;)
    exclude(&#39;META-INF/*.DSA&#39;)
    exclude(&#39;META-INF/*.RSA&#39;)
    exclude(&#39;module-info.class&#39;)
}
mainClassName = &#39;App&#39;

App.kt

import org.bytedeco.javacv.OpenCVFrameGrabber

class App {
    companion object {
        @JvmStatic
        fun main(args: Array&lt;String&gt;) {
            println(&quot;Start App&quot;)
            val grabber: OpenCVFrameGrabber = OpenCVFrameGrabber(0);
            grabber.start()
        }
    }
}

In order to create executable jar file, I'm type this in mac terminal:

sudo 
./gradlew clean build

答案1

得分: 0

我解决了我的问题。macOS的问题在于应用程序在启动之前应该请求摄像头访问权限。macOS不将JAR文件视为应用程序。更多信息在此处。例如,当你通过IDE运行应用程序时,系统会要求你访问摄像头的权限。

英文:

I solved my problem. The problem with macOS was that the app should ask for camera access before launching it. Jar files are not treated as applications by macOS.
More info here. For example, when you running the application by IDE, system will ask you for access to the camera.

huangapple
  • 本文由 发表于 2020年7月21日 22:35:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63016904.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定