Hi I am trying to get some images (10 frames per second) from a webcam so that later I can detect the moving objects.. My code is the following but I dont know how to change it so that I can get 10 frames per second.Any help?

package video;

import java.io.*;
import java.net.*;

public class Main {

public static void main(String[] args) {
try {
String url ="http://studiocam1.disp.duke.edu/view/index.shtml";

HttpURLConnection con = (HttpURLConnection)((new URL(url).openConnection()));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("c:\\image.jpg"));
con.setDoInput(true);
con.setDoOutput(false);
con.setRequestMethod("GET");
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
int bt = 0;
byte[] buffer = new byte[4096];
while ((bt = in.read(buffer, 0, 4096)) > -1) {
out.write(buffer, 0, bt);
}
in.close();
out.close();
System.out.println("Image saved");
} catch(Exception e) {
e.printStackTrace();
}}}

Recommended Answers

All 3 Replies

Well, I would think it unlikely that you are going to retrieve 10 images per second from an HTTP connection, but you could use a Timer to repeat the HTTP GET requests on the connection on a set timing interval.

Thank you I will try!!

Actually I don't get it..Any suggestions on how it is going to happen. I read about Timers but I
don't understand how I am going to attach that to my code.Plz my knowledge is very poor in the subject.Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.