locked
How to publish webcam?

    Întrebare

  • Hello.

    I'd like to publish the webcam. Here is my code following the tutorials. Now I'm using webcam server using "webcam-server" with Logitech webcam. (I'm wondering whether they have some restriction to implement general webcam server)

    When I run this code, I got the error at "camera.getImage()".

    Could you give me the spec of this object (CameraDriver) and idea how to publish the image after capture and to publish the video stream?

    Thank you in advance.
    Seungweon.

    ------ error code message ------
    Unhandled Exception: System.Net.WebException: The server committed a protocol vi
    olation. Section=ResponseStatusLine
    at System.Net.WebClient.OpenRead(Uri address)
    at System.Net.WebClient.OpenRead(String address)
    at MSRSense.Sensors.WebCamDriver.getImage()
    at CameraPublisher.Program.Main(String[] args) in C:\Documents and Settings\S
    eungWeon Park\My Documents\Visual Studio 2005\Projects\CameraPublisher\CameraPub
    lisher\Program.cs:line 222

    ------a part of source code----
    CameraDriver camera = new WebCamDriver("http://xxx.xxx.xxx.xxx");

    Bitmap img = new Bitmap(320, 240);

    img = camera.getImage();

    string mydocs = Environment.CurrentDirectory.ToString();
    img.Save(mydocs + "\\tmp.jpg");
    Console.WriteLine("Saved Image to" + mydocs);

    byte[] imgByte = camera.ConvertBitmapToByteArray(img);

    // generic remove sensor try-catch block
    try
    {
    string removeSensorResult = mySensorMap.RemoveSensor(sensor.publisherName, mySenseWebPassword, sensor.sensorName);
    Console.WriteLine("remove sensor result: " + removeSensorResult);
    }
    catch (Exception e) { Console.WriteLine("Problem with web service: " + e.Message); }

    // generic register try-catch block
    xmlDesc = ObjectSerializer.SerializeObject(sensor);
    try
    {
    wsResponse = mySensorMap.RegisterSensor(sensor.publisherName, mySenseWebPassword, xmlDesc);
    Console.WriteLine("Register " + sensor.sensorName + " response: " + wsResponse);

    wsResponse = mySensorMap.SendBinaryData(sensorPublisherName, mySenseWebPassword, sensorName, DateTime.Now, imgByte);
    Console.WriteLine("SendBinaryData " + sensor.sensorName + " response: " + wsResponse);

    //System.Threading.Thread.Sleep(3000);

    }
    catch (Exception e) { Console.WriteLine("Problem connecting to web service: " + e.Message); }

    31 mai 2007 18:02

Toate mesajele

  • I would first make sure the camera provides only the image as a jpeg (and not a video or a webpage with the image) when one points a browser to "http://xxx.xxx.xxx.xxx" (For instance, the URL may have to modified to something like "http://xxx.xxx.xxx.xxx/yyy.jpg" - depends on your camera.)

     

    More detailed spec of the camera driver will be released soon but the part of source code most relevant to your error string (from the WebCamDriver object) is:

     

    Bitmap webcamImg = new Bitmap(Image.FromStream(webclient.OpenRead(url))); //fetch the image from the camera image URL

     

    where webclient is an instantiation of System.Net.WebClient()

     

    Also, Bitmap img = new Bitmap(320, 240); is unnecessary as camera.GetImage creates a new Bitmap object.

     

    Jie (on behalf of Aman Kansal)
    13 iunie 2007 05:14