Frame Grabber

677 views
Skip to first unread message

Caitlyn Clabaugh

unread,
Nov 7, 2010, 8:21:34 PM11/7/10
to javacv
Hello,
I am new to JavaCV and am trying, very simply, to just run frames from
my camera and display them in a window. I have successfully seen done
this in the camcalib demo. Unfortunately when I attempt to run the
source code of that demo, or write my own code, I get a similar error
message. Which is the following:

Nov 7, 2010 8:12:17 PM asl2txt.Main1 main
SEVERE: null
java.lang.Exception: cvRetrieveFrame() Error: Could not retrieve
frame.
at
com.googlecode.javacv.OpenCVFrameGrabber.grab(OpenCVFrameGrabber.java:
149)
at asl2txt.Main1.main(Main1.java:41)

Here is my code, I am running on linux and am sure that all the
appropriate jar files are in the appropriate places.

package asl2txt;


import static com.googlecode.javacv.jna.cxcore.*;
import static com.googlecode.javacv.jna.cv.*;
import com.googlecode.javacv.jna.highgui.*;
import com.googlecode.javacv.jna.cvaux.*;
import com.googlecode.javacv.CameraDevice;
import com.googlecode.javacv.CameraSettings;
import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.CanvasFrame;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Main1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

//Initiate all variables needed (e.g. the frame grabber, the
variable to hold the frame captured (IplImage), the canvas window
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
IplImage frame;
IplImage frameCopy;
CameraSettings cameraSettings = null;
CameraDevice cameraDevices = null;

CanvasFrame window = new CanvasFrame("Frame Grabber");


while(true){ //Run frame grabbing process forever
try {
//Run frame grabbing process forever
frame = grabber.grab(); //save current frame IT
BREAKS HERE
window.showImage(frame); //show it in the window
}

catch (Exception ex) {

Logger.getLogger(Main1.class.getName()).log(Level.SEVERE, null, ex);
}


}

}

}

Samuel Audet

unread,
Nov 7, 2010, 8:24:31 PM11/7/10
to jav...@googlegroups.com
Hello,

You didn't call grabber.start() before grabber.grab().. I'll have to add
a better error messages, thanks for the tip

Samuel

Caitlyn Clabaugh

unread,
Nov 7, 2010, 8:38:49 PM11/7/10
to javacv
Thanks, so much it worked!

BTW, do you have a reference manual written yet? If you don't I could
probably write one for you at this point :)

Samuel Audet

unread,
Nov 7, 2010, 8:40:29 PM11/7/10
to jav...@googlegroups.com
Nothing much yet no.. You could start by adding content to the wiki I
suppose. Let me know when/if you feel like doing that

Samuel

Caitlyn Clabaugh

unread,
Nov 8, 2010, 3:43:02 PM11/8/10
to javacv
Also, I have the camera capturing and showing images in a window
however I continually get this errors as it runs:

HIGHGUI ERROR: V4L2: getting property #0 is not supported
Corrupt JPEG data: 85 extraneous bytes before marker 0xd9

And it sometimes misses a frame because of it.
I figured it had to do with this line of code: OpenCVFrameGrabber
grabber = new OpenCVFrameGrabber(0);
But I know 0 is for webcam and since that is what I am using, I cannot
change it without it not working completely.

Any ideas?

Thanks,
Caitlyn

Samuel Audet

unread,
Nov 8, 2010, 8:28:09 PM11/8/10
to jav...@googlegroups.com
If it does the same thing from a program in C, then this is a problem
with OpenCV. FFmpeg probably supports V4L better than OpenCV, so you may
want to try that instead, something like
FrameGrabber grabber = new FFmpegFrameGrabber("/dev/video0"
,"video4linux2")
If that does not work, then I would make sure your Webcam drivers
actually work any better in other applications

Samuel

Reply all
Reply to author
Forward
0 new messages