Hello,
So, basically I can use a normal USB Camera and use the code below from the SDK 4.1 Documentation to instrument the camera?
GUS, the gadgeteer camera should work with the same code from SDK 4.1? That camera is much smaller than the ones I have.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.System;
class Program
{
static Bitmap LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
static USBH_Webcam cam;
static USBH_Webcam.ImageFormat usedFormat;
static Thread videoThread;
public static void Main()
{
// Subscribe to USBH events.
USBHostController.DeviceConnectedEvent += USBHostController_DeviceConnectedEvent;
Thread.Sleep(Timeout.Infinite);
}
static void USBHostController_DeviceConnectedEvent(USBH_Device device)
{
if (device.TYPE == USBH_DeviceType.Webcamera && cam == null)
{
cam = new USBH_Webcam(device);
cam.Disconnected += cam_Disconnected;
// get supported formats
USBH_Webcam.ImageFormat[] formats = cam.GetSupportedFormats();
// use the first format
if (formats.Length > 0)
{
usedFormat = formats[0];
// run a thread to display the video
videoThread = new Thread(VideoThread);
videoThread.Start();
}
}
}
public static void VideoThread()
{
try
{
cam.StartStreaming(usedFormat);
LCD.Clear();
while (true)
{
// is there a new image?
if (cam.IsNewImageReady())
{
// center the image
cam.DrawImage(LCD, (LCD.Width - cam.CurrentFormat.Width) / 2, (LCD.Height - cam.CurrentFormat.Height) / 2, cam.CurrentFormat.Width, cam.CurrentFormat.Height);
LCD.Flush();
}
}
}
catch (Exception e)
{
Debug.Print("Exception: " + e.Message);
}
}
static void cam_Disconnected(USBH_Webcam sender, USBH_WebcamEventArgs args)
{
videoThread.Abort();
cam.StopStreaming();
cam = null;
}
}
Thanks, Herlander