C#相机检测到任何动作后如何获取图片 [英] C# how to get picture after camera detected any motion

查看:102
本文介绍了C#相机检测到任何动作后如何获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作这样的节目。如果网络摄像头检测到任何动作,那么我想拍摄这个动作。我完成了程序,但我需要得到那个图像。我的项目有一张照片。当用户点击Tamam>消息框显示动作已被解除后好的

然后屏幕将保存。



http://prntscr.com/4syrrq



i想拍照(在消息框后面),你可以看到。



谢谢。



ps:抱歉我的英文不好。

Hi, im making a program like that. If web cam detects any motion then i want to take picture of this motion. I finished the program but i need just get that image. There is a picture from my project. After message box shows you "motion is dedected" when user click "Tamam" > "Okay"
then screen will be save.

http://prntscr.com/4syrrq

i wanna take the picture (behind the messagebox) as you can see.

Thanks.

ps: sorry for my bad english.

推荐答案

有一篇关于CodeProject的文章解释了如何区分两个图像。当您查看相机屏幕时,您正在观看图像被更改为屏幕上的帧。它们中的每一个都是提供给您的帧。



因此,每一帧在许多方面可能与前一帧不同。 .NET中的简单图像比较 [ ^ ]解释了如何获得差异。



在那篇文章中,他解释说,在字节级别(像素级别),每个像素都有一点点差别,人眼甚至无法想到注意到。因此,您可能无法检测到任何更改,但计算机会在新图像中找到更改,并且将单击!单击!单击!在第二部分的第三部分等等。



阅读上面的文章,并为您编写代码。您需要做的就是确保正在处理图像差异。之后,您可以从屏幕获取像素并保存为屏幕截图。我已经为此写了一个提示,使用C#保存屏幕截图, AKA控制台监视器 [ ^ ],你走了。阅读这两个链接,我希望你能得到你想要的东西。
There is an article on CodeProject that explains how you can get the difference between two images. While you're having a look at the camera screen, you're watching images being changed as frames on the screen. Each of them in real are frames being provided to you.

So, each frame might differ to the previous one in many ways. Simple image comparison in .NET[^] explains how you can get the difference.

In that article, he explains that on the byte level (pixel level) each pixel has a slight difference that human eye can never even think about noticing. So you might not detect any change but the computer would find a change in the new image and will "Click! Click! Click!" in 3rd part of the second and so.

Read the article above, and code it out for you. All you need to do is, to make sure, that the image difference is being handled. After that you can get the pixels from the screen and saved as a screenshot. I have written a tip for that, Saving a Screenshot Using C#, A.K.A "Console Monitor"[^], here you go. Read these both links, and I hope you will get what you want to get.


你好,



能够检测到任何动作时拍摄快照,请查看以下代码段。

(这是一个简短的例子,可以在这里找到完整的源代码:

如何通过拍摄快照并将其作为一个快照发送来处理警报C#中的电子邮件 [ ^ ]。)



使用此代码可以创建快照(在文件名中显示当前日期)

如果检测到任何动作。 (由于前面提到的示例项目侧重于将此

快照作为警报通知发送到电子邮件中,因此也可以使用已编辑的代码片段

并调用SendEmail( )通过电子邮件自动发送快照的方法。)



Hello,

To be able to take snapshots when any motion is detected, take a look the following code snippet.
(This is a short example from the full source code that can be found here:
How to handle alarms by taking a snapshot and sending it as an e-mail in C#[^].)

By using this code you can create a snapshot (displaying the current date in the file name)
if any motion is detected. (As the previously mentioned example project focuses on sending this
snapshot in e-mail as an alarm notification, the insterted code snippet can be also used
and call the SendEmail() method that sends the snapshot automatically in e-mail.)

private void _motionDetector_MotionDetection(object sender, MotionDetectionEvent e)
{
if (e.Detection)
{
InvokeGuiThread(() => label_Motion.Text = "Motion detected");

var date = DateTime.Now.Year + "y-" + DateTime.Now.Month + "m-" + DateTime.Now.Day + "d-" +
DateTime.Now.Hour + "h-" + DateTime.Now.Minute + "m-" + DateTime.Now.Second + "s";
var filename = "Camera_" + date + ".jpg";

Task.Factory.StartNew(() =>
{
var snapshot = _snapshot.TakeSnapshot();
_image = snapshot.ToImage();
_image.Save(filename);
SendEmail(filename);
});
}
else
InvokeGuiThread(() => label_Motion.Text = "Motion ended");
}





我希望它可以帮助您完成您的问题。



I hope it helps you to complete your issue.


这篇关于C#相机检测到任何动作后如何获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆