Ask Your Question
0

capture image to slow with java

asked 2013-09-05 13:54:56 -0600

a242133 gravatar image

updated 2013-09-13 11:47:58 -0600

open webcam, read and releas takes about 600ms. Is there a way to speed-up? Using it on Windows 7 with latest java and recent opencv:

VideoCapture webcam = new VideoCapture();
boolean opened = webcam.opened();
if (opened) {
    return null;
}
try {
    webcam.open(0);
} catch (Exception e) {
    return null;
}

if (!webcam.opened()) {
    return null;
}
try {
    Mat frame = new Mat();
    webcam.read(frame);
    //do somethinig
    webcam.release();
} catch (Exception e) {
    null
}
return null;
edit retag flag offensive close merge delete

Comments

So many information about your system, camera etc.

Moster gravatar imageMoster ( 2013-09-05 16:25:26 -0600 )edit

@Monster You're right. I did add more information

a242133 gravatar imagea242133 ( 2013-09-06 10:45:26 -0600 )edit

Does it speed up if you dont use try catch?

Moster gravatar imageMoster ( 2013-09-08 09:39:29 -0600 )edit

No, it doesn't help.

a242133 gravatar imagea242133 ( 2013-09-09 14:22:57 -0600 )edit

Would it be possible for you to try the same on c++? If it takes the same time, you wont really be able to speed it up I guess

Moster gravatar imageMoster ( 2013-09-12 13:23:42 -0600 )edit

Never used c++, so it gonna take a while

a242133 gravatar imagea242133 ( 2013-09-13 02:39:09 -0600 )edit

What might bring a little speed is to directly call new VideoCapture(0) and then only check once webcam.opened(), but maybe only a little bit.

Moster gravatar imageMoster ( 2013-09-13 02:51:11 -0600 )edit
1

Well, camera initialization does take a while, even in pure C/C++.

Daniel Baggio gravatar imageDaniel Baggio ( 2014-01-18 21:56:10 -0600 )edit

(sorry, initially posted as answer, now posting as comment, I'm a little new to this site)

Can you confirm which part of the code is slow? Is it opening the camera, or reading frames?

I'm asking because I have discovered that opening a connection to an IP camera in Java is horribly slow (have to wait a whole minute), but getting frames from the camera afterwards runs at reasonable speed.

arp gravatar imagearp ( 2014-09-29 12:13:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-09-28 02:45:00 -0600

rocksean30 gravatar image

updated 2014-09-28 02:46:04 -0600

Try lower resolution

VideoCapture capture = new VideoCapture(0);
int WIDTH = 320;
int HEIGHT = 240;
if (capture.isOpened())
{
    // to get the actual width of the camera
    System.out.print("Width: " + capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
    // to get the actual height of the camera
    System.out.println(", Height: " + capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));

    boolean wset = capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, WIDTH);
    boolean hset = capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);
    if (!hset || !wset)
    {
        System.out.println("Width Changed: "+wset);
        System.out.println("Height Changed: "+hset);

        // to get the actual width of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
        // to get the actual height of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));
    }
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-05 13:54:56 -0600

Seen: 2,025 times

Last updated: Sep 29 '14