All Projects → techyian → Mmalsharp

techyian / Mmalsharp

Licence: mit
C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera.

Projects that are alternatives of or similar to Mmalsharp

Raspberryio
The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#
Stars: ✭ 593 (+290.13%)
Mutual labels:  raspberry-pi, camera, raspberry-pi-camera, dotnetcore, mono
Little Backup Box
Software that turns a single-board computer into a versatile and pocketable backup appliance
Stars: ✭ 278 (+82.89%)
Mutual labels:  raspberry-pi, camera, photography
Balena Cam
Network Camera with Raspberry Pi and WebRTC. Tutorial:
Stars: ✭ 120 (-21.05%)
Mutual labels:  raspberry-pi, camera, raspberry-pi-camera
Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (+562.5%)
Mutual labels:  raspberry-pi, dotnetcore, mono
Picam
Elixir library used to capture MJPEG video on a Raspberry Pi using the camera module.
Stars: ✭ 96 (-36.84%)
Mutual labels:  raspberry-pi, camera
Picamera
A pure Python interface to the Raspberry Pi camera module
Stars: ✭ 1,339 (+780.92%)
Mutual labels:  raspberry-pi, raspberry-pi-camera
Sltk
An OpenCV-based structured light processing toolkit.
Stars: ✭ 151 (-0.66%)
Mutual labels:  raspberry-pi, camera
Cam2web
Streaming camera to web as MJPEG stream or individual JPEG snapshots. Providing embedded web UI for watching camera directly from a web browser.
Stars: ✭ 117 (-23.03%)
Mutual labels:  raspberry-pi, camera
Auto car
基于深度学习的自动避障智能小车
Stars: ✭ 74 (-51.32%)
Mutual labels:  raspberry-pi, raspberry-pi-camera
Raft.net
Implementation of RAFT distributed consensus algorithm among TCP Peers on .NET / .NETStandard / .NETCore / dotnet
Stars: ✭ 112 (-26.32%)
Mutual labels:  dotnetcore, netcore
Raspilive
📷 Stream video from the Raspberry Pi Camera Module to the web
Stars: ✭ 120 (-21.05%)
Mutual labels:  raspberry-pi, raspberry-pi-camera
Module Shop Mini Program
一个基于 .NET Core构建的简单、跨平台、模块化的商城系统
Stars: ✭ 89 (-41.45%)
Mutual labels:  dotnetcore, netcore
Damselfly
Damselfly is a server-based Digital Asset Management system for photographs. The goal of Damselfly is to index an extremely large collection of images, and allow easy search and retrieval of those images, using metadata such as the IPTC keyword tags, as well as the folder and file names.
Stars: ✭ 86 (-43.42%)
Mutual labels:  photography, exif
Cameracontrollerapi
The CameraControlerApi is an attempt to control a DSLR via REST functionality.
Stars: ✭ 110 (-27.63%)
Mutual labels:  camera, photography
Rpicam
Raspberry PI Surveillance Automation
Stars: ✭ 77 (-49.34%)
Mutual labels:  raspberry-pi, camera
Zipstorer
A Pure C# Class to Store Files in Zip
Stars: ✭ 139 (-8.55%)
Mutual labels:  netcore, mono
Teslalogger
Stars: ✭ 131 (-13.82%)
Mutual labels:  raspberry-pi, mono
C Is For Camera
A 35mm camera, based on the Canonet G-III QL17 rangefinder, simulated in Python.
Stars: ✭ 138 (-9.21%)
Mutual labels:  camera, photography
Nextlevel
NextLevel was initally a weekend project that has now grown into a open community of camera platform enthusists. The software provides foundational components for managing media recording, camera interface customization, gestural interaction customization, and image streaming on iOS. The same capabilities can also be found in apps such as Snapchat, Instagram, and Vine.
Stars: ✭ 1,940 (+1176.32%)
Mutual labels:  camera, photography
Homekitcam
A project to make a Raspberry Pi driven, HomeKit Enabled camera.
Stars: ✭ 69 (-54.61%)
Mutual labels:  raspberry-pi, raspberry-pi-camera

MMALSharp - C# wrapper to Broadcom's MMAL and API to the Raspberry Pi camera

Build status Join the chat at https://gitter.im/MMALSharp/Lobby

If you like this project, please support it by giving it a star! GitHub stars

MMALSharp is a C# wrapper around the MMAL library designed by Broadcom. It exposes many elements of MMAL and in addition provides an easy to use, asynchronous API to the Raspberry Pi Camera Module. The library targets .NET Standard 2.0 and is compatible with Mono 5.4/.NET Core 2.0 or greater platforms.

Installation

MMALSharp NuGet package: NuGet version

PM> Install-Package MMALSharp

MMALSharp.FFmpeg NuGet package: NuGet version

PM> Install-Package MMALSharp.FFmpeg

Pre-release builds can be found on MyGet:

Logging configuration

For v0.6, MMALSharp now uses Microsoft.Extensions.Logging.Abstractions to provide package agnostic logging. If you want to enable logging, you must provide the ILoggerFactory instance your client application is using. For .NET Core applications, this will typically be done during dependency injection configuration. For more information, please see here.

Below is an example on how to configure NLog in a .NET Core 3.0+ console app. Note: the ILoggerFactory instance should be set before carrying out any MMALSharp specific operations:

var loggerFactory = LoggerFactory.Create(builder =>
{
	builder                
	.ClearProviders()
	.SetMinimumLevel(LogLevel.Trace)                
	.AddNLog("NLog.config");
});

MMALLog.LoggerFactory = loggerFactory;

Also see here for full NLog integration instructions.

Basic Examples

Take a JPEG image using YUV420 encoding:

public void TakePicture()
{
    // Singleton initialized lazily. Reference once in your application.
    MMALCamera cam = MMALCamera.Instance;

    using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", "jpg"))        
    {            
        await cam.TakePicture(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420);
    }
    
    // Cleanup disposes all unmanaged resources and unloads Broadcom library. To be called when no more processing is to be done
    // on the camera.
    cam.Cleanup();
}

Take a H.264 video using YUV420 encoding at 30 fps:

public void TakeVideo()
{
    // Singleton initialized lazily. Reference once in your application.
    MMALCamera cam = MMALCamera.Instance;

    using (var vidCaptureHandler = new VideoStreamCaptureHandler("/home/pi/videos/", "avi"))        
    {    
        var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
                
        await cam.TakeVideo(vidCaptureHandler, cts.Token);
    }   

    // Cleanup disposes all unmanaged resources and unloads Broadcom library. To be called when no more processing is to be done
    // on the camera.
    cam.Cleanup();
}

Basic Configuration

Below are common global configuration properties which you may want to edit:

MMALCameraConfig.Resolution = new Resolution(640, 480); // Set to 640 x 480. Default is 1280 x 720.
MMALCameraConfig.Framerate = new MMAL_RATIONAL_T(20, 1); // Set to 20fps. Default is 30fps.
MMALCameraConfig.ShutterSpeed = 2000000; // Set to 2s exposure time. Default is 0 (auto).
MMALCameraConfig.ISO = 400; // Set ISO to 400. Default is 0 (auto).

Performance

The performance of MMALSharp is very good due to being a wrapper around the native MMAL library with minimal additional operations being carried out whilst the camera is in use. BenchmarkDotNet reports a mean time of 527.0ms to capture a JPEG still at 640 x 480 resolution following configuration and warmup of the camera, with even faster still capture performance being gained if you capture from the camera's video port instead.

SD Card IO performance - Having a high performance SD card is crucial to get the most out of using this library, especially when saving to multiple FileStreams with the splitter component. You may find when outputting to multiple FileStreams that the SD Card IO is a bottleneck and using a faster storage medium would be beneficial such as a ramdisk mount. On the Raspberry Pi 4, using an external USB 3 Hard Drive would also be a great option for the best performance possible.

Documentation

For full installation instructions for Mono and .NET Core, including configuration and examples - please visit the Wiki.

License

MIT license

Copyright (c) 2016-2020 Ian Auty and contributors.

Raspberry Pi is a trademark of the Raspberry Pi Foundation

Contributors

I want to say a big thank you to those of you who have helped develop MMALSharp over the years, your contributions are most appreciated. In addition, I'd like to say thanks to Dave Jones @waveform80 for your work on picamera which gave me the inspiration to start this project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].