Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 在Javacv中,cvCreateFileCapture无法从内存中读取视频_Opencv_Javacv - Fatal编程技术网

Opencv 在Javacv中,cvCreateFileCapture无法从内存中读取视频

Opencv 在Javacv中,cvCreateFileCapture无法从内存中读取视频,opencv,javacv,Opencv,Javacv,我试图在javacv中导入视频,但cvCreateFileCapture(“文件名”)类返回空值,并且我还尝试使用OpenCVFrameGrabber(“文件名”),它也不能正常工作 这是我的密码: public class SmokeDetectionInStoredVideo { private static final int IMG_SCALE = 2; private static final int width = 640; private static

我试图在javacv中导入视频,但cvCreateFileCapture(“文件名”)类返回空值,并且我还尝试使用OpenCVFrameGrabber(“文件名”),它也不能正常工作

这是我的密码:

public class SmokeDetectionInStoredVideo {
    private static final int IMG_SCALE = 2;
    private static final int width = 640;  
    private static final int height = 480;

public static void main(String args[]){
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    CvMemStorage storage = CvMemStorage.create();
    IplImage img1=null,imghsv=null,imgbin=null;
    CvSeq contour1;
    CvSeq contour2;
    double areaMax = 00, areaC = 0.0;
    imghsv = IplImage.create(width/IMG_SCALE, height/IMG_SCALE, 8, 3);
    imgbin = IplImage.create(width/IMG_SCALE, height/IMG_SCALE, 8, 1);
    try{
        CvCapture capture = cvCreateFileCapture("Red.mp4");//cvCreateCameraCapture(0);
        if(capture.isNull()){
            System.out.println("Error reading file");
        }
        IplImage grabbedImage = cvQueryFrame(capture);
        OpenCVFrameConverter.ToIplImage converter=new OpenCVFrameConverter.ToIplImage();
        CanvasFrame canvasFrame = new CanvasFrame("Actual Video");
        CanvasFrame canvasBinFrame = new CanvasFrame("Contour Video");
        canvasFrame.setCanvasSize(grabbedImage.width(), grabbedImage.height());
        canvasBinFrame.setCanvasSize(grabbedImage.width(), grabbedImage.height());
        imghsv = IplImage.create(grabbedImage.width(), grabbedImage.height(), 8, 3);
        imgbin = IplImage.create(grabbedImage.width(), grabbedImage.height(), 8, 1);

        while (canvasFrame.isVisible() && (img1 = cvQueryFrame(capture)) != null) {
            cvCvtColor(img1, imghsv, CV_RGB2HSV);
            //canvasFrame.showImage(converter.convert(imghsv));

            cvInRangeS(img1, cvScalar(220, 220, 220, 0), cvScalar(235, 235, 235, 0), imgbin);
            contour1 = new CvSeq();
            cvFindContours(imgbin, storage, contour1, Loader.sizeof(CvContour.class), CV_RETR_LIST, CV_LINK_RUNS);
            contour2 = contour1;

            while (contour1 != null && !contour1.isNull()) {
                areaC = cvContourArea(contour1, CV_WHOLE_SEQ, 1);
                if(areaC>areaMax){
                    areaMax = areaC;
                }
                contour1 = contour1.h_next();
            }

            while (contour2 != null && !contour2.isNull()){
                areaC = cvContourArea(contour2, CV_WHOLE_SEQ, 1);
                if(areaC>areaMax){
                    cvDrawContours(imgbin, contour1, CV_RGB(0, 0, 0), CV_RGB(0, 0, 0), 0, CV_FILLED, 8);
                }
                contour2 = contour2.h_next();
            }
            canvasBinFrame.showImage(converter.convert(imgbin));
            canvasFrame.showImage(converter.convert(img1));
        }
        canvasFrame.dispose();
        cvReleaseMemStorage(storage);
        cvReleaseImage(img1);
        cvReleaseImage(imgbin);
        cvReleaseImage(imghsv);
    }
    catch (Exception e) {
        System.out.println("Error while processing video");
        // TODO: handle exception
    }
}
}


是否有其他方法在javacv中导入视频。

是否确定类路径中有此文件?请尝试以下方法检查文件是否存在并显示输出,好吗

File file = new File("Red.mp4");
System.out.println(file.exists());

是的,我肯定。