Results 1 to 12 of 12
  1. #1
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

    Default How To Receive And Display Image From Network Camera

    hi

    I am trying to get the image from the network camera.
    Below program is able to establish the connection with the camera web server,I can able to receive the response.
    I am not gettin image data in command prompt






    import java.io.*;

    import java.net.*;


    class TCPClient {

    public static void main(String argv[]) throws Exception

    {
    String sentence;
    String modifiedSentence;


    BufferedReader inFromUser =

    new BufferedReader(new InputStreamReader(System.in));




    Socket clientSocket = new Socket("192.168.0.100", 80);



    DataOutputStream outToServer =
    new DataOutputStream(clientSocket.getOutputStream());

    BufferedReader inFromServer =
    new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));



    sentence = inFromUser.readLine();



    outToServer.writeBytes(sentence + '\n');



    modifiedSentence = inFromServer.readLine();



    System.out.println("FROM SERVER: " + modifiedSentence);

    String headerline=null;


    while((headerline = inFromServer.readLine()).length()!=0 ) {



    System.out.println(headerline);
    }





    clientSocket.close();

    }

    }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    I'm definitely not an expert in this subject, but your program is expecting to receive a string... can a camera image be received in a string variable? Everything that I've been able to look up points that you have to use Java Media Framework library (JMF).

    CJSL
    Last edited by CJSLMAN; 03-03-2009 at 05:14 AM. Reason: update with more info
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Is the camera acting as an HTTP server? Using a raw socket to talk to a Web server is going to be unnecessarily complicated...

  4. #4
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

    Default Camera has http built in server

    Instead of string how can I store image

    I am getting server response from can server as

    command in prompt:GET ://192.168.0.100/oneshotimage.jpg

    Response:

    FROM SERVER: HTTP/1.0 200 OK
    Date: Fri, 27 Feb 2009 05:14:50 GMT
    Server: Boa/0.94.14rc18
    Accept-Ranges: bytes
    Connection: close
    ///<jpeg data but i am not getting >> except data m receiving response


    Please help me how to store image data, Where I am committing mistake because if I run CGI command in browser its working.

    Please help me, I have to submit program tomorrow

    Thank you,

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Look at HTTPUrlConnection and URLConnection.getContent().

  6. #6
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

    Default POST PTZ controls

    hi

    Above method u have suggested works to receive image from PTZ camera but in case of POST command how can I send message to camera to control PTZ motion, because I have sent POST commands to the camera, its not working with above program.

    Please suggest me...................


    Thank you

  7. #7
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

    Default when I run Below code I am getting half image

    import java.net.*;
    import javax.imageio.*;
    import java.io.InputStream;

    class TCPClient5 {
    public static void main(String argv[]) throws Exception
    {

    java.io.InputStream s = null;
    java.io.InputStreamReader r = null;
    //java.io.BufferedReader b = null;
    StringBuilder content = new StringBuilder();
    try {
    URLConnection uc = new URL("countryflower.com/Country_Flower_Home_Pic.jpg").openConnection();
    s = uc.getInputStream();
    System.out.println(uc.getContentLength());
    //r = new java.io.InputStreamReader(s);
    //b = new java.io.BufferedReader(r);

    byte[] buffer = new byte[37006];
    int n = 0;
    File f = new File("c:\\Users\\dell\\Desktop\\image\\image.jpg") ;
    DataOutputStream outdata = new DataOutputStream(new FileOutputStream(f));
    while (n >= 0) {
    n = s.read(buffer, 0, buffer.length);

    outdata.write(buffer, 0, buffer.length);
    }
    }
    finally {
    //if (b != null) b.close();
    if (r != null) r.close();
    if (s != null) s.close();
    }

    }

    }
    When I run the above code I am receiving only half image ,
    Please suggest me asap............

  8. #8
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    First, clean up the read loop logic. I suggest

    while(true) {
    n = s.read(...);
    if (n == -1) break;
    if (n == 0) {Thread.sleep(50); continue;}
    outdata.write(...);
    }

    Second, wrap your input stream with BufferedInputStream, and get rid of the dead code.

    Third, you never flush or close outdata. Possibly, the buffer is not being completely written.

  9. #9
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

    Default Please help me with code

    class TCPClient5 {
    public static void main(String argv[]) throws Exception
    {
    java.io.InputStream s = null;
    java.io.InputStreamReader r = null;
    try {
    URLConnection uc = new URL(".countryflower.com/Country_Flower_Home_Pic.jpg").openConnection();
    s = uc.getInputStream();
    System.out.println(uc.getContentLength());

    BufferedInputStream buffer = new BufferedInputStream(s);
    int n = 0;
    String string
    File f = new File("c:\\Users\\dell\\Desktop\\image\\image.jpg") ;
    DataOutputStream outdata = new DataOutputStream(new FileOutputStream(f));

    while(true) {

    n = s.read(buffer ); -- here I am confused could you please tell me the method
    if (n == -1) break;
    if (n == 0) {Thread.sleep(50); continue;}
    outdata.write(...);

    }



    Thank you



    outdata.close();

    }
    finally {
    //if (b != null) b.close();
    if (r != null) r.close();
    if (s != null) s.close();
    }


    }
    }

  10. #10
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

    Default import java.net.*; import java.io.*; import java.awt.*; import javax.imageio.*; cl

    import java.net.*;
    import java.io.*;
    import java.awt.*;
    import javax.imageio.*;
    class TCPClient6 {
    public static void main(String argv[]) throws Exception {

    try{

    // Construct a URL object
    URL url = new URL("//192.168.0.100/oneshotimage.jpg");

    // try and get the content type
    try{
    Object obj = url.getContent();


    File f = new File("c:\\Users\\dell\\Desktop\\image\\image.jpg") ;

    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("image.jpg"));
    oos.writeObject(obj);
    oos.close();



    }
    catch(IOException e){ System.out.println(e); }
    }
    catch(MalformedURLException e){ System.out.println(e); }

    }
    }
    hi

    I have run above code I got error
    Please suggest me...........................

  11. #11
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    The logic of this loop is incorrect:

    Java Code:
    while (n >= 0) {
    n = s.read(buffer, 0, buffer.length); 
    
    outdata.write(buffer, 0, buffer.length);
    }
    You have not accounted for partial reads, which is almost certainly happening for image data. Instead of trying to be aware of the image size, do this:

    Java Code:
    URLConnection uc = new URL("countryflower.com/Country_Flower_Home_Pic.jpg").openConnection();
    s = uc.getInputStream();
    System.out.println(uc.getContentLength());
    //r = new java.io.InputStreamReader(s);
    //b = new java.io.BufferedReader(r);
    
    byte[] buffer = new byte[[b]65536[/b]]; // good arbitary size
    
    File f = new File("c:\\Users\\dell\\Desktop\\image\\image.jpg") ;
    DataOutputStream outdata = new DataOutputStream(new FileOutputStream(f));
    
    while (true) {
      int n = s.read(buffer, 0, buffer.length); 
    
      if(n==-1) 
        break;
    
      outdata.write(buffer, 0, [b]n[/b]);
    }

  12. #12
    sri_reddy523 is offline Member
    Join Date
    Mar 2009
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Receive uploaded image / video (byte array) from j2me on jsp.HOW???
    By angelicsign in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-29-2010, 06:21 PM
  2. Replies: 0
    Last Post: 12-02-2008, 10:55 AM
  3. Replies: 0
    Last Post: 11-20-2008, 11:03 AM
  4. How to display image ?
    By Birkoff in forum AWT / Swing
    Replies: 7
    Last Post: 06-09-2008, 07:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •