Ask Your Question
0

VideoCapture (0) does not work in mac Catalina. The program crashed

asked 2020-01-24 05:05:37 -0600

robertodaza gravatar image

updated 2020-01-24 09:44:22 -0600

VideoCapture (0) of opencv 3.4.5 in eclipse does not work for me. The program crashes. I don't know if it has to do with Catalina's permits. Eclipse does not throw error.

How can I fix the error?

Thanks in advance.

This is the code:

 package prueba;

import java.awt.AWTException;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import java.time.LocalTime;

import javax.imageio.ImageIO;

import org.opencv.core.Core;
import org.opencv.core.Mat;

import org.opencv.videoio.VideoCapture;


    public class prueba {

        public static void main (String args[]) throws InterruptedException{

            int i=0;
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
            File directorio=new File("Capturas"); 
            directorio.mkdir(); 
            VideoCapture camera = new VideoCapture(0);//program crashes
            System.out.println("It doesn't arrive here");
            Mat frame = new Mat();
        while (i<20) {
            if(!camera.isOpened()){
                System.out.println("Error");
            }
            else {                  


                 System.out.println("all right");
             } 

         i++;
        }

        camera.release();//close

      }

    }

upgrade

I just downloaded the latest version of opencv 4.2.0 and now show the following error:

OpenCV: not authorized to capture video (status 0), requesting...
OpenCV: can not spin main run loop from other thread, set OPENCV_AVFOUNDATION_SKIP_AUTH=1 to disable authorization request and perform it in your application.
OpenCV: camera failed to properly initialize!

how i can setup OPENCV_AVFOUNDATION_SKIP_AUTH = 1 to disable the authorization request?

edit retag flag offensive close merge delete

Comments

1

it's not an opencv problem, your process needs special permission to use the camera with your os

berak gravatar imageberak ( 2020-01-24 05:08:44 -0600 )edit

How can I create the permission? I would be very grateful if you will help me

robertodaza gravatar imagerobertodaza ( 2020-01-24 05:16:09 -0600 )edit
1

sorry, no idea, you'll have to ask apple users

berak gravatar imageberak ( 2020-01-24 05:34:54 -0600 )edit
1

In version 4.2.0 of opencv throws an error:

OpenCV: not authorized to capture video (status 0), requesting...
OpenCV: can not spin main run loop from other thread, set OPENCV_AVFOUNDATION_SKIP_AUTH=1 to disable authorization request and perform it in your application.
OpenCV: camera failed to properly initialize!

I don't know how to fix it?

robertodaza gravatar imagerobertodaza ( 2020-01-24 09:46:27 -0600 )edit

Upgraded OpenCV 4.2.0.

supra56 gravatar imagesupra56 ( 2020-01-24 21:02:06 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-06-26 11:30:38 -0600

HaGeKa gravatar image

For this trick worked:

  1. Find the file info.plist in "/Library/Java/JavaVirtualMachines/your-JRE/Contents
  2. add to info.plist in <dict>:

... <key>NSCameraUsageDescription</key> <string>OpenCV/string> <key>NSMicrophoneUsageDescription</key> <string>OpenCV</string> ...


After that I had to reopen the project in Netbeans but I was asked to grand access to the camera as it should be.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-01-24 05:05:37 -0600

Seen: 5,077 times

Last updated: Jan 24 '20