sarxos / webcam-capture

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.
http://webcam-capture.sarxos.pl
MIT License
2.25k stars 1.11k forks source link

Can't get any camera in MacOS using example code?Any help? #791

Open yongxin100 opened 3 years ago

yongxin100 commented 3 years ago

Hi I launched a project in IDEA IDE and running example code of project:

       List<Webcam> webcam = Webcam.getWebcams(1000*50);
        if (webcam != null) {
            System.out.println("Webcam: " + webcam.size());
        } else {
            System.out.println("No webcam detected");
        }

But i got zero size of webcam list!!!

When i am using the default camera app PhotoBooth ,i can see both usb camera i attached to MacBook and internal camera.

It is something related to MacOS's permission strategy??

Thanks a lot!

yongxin100 commented 3 years ago

ok, I 've solved the problem by following steps: 1、 use snapshot version of webcam-capture. 2、add nativelibs4java dependency to pom of the my project The POM files as following:

`<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>org.example</groupId>
<artifactId>jxxbarcode</artifactId>
<version>1.0-SNAPSHOT</version>

<repositories>
    <repository>
        <id>Sonatype OSS Snapshot Repository</id>
        <url>http://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>

    <repository>
        <id>bridjhack</id>
        <url>http://maven.ecs.soton.ac.uk/content/repositories/thirdparty/</url>
    </repository>

</repositories>

<dependencies>

    <dependency>
        <groupId>com.github.sarxos</groupId>
        <artifactId>webcam-capture</artifactId>
        <version>0.3.13-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.nativelibs4java</groupId>
        <artifactId>bridj</artifactId>
        <version>0.7-20140918-2</version>
    </dependency>

    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacv</artifactId>
        <version>1.4.3</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.25</version>
        <!-- <scope>test</scope> -->
    </dependency>

</dependencies>

`