opencv problem with bootcamp

edited September 24 in Kinect

I'm trying to do face detection on a video with opencv on bootcamp (windows 10) and processing 2.2.1

import processing.video.*;

Movie video; import gab.opencv.*; import java.awt.Rectangle;

OpenCV opencv; Rectangle[] faces;

void setup() { size(640,360);

video = new Movie(this, "people.mp4"); video.play(); video.loop();
opencv = new OpenCV(this, video.width, video.height); opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); }

void draw() { background(0); fill(255);
image(video,0,0);
opencv.loadImage(video); faces = opencv.detect();
}

void movieEvent(Movie m) { m.read();
}

It crashes at the line: opencv.loadImage(video);

With the message: IndexOutOfBoundsException: Index 3: Size 0

Any ideas? This works fine on mac osx with the same version of processing.

Answers

  • edited October 2016

    https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    • The 1st Movie's frame takes some time to get read().
    • If we try to access its content before it's fully ready it can crash the sketch! :-SS
    • There are some approaches we can take, like checking whether Movie's width or height aren't 0 before calling OpenCV's loadImage() over the Movie instance.
    • But my favorite is keeping calling delay() within setup() until we got a non-0 height: \m/

    /**
     * Resurfaced Movie (v1.0)
     * GoToLoop (2016-Oct-14)
     * forum.Processing.org/two/discussion/18536/
     * opencv-problem-with-bootcamp#Item_1
     */
    
    import processing.video.Movie;
    static final String MOVIE = "people.mp4";
    Movie mov;
    
    void setup() {
      (mov = new Movie(this, MOVIE)).play();
      while (mov.height == 0)  delay(10);
    
      getSurface().setSize(mov.width, mov.height);
      getSurface().setTitle(MOVIE);
    }
    
    void draw() {
      background(mov);
    }
    
    void movieEvent(final Movie mv) {
      mv.read();
    }
    
  • Thanks for the response. That doesn't seem to help though.

    The video is loading correctly. The problem seems to be inside opencv.

  • Well, .loadImage is encountering a size 0 array. I'm curious, why do you say it is loading correctly? Do you have separate evidence of that?

    • Have you tried another movie file just to see if it is a specific encoding issue?
    • Is there demo code for openCV.loadImage that you can start with testing as a baseline?
  • The video is playing correctly, if I comment out the openCV.loadImage line it plays correctly on the screen, I've tried several different videos and they produce the same result.

    If I put a println just abouve opencv.loadImage to print the width/height of the video it gives the correct size of the video even on the first loop.

    Even loading an image and passing that to opencv.loadImage produces the same result...

  • @jayson -- I don't work a lot with movies and opencv in Processing, but according to what I'm seeing in the opencv.loadImage source code, it takes either a filename string or a PImage. Is 'video' a PImage?

    By "loading an image ... produces the same result" did you mean that you created a PImage from video first, then passed that to opencv.loadImage(), and it still didn't work?

    Re: my suggestion to trying demo code first. There are a lot of opencv-processing examples that use loadImage. Do any of them work for you? If none of them work, perhaps you should report an issue. There may already be a related issue in the open issues list.

Sign In or Register to comment.