Skip to main content

Meadow.Foundation.Sensors.Camera.Vc0706

Vc0706
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Camera.Vc0706
Vc0706 camera;

//Uses SimpleJpegDecoder package for jpeg decoding
public MeadowApp()
{
Console.WriteLine("Initialize hardware...");

camera = new Vc0706(Device, Device.SerialPortNames.Com4, 38400);

camera.SetImageSize(Vc0706.ImageSize._320x240);
Console.WriteLine($"Image size is {camera.GetImageSize()}");

camera.TakePicture();

uint frameLen = camera.GetFrameLength();
Console.WriteLine($"Frame length: {frameLen}");

byte bytesToRead;
byte[] jpg;

var decoder = new JpegDecoder();

using (var stream = new MemoryStream())
{
Console.WriteLine($"Decode jpeg - this operation may take serveral seconds");

while (frameLen > 0)
{
bytesToRead = (byte)Math.Min(32, frameLen);

var buffer = camera.ReadPicture(bytesToRead);

stream.Write(buffer, 0, bytesToRead);
frameLen -= bytesToRead;
}
jpg = decoder.DecodeJpeg(stream.ToArray());
}

Console.WriteLine($"Jpeg data length: {jpg.Length}");

Console.WriteLine($"Jpeg decoded is {decoder.ImageSize} bytes");
Console.WriteLine($"Width {decoder.Width}");
Console.WriteLine($"Height {decoder.Height}");
Console.WriteLine($"IsColor {decoder.IsColor}");
}

Sample project(s) available on GitHub

|

Code Example

Vc0706 camera;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

camera = new Vc0706(Device, Device.PlatformOS.GetSerialPortName("COM4"), 38400);

return Task.CompletedTask;
}

public override Task Run()
{
if (!camera.SetCaptureResolution(Vc0706.ImageResolution._160x120))
{
Resolver.Log.Info("Set resolution failed");
}

_ = TakePicture();

return Task.CompletedTask;
}

async Task TakePicture()
{
Resolver.Log.Info($"Image size is {camera.GetCaptureResolution()}");

camera.CapturePhoto();

using var jpegStream = await camera.GetPhotoStream();

var jpeg = new JpegImage(jpegStream);
Resolver.Log.Info($"Image decoded - width:{jpeg.Width}, height:{jpeg.Height}");
}

Sample project(s) available on GitHub