This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Motion detection plug-in model and analysis #175
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bcf3a21
Merge pull request #3 from techyian/dev
MV10 82627aa
Merge pull request #5 from techyian/dev
MV10 14298ad
motion algorithm plug-in model and live analysis
MV10 311147d
alter motion algorithm to output analysis frames to capture handler
MV10 391375f
remove auto pkg generation (don't break the build!)
MV10 c10fb33
image processing (convolution) using cell-based parallel processing
MV10 5fd1f0a
Merge branch 'dev' into motiondiff
MV10 883f0cb
restore fixes in commit 8b07ab3
MV10 20b591c
catch up to dev
MV10 b85084e
encoded image support
MV10 6ff0288
add cell counts for padded raw buffer dimensions
MV10 c18ece5
suppress callback if buffer length is zero
MV10 a2f47c7
fixes #187
MV10 7ca06e0
test that the source data is raw
MV10 62f7d02
copy cloned resolution into original context (TakePicture doesn't set…
MV10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// <copyright file="FormatRawImageExtension.cs" company="Techyian"> | ||
// Copyright (c) Ian Auty and contributors. All rights reserved. | ||
// Licensed under the MIT License. Please see LICENSE.txt for License info. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MMALSharp.Common.Utility | ||
{ | ||
/// <summary> | ||
/// An extension to convert raw <see cref="ImageContext"/> data to a bitmap <see cref="ImageFormat"/>. | ||
/// </summary> | ||
public static class FormatRawImageExtension | ||
{ | ||
/// <summary> | ||
/// Converts the raw image data in an <see cref="ImageContext"/> object to a specified bitmap | ||
/// <see cref="ImageFormat"/> (such as <see cref="ImageFormat.Jpeg"/> or <see cref="ImageFormat.Png"/>). | ||
/// </summary> | ||
/// <param name="context">The image to convert. Must be raw data.</param> | ||
public static void FormatRawImage(this ImageContext context) | ||
{ | ||
if (!context.Raw) | ||
{ | ||
throw new Exception("ImageContext does not contain raw data"); | ||
} | ||
|
||
if (context.StoreFormat == null) | ||
{ | ||
throw new Exception("ImageContext.StoreFormat does not define a target ImageFormat"); | ||
} | ||
|
||
var pixfmt = MMALEncodingToPixelFormat(context.PixelFormat); | ||
|
||
using (var bitmap = new Bitmap(context.Resolution.Width, context.Resolution.Height, pixfmt)) | ||
{ | ||
BitmapData bmpData = null; | ||
try | ||
{ | ||
bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); | ||
var ptr = bmpData.Scan0; | ||
int size = bmpData.Stride * bitmap.Height; | ||
var data = context.Data; | ||
Marshal.Copy(data, 0, ptr, size); | ||
} | ||
finally | ||
{ | ||
bitmap.UnlockBits(bmpData); | ||
} | ||
|
||
using(var ms = new MemoryStream()) | ||
{ | ||
bitmap.Save(ms, context.StoreFormat); | ||
context.Data = new byte[ms.Length]; | ||
Array.Copy(ms.ToArray(), 0, context.Data, 0, ms.Length); | ||
} | ||
} | ||
} | ||
|
||
private static PixelFormat MMALEncodingToPixelFormat(MMALEncoding encoding) | ||
{ | ||
if(encoding == MMALEncoding.RGB24) | ||
{ | ||
return PixelFormat.Format24bppRgb; | ||
} | ||
|
||
if (encoding == MMALEncoding.RGB32) | ||
{ | ||
return PixelFormat.Format32bppRgb; | ||
} | ||
|
||
if (encoding == MMALEncoding.RGBA) | ||
{ | ||
return PixelFormat.Format32bppArgb; | ||
} | ||
|
||
throw new Exception("Unsupported encoding / pixel format"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ public interface IMotionCaptureHandler | |
/// <summary> | ||
/// Disables motion detection. When configured, this will instruct the capture handler not to detect motion. | ||
/// </summary> | ||
void DisableMotionDetection(); | ||
/// <param name="disableCallbackOnly">When true, motion detection will continue but the OnDetect callback | ||
/// will not be invoked. Call <see cref="EnableMotionDetection"/> to re-enable the callback.</param> | ||
void DisableMotionDetection(bool disableCallbackOnly = false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user calls this method and wants to re-enable the callback, how do they do this? Am I right in thinking they just modify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this additional constructor is used to replicate what
MMALCamera.WithMotionDetection()
does?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By funny coincidence I was just looking at that myself, and I don't think it is needed. There was a point where I was trying to avoid modifying
MotionConfig
and I think it's left over from that. I will straighten it out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that constructor was useful when doing nothing but visualizing the motion detection analysis. Used in a simple configuration like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see I do explain one usage in the constructor summary, although it could be better, it does now also work with the camera (the example above is for streaming). I'll update the summary.