Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2532 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  caméra Axis

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

caméra Axis

n°1984283
nesrine18
étudiante
Posté le 15-04-2010 à 12:23:04  profilanswer
 

bonjour,
c'est mon code qui sert à récupérer le flux video d'une camera Axis et l'afficher dans un jFrame....
pouvez vous m'aider maintenant pour faire l'enregistrement???   :(  
merci

 

Code :
  1. import java.awt.Component;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5. import java.io.BufferedInputStream;
  6. import java.io.ByteArrayInputStream;
  7. import java.io.DataInputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.net.HttpURLConnection;
  11. import java.net.URL;
  12. import javax.swing.JFrame;
  13. import javax.swing.JPanel;
  14. import com.sun.image.codec.jpeg.JPEGCodec;
  15. import com.sun.image.codec.jpeg.JPEGImageDecoder;
  16. public class NewClass extends JPanel implements Runnable {
  17. public boolean useMJPGStream = true;
  18. public String mjpgURL = http192.168.1.218axis-cgimjpgvideo.cgi;
  19. private String camLogin = root;
  20. private String camPwd = waycon;
  21. DataInputStream dis;
  22. private Image image = null;
  23. public Dimension imageSize = null;
  24. public boolean connected = false;
  25. private boolean initCompleted = false;
  26. HttpURLConnection huc = null;
  27. Component parent;
  28. Creates a new instance of AxisCamera
  29. public NewClass(Component parent_) {
  30. parent = parent_;
  31. }
  32. public void connect() {
  33. System.out.println(NewClass.connect());
  34. try {
  35. URL u = new URL(mjpgURL);
  36. huc = (HttpURLConnection) u.openConnection();
  37. String userPassword = camLogin +  + camPwd;
  38. String encoding = new sun.misc.BASE64Encoder().encode(userPassword
  39. .getBytes());
  40. huc.setRequestProperty(Authorization, Basic  + encoding);
  41. InputStream is = huc.getInputStream();
  42. connected = true;
  43. BufferedInputStream bis = new BufferedInputStream(is);
  44. dis = new DataInputStream(bis);
  45. if (!initCompleted)
  46. initDisplay();
  47. } catch (IOException e) {
  48. e.printStackTrace();
  49. try {
  50. huc.disconnect();
  51. Thread.sleep(60);
  52. } catch (InterruptedException ie) {
  53. ie.printStackTrace();
  54. huc.disconnect();
  55. connect();
  56. }
  57. connect();
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. ;
  61. }
  62. }
  63. public void initDisplay() {  setup the display
  64. readMJPGStream();
  65. imageSize = new Dimension(image.getWidth(this),
  66. image.getHeight(this)); setPreferredSize(imageSize);
  67. parent.setSize(imageSize); parent.validate(); initCompleted = true;
  68. }
  69. public void disconnect() {
  70. try {
  71. if (connected) {
  72. dis.close();
  73. connected = false;
  74. }
  75. } catch (Exception e) {
  76. ;
  77. }
  78. }
  79. public void paint(Graphics g) {  used to set the image on the panel
  80. if (image != null)
  81. g.drawImage(image, 0, 0, this);
  82. }
  83. public void readStream() {  the basic method to continuously read the
  84. stream
  85. }
  86. public void readMJPGStream() {
  87. readLine(0, dis);
  88. }
  89. public void readJPG() {
  90. System.out.println(NewClass.readJPG());
  91. try {
  92. JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis);
  93. image = decoder.decodeAsBufferedImage();
  94. } catch (Exception e) {
  95. e.printStackTrace();
  96. disconnect();
  97. }
  98. }
  99. public void readLine(int n, DataInputStream dis) {
  100. readLine(dis);
  101. }
  102. public void readLine(DataInputStream dis) {
  103. int index = 1;
  104. try {
  105. do {
  106. int length = 0;
  107. int r;
  108. for (int i = 0; i  ((index == 1)  4  5); i++) {
  109. String line = dis.readLine();
  110. System.out.println( index +   $$$$  + line);
  111. String string = Content-Length;
  112. if (line.contains(string)) {
  113. String trim = line.substring(string.length()).trim();
  114. System.out.println(trim);
  115. length = Integer.parseInt(trim);
  116. }
  117. }
  118. byte[] aux = new byte[1000000];
  119. int total = 0;
  120. while (total  length) {
  121. r = dis.read(aux, total, length - total);
  122. total = total + r;
  123. }
  124. System.out.println(r =  + total);
  125. JPEGImageDecoder decoder = JPEGCodec
  126. .createJPEGDecoder(new ByteArrayInputStream(aux, 0,
  127. length));
  128. image = decoder.decodeAsBufferedImage();
  129. imageSize = new Dimension(image.getWidth(this), image
  130. .getHeight(this));
  131. setPreferredSize(imageSize);
  132. parent.setSize(imageSize);
  133. parent.repaint();
  134. index ++;
  135. }
  136. while (true);
  137. } catch (Exception e) {
  138. System.out.println(error at  + index);
  139. e.printStackTrace();
  140. }
  141. }
  142. public void run() {
  143. connect();
  144. readStream();
  145. }
  146. public static void main(String[] args) {
  147. JFrame jframe = new JFrame();
  148. jframe.setBounds(100, 100, 500, 500);
  149. jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  150. NewClass axPanel = new NewClass(jframe);
  151. new Thread(axPanel).start();
  152. jframe.getContentPane().add(axPanel);
  153. jframe.pack();
  154. jframe.setVisible(true);
  155. }
  156. }

mood
Publicité
Posté le 15-04-2010 à 12:23:04  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  caméra Axis

 

Sujets relatifs
enregistrer le flux video d'une camera Axis[c++ / qt] freefly camera problème souris
Déplacement caméra sur les 3 axes avec Sandy3DWeb Service Axis, inversion paramètres methode
Contrôle caméra sous labview...stopper la camera sous vtk
Script shell pour récupèrer des images sur une camera[WS Axis] Problème de sérialisation
affichage flux cameraFlash & camera ip Axis
Plus de sujets relatifs à : caméra Axis


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR