I want to capture MotionJPG from 2 IP camera and joining together and display it
on applet .
I made this software , but I can capture & display maximum 2 frame per second
which is not good enough for my propose .I want to display at least 15 frame per
second and best is to reach this number to 30 frame per second . I connect both
camera to my private network ( LAN ) , So I don`t think i can do anything on
network side to speed up more . It has to do something with program side .
Here is my code :
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.net.URLConnection;
import javax.imageio.ImageIO;
import javax.swing.JApplet;
public class Main extends JApplet {
private BufferedImage camImg1 = null, camImg2 = null, JoinImag = null;
private URL imageURL1, imageURL2;
private URLConnection urlConnection1, urlConnection2;
private boolean Active = false;
class MyThread extends Thread {
public void run() {
if (Thread.currentThread().getName().equals("LoadCamNo1")) {
while (true) {
try {
String camera1IP = getParameter("camera1IP");
if (camera1IP == null) {
imageURL1 = new
URL("192.168.11.98/.../image.jpg?&textdisplay=disable");
} else {
imageURL1 = new URL(camera1IP);
}
urlConnection1 = imageURL1.openConnection();
urlConnection1.setDefaultUseCaches(false);
urlConnection1.setRequestProperty("Cache-Control",
"no-store,max-age=0,no-cache");
urlConnection1.setRequestProperty("Expires", "0");
urlConnection1.setRequestProperty("Pragma", "no-cache");
camImg1 = ImageIO.read(imageURL1);
} catch (Exception e) {
System.err.println("Problem in LoadCamNo1 thread : " +
e.toString());
}
try {
sleep(80L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (Thread.currentThread().getName().equals("LoadCamNo2")) {
while (true) {
try {
String camera2IP = getParameter("camera2IP");
if (camera2IP == null) {
imageURL2 = new
URL("192.168.11.99/.../image.jpg?&textdisplay=disable");
} else {
imageURL2 = new URL(camera2IP);
}
urlConnection2 = imageURL2.openConnection();
urlConnection2.setDefaultUseCaches(false);
urlConnection2.setRequestProperty("Cache-Control",
"no-store,max-age=0,no-cache");
urlConnection2.setRequestProperty("Expires", "0");
urlConnection2.setRequestProperty("Pragma", "no-cache");
camImg2 = ImageIO.read(imageURL2);
} catch (Exception e) {
System.err.println("Problem in LoadCamNo2 thread : " +
e.toString());
}
try {
sleep(80L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (Thread.currentThread().getName().equals("JoinImage")) {
while (true) {
if (camImg1 != null && camImg2 != null) {
try {
int height = (camImg1.getHeight() >
camImg2.getHeight()) ? camImg1.getHeight() : camImg2.getHeight();
int width = camImg1.getWidth() + camImg2.getWidth();
int width1 = camImg1.getWidth();
int height1 = camImg1.getHeight();
int width2 = camImg2.getWidth();
int height2 = camImg2.getHeight();
BufferedImage dest = new BufferedImage(width,
height, BufferedImage.TYPE_INT_RGB);
for (int i = 0; i < width1; i++) {
for (int j = 0; j < height1; j++) {
dest.setRGB(i, j, camImg1.getRGB(i, j));
}
}
for (int i = 0; i < width2; i++) {
for (int j = 0; j < height2; j++) {
dest.setRGB(i + width1, j, camImg2.getRGB(i,
j));
}
}
JoinImag = dest;
if (JoinImag != null) {
Active = true;
}
sleep(80L);
} catch (Exception e) {
System.err.println("Problem in JoinImage thread : "
+ e);
}
}
}
}
}
MyThread(String n) {
super(n);
}
}
public void init() {
MyThread LoadCamNo1 = new MyThread("LoadCamNo1");
MyThread LoadCamNo2 = new MyThread("LoadCamNo2");
MyThread JoinImage = new MyThread("JoinImage");
LoadCamNo1.start();
LoadCamNo2.start();
JoinImage.start();
}
public void paint(Graphics g) {
if (!Active) {
g.drawString("www.AliJamali.com", 20, 20);
g.drawString("© Ali Jamali", 20, 40);
g.drawString("Loading ........ ", 210, 150);
}
g.drawImage(JoinImag, 0, 0, this);
repaint();
}
public void update(Graphics g) {
paint(g);
}
}