OpenCV在mac上无法正常工作 [英] OpenCV not working correctly on mac

查看:286
本文介绍了OpenCV在mac上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用OpenCV使用网络摄像头拍照的程序。它就像在Windows上的魅力,但它不适用于OSx。应显示Webcam视图的框架保持空白。当我拍照时,它只显示一个黑色的空白,好像它无法找到网络摄像头

I have a program that uses OpenCV to take a picture using your webcam. It works like a charm on windows, yet, it doesn't work on OSx. The Frame where the Webcam view should appear stays empty. And when I take a picture, it just shows a black void, as if it couldnt find the webcam

public void run(){
        try {
            grabber = new VideoInputFrameGrabber(0); 
            grabber.start();
            while (active) {
                IplImage originalImage = grabber.grab();
                Label.setIcon(new ImageIcon( originalImage.getBufferedImage() ));
            }
            grabber.stop();
            grabber.flush();

        } catch (Exception ex) {
            //Logger.getLogger(ChPanel.class.getName()).log(Leve l.SEVERE, null, ex);
        }

    }

    public BufferedImage saveImage(){
        IplImage img;
        try {
            //capture image
            img = grabber.grab();
            // save to file
            File outputfile = new File(Project.getInstance().getFileURLStr() + " capture" + fotoCount++ + ".jpg");
            ImageIO.write(img.getBufferedImage(), "jpg", outputfile);    

            //get file and set it in the project library
            BufferedImage ImportFile = ImageIO.read(outputfile);
            Project p = Project.getInstance();
            MainScreen ms = MainScreen.getInstance();
            ImageIcon takenPhoto = new ImageIcon(ImportFile);
            p.setNextImage(takenPhoto);
            ms.setPanels();
            return ImportFile;
        } catch (com.googlecode.javacv.FrameGrabber.Exception e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }

有谁知道如何解决这个问题?我怀疑使用网络摄像头的权利或类似的东西

Does anyone know how to solve this? I suspect something about rights to use the webcam or something like that

推荐答案

grabber = new VideoInputFrameGrabber(0); 

此处 0 指定为捕获设备编号0

可能是第0个设备无法用于视频捕获的数字

使用此代码分别获取设备和数字列表。

Use this code to get the list of devices and number respectively.

import com.googlecode.javacv.cpp.videoInputLib.videoInput;
class Main {


     public static void main(String[] args) {
           int n=videoInput.listDevices();
           for(int i=0;i<n;i++)
        {
            System.out.println(i+" = "+videoInput.getDeviceName(i));

        }

}
}

然后指定该设备的编号

grabber = new VideoInputFrameGrabber(1); // 0 or 1 or 2

这篇关于OpenCV在mac上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆