2017-01-06 4 views
0

Ich versuche, Video in JavaCV importieren, aber cvCreateFileCapture ("Dateiname") -Klasse gibt Nullwert zurück und ich habe auch versucht, mit OpenCVFrameGrabber ("Dateiname"), es funktioniert auch nicht richtig.In Javacv cvCreateFileCapture ist nicht in der Lage, das Video aus dem Speicher zu lesen

Hier ist mein Code:

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 
    } 
} 

}

Gibt es eine andere Möglichkeit, das Video in javacv zu importieren.

Antwort

0

Sind Sie sicher, dass Sie diese Datei in Ihrem Klassenpfad haben? Können Sie Folgendes versuchen, um zu prüfen, ob die Datei existiert und die Ausgabe bitte anzeigen?

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

Ja bin ich sicher abt es. –

Verwandte Themen