Connexion avec une camera IP

nesrine18 Messages postés 29 Date d'inscription mercredi 24 février 2010 Statut Membre Dernière intervention 15 avril 2010 - 30 mars 2010 à 10:16
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 - 30 mars 2010 à 14:00
bonjour,
je veux communiquer avec une camera IP en utilisant son adresse TP..c'est a dire,récupérer le flux video et l'afficher dans un jLabel..
pouvez vous me guider??en me donnant des liens ou des idées..
merci

8 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
30 mars 2010 à 10:37
Salut,

et l'afficher dans un jLabel


Un JLabel est censé affiché un texte statique, je le vois très mal pour afficher une vidéo !

Regarde plutôt du côté de la bibiothèque JMF qui sera bien plus adapté pour afficher efficacement un flux vidéo.
______________________________________

AVANT de poster votre message, veuillez lire, comprendre, et appliquer notre réglement
0
nesrine18 Messages postés 29 Date d'inscription mercredi 24 février 2010 Statut Membre Dernière intervention 15 avril 2010
30 mars 2010 à 11:04
d'accord..ça sera mieux pour jFrame??
0
nesrine18 Messages postés 29 Date d'inscription mercredi 24 février 2010 Statut Membre Dernière intervention 15 avril 2010
30 mars 2010 à 12:08
alors,
j'ai trouver ça,normalement ça marche,mais je c pas ou est le probleme..
pouvez vous me dire ou est la faute??
merci d'avance
0
nesrine18 Messages postés 29 Date d'inscription mercredi 24 février 2010 Statut Membre Dernière intervention 15 avril 2010
30 mars 2010 à 12:09
import java.net.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;


/**
*
* @author David E. Mireles, Ph.D.
*/
public class AxisCamera extends JPanel implements Runnable {
public boolean useMJPGStream = true;
public String jpgURL="http://your-ip-here/axis-cgi/jpg/image.cgi?resolution=352x240";
public String mjpgURL="http://your-ip-here/axis-cgi/mjpg/video.cgi?resolution=352x240";
DataInputStream dis;
private Image image=null;
public Dimension imageSize = null;
public boolean connected = false;
private boolean initCompleted = false;
HttpURLConnection huc=null;
Component parent;

/** Creates a new instance of AxisCamera */
public AxisCamera (Component parent_) {
parent = parent_;
}

public void connect(){
try{
URL u = new URL(useMJPGStream?mjpgURL:jpgURL);
huc = (HttpURLConnection) u.openConnection();







//System.out.println(huc.getContentType());
InputStream is = huc.getInputStream();
connected = true;
BufferedInputStream bis = new BufferedInputStream(is);
dis= new DataInputStream(bis);
if (!initCompleted) initDisplay();
}catch(IOException e){ //incase no connection exists wait and try again, instead of printing the error
try{
huc.disconnect();
Thread.sleep(60);
}catch(InterruptedException ie){huc.disconnect();connect();}
connect();
}catch(Exception e){;}
}

public void initDisplay(){ //setup the display
if (useMJPGStream)readMJPGStream();
else {readJPG();disconnect();}
imageSize = new Dimension(image.getWidth(this), image.getHeight(this));
setPreferredSize(imageSize);
parent.setSize(imageSize);
parent.validate();
initCompleted = true;
}

public void disconnect(){
try{
if(connected){
dis.close();
connected = false;
}
}catch(Exception e){;}
}

public void paint(Graphics g) { //used to set the image on the panel
if (image != null)
g.drawImage(image, 0, 0, this);
}

public void readStream(){ //the basic method to continuously read the stream
try{
if (useMJPGStream){
while(true){
readMJPGStream();
parent.repaint();
}
}
else{
while(true){
connect();
readJPG();
parent.repaint();
disconnect();

}
}

}catch(Exception e){;}
}


public void readMJPGStream(){ //preprocess the mjpg stream to remove the mjpg encapsulation
readLine(3,dis); //discard the first 3 lines
readJPG();
readLine(2,dis); //discard the last two lines
}

public void readJPG(){ //read the embedded jpeg image
try{
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis);
image = decoder.decodeAsBufferedImage();
}catch(Exception e){e.printStackTrace();disconnect();}
}

public void readLine(int n, DataInputStream dis){ //used to strip out the header lines
for (int i=0; i<n;i++){
readLine(dis);
}
}
public void readLine(DataInputStream dis){
try{
boolean end = false;
String lineEnd = "\n"; //assumes that the end of the line is marked with this
byte[] lineEndBytes = lineEnd.getBytes();
byte[] byteBuf = new byte[lineEndBytes.length];

while(!end){
dis.read(byteBuf,0,lineEndBytes.length);
String t = new String(byteBuf);
//System.out.print(t); //uncomment if you want to see what the lines actually look like
if(t.equals(lineEnd)) end=true;
}
}catch(Exception e){e.printStackTrace();}


}
public void run() {
connect();
readStream();
}


public static void main(String[] args) {
JFrame jframe = new JFrame();
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AxisCamera axPanel = new AxisCamera(jframe);
new Thread(axPanel).start();
jframe.getContentPane().add(axPanel);
jframe.pack();
jframe.show();
}


}
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
nesrine18 Messages postés 29 Date d'inscription mercredi 24 février 2010 Statut Membre Dernière intervention 15 avril 2010
30 mars 2010 à 12:11
quand je fais l'execution,y'a pas d'erreur mais je vois pas l'image sur mon jFrame
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
30 mars 2010 à 12:19
Salut,

catch(Exception e){;} 


Forcément, si tu n'affiches pas les erreurs lorsqu'il y en a, il risque pas afficher d'erreur...
______________________________________

AVANT de poster votre message, veuillez lire, comprendre, et appliquer notre réglement
0
nesrine18 Messages postés 29 Date d'inscription mercredi 24 février 2010 Statut Membre Dernière intervention 15 avril 2010
30 mars 2010 à 12:24
merci mais j'ai pas compris..est ce que je dois l'enlever??
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
30 mars 2010 à 14:00
Salut,

Non faut pas l'enlever, il faut le rendre plus verbeux : un catch permet de traîter une erreur. Si tu ne fais rien dans le bloc catch, tu ne vois absolument rien (pas de trace dans la console par exemple).

Donc au strict minimum, affiche au moins la stacktrace de l'erreur : remplace tout les blocs catch qui ne font rien par :
catch(Exception e){e.printStackTrace();}


Et là tu devrais voir pourquoi tu ne vois pas d'image dans ton JFrame...
______________________________________

AVANT de poster votre message, veuillez lire, comprendre, et appliquer notre réglement
0
Rejoignez-nous