Use a webcam plugged in a Raspberry pi with Mono in C# using RaspberryCam

from http://www.raspberry-sharp.org/


RaspberryCam is a Mono/.NET assembly providing access to cameras plugged in your Raspberry Pi.
This program is based on v4l API and some fswebcam source headers.
With RapberryCam, you can take pictures and videos from a webcam pluged in your Raspberry Pi.
For the moment, the video stream is not a MPEG stream, but just a succession of compressed frames.
Or you can just install the NuGet RaspberryCam in your project. (cf. https://nuget.org/packages/RaspberryCam)
In a future version, a real MPEG format should be implemented.
Before your first usage
Just copy RaspberryCam.so into /Lib
Or :
Copy C sources files on your Rapsberry Pi and type:
$sudo make
$sudo make install
Try it
Run ServerExample on your Rapsberry Pi
mono RaspberryCam.ServerExample.exe
And run RaspberryCam.VideoViewer.exe on your PC
Take a simple picture from C# code:
var cameras = Cameras.DeclareDevice()  
  .Named("Camera 1")
  .WithDevicePath("/dev/video0")  
  .Memorize();

cameras.Get("Camera 1").SavePicture(new PictureSize(640, 480), "Test1.jpg", 20);

// Or

cameras.Default.SavePicture(new PictureSize(640, 480), "Test2.jpg", 20);

// Best practice: cameras should be a single instance in your program  
Host a video and pictures server in your application
var videoServer = new TcpVideoServer(8080, cameras);  
Console.WriteLine("Server strating ...");  
videoServer.Start();  
Console.WriteLine("Server strated.");  
Download pictures from your Raspberry Pi
var videoClient = new TcpVideoClient(serverHostIp, serverPort);  
videoClient.StartVideoStreaming(new PictureSize(imageWidth/2, imageHeight/2)); //Open hardware  
var data = videoClient.GetVideoFrame(compressionRate); //data contains a simple jpeg frame  
videoClient.StopVideoStreaming(); //Close Hardware


留言

熱門文章