Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java Advanced Imaging - How i can capture 30 frame per second

  Asked By: Hondo    Date: Jul 28    Category: Java    Views: 1469
  

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);
}
}

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Kyle Fox     Answered On: Jul 28

You should be looking into video streaming. Opening an http connection for
every single frame  is very time consuming.
You can fine plenty of examples on streaming on the internet. Just google:
"java video streaming"

 
Answer #2    Answered By: Leonard Pierce     Answered On: Jul 28

What I want do to is :

1. Input : capture  MotionJEPG or Video Stream from 2 IP camera  
2. Operation :

2.1 . I need to change the picture by deformation effect . some effect like this ( http://en.nicoptere.net/?p=292 ) .

2.2 . Stitching two picture from camera together plus in point of stitching two image  need to Behind together .
3. Output : display  final picture in side  applet frame  .


Now what I did :

I wrote code  which able to capture MotionJEPG from two IP camera and Stitching together and display it ,

But two problem I am having :
1. I am not able to deformation effect ( Task 2.1 ) and ( task 2.2 ) I could do just stitching part but i could not do blending pictures in join point .
2. My code work but very slowly almost 1 frame per second . which is not good  for my purpose .

Refer to this link you can see my code and other people idea :
forums.sun.com/thread.jspa

Some people in this link telling me you problem is about network  which i think is not . how ever i search more and I found other code which done with other guy with JMF .
and capture and display almost 15 to 20 frame per second : This code you can find in this link :
72.5.124.102/thread.jspa


Ok I have to modify code and test if i can add other camera to this code and test it . But here is my fist question :
1 . why the second code is working much more faster than mine It is because of JMF frame work or something else which i am not understanding ?
2. How i can add deformation effect to this code ?
3. How I can add blending operation in point of join image ?
4. How to make this code work more faster , I need to see live picture from both camera ?

 




Tagged: