Results 1 to 12 of 12
- 03-01-2009, 08:26 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
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();
}
}
- 03-01-2009, 10:10 AM #2
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).
CJSLLast 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.
- 03-01-2009, 05:40 PM #3
Is the camera acting as an HTTP server? Using a raw socket to talk to a Web server is going to be unnecessarily complicated...
- 03-01-2009, 06:34 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
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,
- 03-02-2009, 02:22 AM #5
Look at HTTPUrlConnection and URLConnection.getContent().
- 03-02-2009, 06:03 PM #6
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
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
- 03-02-2009, 10:33 PM #7
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
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............
- 03-03-2009, 02:54 AM #8
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.
- 03-03-2009, 04:56 AM #9
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
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();
}
}
}
- 03-03-2009, 06:25 AM #10
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
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...........................
- 03-03-2009, 07:45 AM #11
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
The logic of this loop is incorrect:
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:while (n >= 0) { n = s.read(buffer, 0, buffer.length); outdata.write(buffer, 0, buffer.length); }
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]); }
- 03-03-2009, 09:22 AM #12
Member
- Join Date
- Mar 2009
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Receive uploaded image / video (byte array) from j2me on jsp.HOW???
By angelicsign in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 06-29-2010, 06:21 PM -
Java code that allows me to make and receive calls, send and receive sms
By nareshbabu@live.in in forum NetworkingReplies: 0Last Post: 12-02-2008, 10:55 AM -
Capturing a video camera and save a snapshot as image
By happyday in forum AWT / SwingReplies: 0Last Post: 11-20-2008, 11:03 AM -
How to display image ?
By Birkoff in forum AWT / SwingReplies: 7Last Post: 06-09-2008, 07:58 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks