Skip to main content

How i can capture 30 frame per second and display in applet .

2 replies [Last post]
jspecialist
Offline
Joined: 2008-03-28

Hello ,

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("http://192.168.11.98/cgi-bin/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("http://192.168.11.99/cgi-bin/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);
}
}

Please let me know how i can speed it up to 30 fps .

Thanks
Ali

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Bob Deen

I don't know if 30fps even 15 is achievable. But calling setRGB() per
pixel is horribly, horribly slow. Instead, fill up a primitive-type
array, set that into a DataBuffer (or perhaps better, create a
DataBuffer and pull the array from it), and create a BufferedImage from
that. There may be a few intermediate steps there but that's the basic
idea.

Good luck...

-Bob

jai-interest@javadesktop.org wrote:
> Hello ,
>
> 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("http://192.168.11.98/cgi-bin/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("http://192.168.11.99/cgi-bin/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);
> }
> }
>
>
>
>
> Please let me know how i can speed it up to 30 fps .
>
>
> Thanks
> Ali
> [Message sent by forum member 'jspecialist']
>
> http://forums.java.net/jive/thread.jspa?messageID=469363
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Alessandro Ferrucci

One suggestion is to look at IPP's JPEG decoder, It is very very fast.

On Tue, May 11, 2010 at 11:41 AM, Bob Deen wrote:

> I don't know if 30fps even 15 is achievable. But calling setRGB() per
> pixel is horribly, horribly slow. Instead, fill up a primitive-type array,
> set that into a DataBuffer (or perhaps better, create a DataBuffer and pull
> the array from it), and create a BufferedImage from that. There may be a
> few intermediate steps there but that's the basic idea.
>
> Good luck...
>
> -Bob
>
>
>
> jai-interest@javadesktop.org wrote:
>
>> Hello ,
>>
>> 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("
>> http://192.168.11.98/cgi-bin/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("
>> http://192.168.11.99/cgi-bin/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);
>> }
>> }
>>
>>
>>
>>
>> Please let me know how i can speed it up to 30 fps .
>>
>>
>> Thanks
>> Ali
>> [Message sent by forum member 'jspecialist']
>>
>> http://forums.java.net/jive/thread.jspa?messageID=469363
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

--
Signed,
Alessandro Ferrucci
[att1.html]