Comments (5)
A related idea: it may also be interesting to look at generalizing the cell-level processing into a delegate approach. If the call overhead isn't too terrible, changes like the convolution code in PR #175 could perhaps just turn into an implementation of that. Although I'll be surprised if the framework doesn't add a lot of overhead. Even so, a cell-level delegate might be interesting, too, even if it's faster to hard-code it internally as the PR does.
from mmalsharp.
Possibly related to #82
from mmalsharp.
I'm playing around with this and a per-pixel delegate is about as fast as the convolution processing -- delegate invocation overhead doesn't seem to be a big problem. We're about to take a vacation but I should have something on this around the middle of next week.
However, I'm realizing the CloneToRawBitmap method I wrote for convolution also results in a BGR buffer, so Bitmap's channel-mixup works in the other direction as well. This means we have two scenarios.
Scenario 1 is when the original context is raw. The data is RGB and we must do the red/blue swap before saving.
Scenario 2 is when the original context is encoded. We need raw data, but Bitmap is returning that as BGR -- and to re-encode, it needs to stay BGR. So instead of swapping twice, we can use an array index offset to point to the red and blue channels and process them in place.
A bit of a headache.
from mmalsharp.
Here's a vignette delegate (linear, so a bit crude), runs in about 500 ms on a 1296 x 972. (v1 mode4) image:
context.Apply(new CustomPixelProcessor((r, g, b, x, y, w, h) =>
{
var xc = w / 2;
var yc = h / 2;
var point = Math.Sqrt(Math.Pow(x - xc, 2) + Math.Pow(y - yc, 2));
var center = Math.Sqrt(Math.Pow(xc, 2) + Math.Pow(yc, 2));
var dist = 1.0f - (point / center);
return ((int)(r * dist), (int)(g * dist), (int)(b * dist));
}));
And a grayscale delegate runs in about 340 ms:
context.Apply(new CustomPixelProcessor((r, g, b, x, y) =>
{
var i = (int)((r * 0.299f) + (g * 0.587f) + (b * 0.114f));
return (i, i, i);
}));
Users will have to be careful about thread safety, though. I'm thinking about a couple of ways to allow the user to pass arbitrary data to the delegate but I need to review how to make it thread safe -- I think I can use a generic struct param but I need to double check some assumptions.
From here I think the cell-based delegate will be relatively trivial.
I should really go pack my luggage, though.
Vignette of my office (excuse the mess, we're moving house)...
from mmalsharp.
If you want to have a look at the work-in-progress while I'm out of town, I moved convolutions to a separate folder and put much of the common logic into a base class. The cell-based delegate is currently stubbed until I get back, but:
The vignette implementation using a custom metadata struct:
https://github.com/MV10/pi-cam-test/blob/local_mmal_dev_pkg/Program.cs#L854
https://github.com/MV10/pi-cam-test/blob/local_mmal_dev_pkg/VignetteMetadata.cs
from mmalsharp.
Related Issues (20)
- Allow splitter component to process still images HOT 2
- TakePicture not setting ImageContext resolution HOT 4
- Bitmap.Save writes a raw RGB array as BGR HOT 4
- Unnecessary file output to post-process still captures
- Add user provided name to MMALPortConfig
- Allow user provided buffer number and size for camera ports HOT 1
- Setting ShutterSpeed not taking HOT 5
- Raw ImageContext output and padded resolutions HOT 1
- StereoMode not being set HOT 1
- Default motion detection example for v0.6 throws "Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception." HOT 10
- How to set camera number to capture from HOT 3
- MMALCamera.ProcessAsync sometimes hangs indefinitely HOT 7
- Question: LineDetection in Video HOT 3
- Capturing still image to memory stream no longer working HOT 2
- Camera warmup time question HOT 5
- Investigate use of ArrayPool to reduce allocations
- MMALSharp not working with new Raspbian GNU/Linux 11 (bullseye) OS HOT 4
- MMAP gives exception when initialising camera HOT 1
- Howto change PreviewPort after cam.Camera.PreviewPort.ConnectTo(video)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mmalsharp.