Click here to Skip to main content
15,867,704 members
Articles / Programming Languages / C++/CLI

Easy Motion Detection

Rate me:
Please Sign up or sign in to vote.
3.91/5 (15 votes)
25 Jul 2006CPOL1 min read 115.8K   7.7K   58   11
Detect motion using any webcam
How it response to a motion.

Introduction

When I worked on another project, I got this method to implement motion detection.

I tried some other ways to do this motion detection. But I got frustrated when I used them. Because I don't really need any advanced algorithms to do this one, I thought a little and got a nice idea to do it. And you can also do it now.

Just about 5 lines in Visual C++ .NET code and a few lines in Flash Action Script.

Select the COM

Background + Prerequisites

You should have pre-installed the .NET version 1.1 and Flash player 6 or higher for testing this code. They are freely available at the links given below:

Using the Code

The first message comes when the application starts. The others come when it detects motion. The camera preview part and the motion detecting part are actually being done by the flash scripts. Finally the Visual C++ .NET application gets the motion via VC COM interface fscommand();

C++
//get the real camera & set the motion level + quality
camera = Camera.get();
camera.setMotionLevel(25, 2);
camera.setQuality(0,5);

//embedded video object
myVideoObject.hide();
//get the preview
myVideoObject.attachVideo(camera);

//call when camera detects a motion
camera.onActivity = function(mode)
{
    if (mode)
    {
        trace("Kawru hari awa. Camerawa langata.");
        //get into the Visual C++
        fscommand("MOTION_DETECTED", "OK");
    }
};

Camera.get(); will return the camera object with the default connected interface. Then we can set the motion level and the quality. Finally attach the camera object to the Embedded Video object.

When activity happens, it gives the feed into the VC++.

C++
private: 
    AxInterop::ShockwaveFlashObjects::AxShockwaveFlash*  axShockwaveFlash1;

    String* sFlashPath = System::Environment::CurrentDirectory;
    String* sCurrentDir = sFlashPath;
    //set the path of GUI
    file = new String("\\detector.swf");
    sFlashPath = String::Concat(sFlashPath, file);

    iStartApp = 0;

    //load Main detector GUI
    axShockwaveFlash1->LoadMovie(0, sFlashPath);

In Visual C++ .NET, just use the axShockwaveFlash COM interface to load the Main Flash GUI. Then use axShockwaveFlash1_FSCommand event to interface with the COM.

Additional Resources

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Mixed Reality Lab, National University of Singapor
Singapore Singapore
Graduate student of Mixed Reality Lab, National University of Singapore

Comments and Discussions

 
QuestionNot really an article... Pin
Dave Kreskowiak22-Jul-11 7:11
mveDave Kreskowiak22-Jul-11 7:11 
GeneralMy vote of 1 Pin
claudio_romero7-Nov-10 7:00
claudio_romero7-Nov-10 7:00 
QuestionAxShockwaveFlash time duration? Pin
victorace4-Feb-09 21:22
victorace4-Feb-09 21:22 
QuestionHow to handle flash event ? Pin
FeiluHang24-May-07 18:49
FeiluHang24-May-07 18:49 
AnswerRe: How to handle flash event ? Pin
Nimesha Ranasinghe29-Oct-07 19:38
Nimesha Ranasinghe29-Oct-07 19:38 
GeneralSome problem when i add shockwave Flash object Pin
YJunsom11-Feb-07 16:46
YJunsom11-Feb-07 16:46 
I use MS Visual Studio.NET 2005(C#). I can not add shockwave Flash object . When i added and drag it to window MS Visual Studio.NET 2005 will show message "Failed to import the ActiveX Control.Please ensure it is properly registered" I don't know this message.
Can you programming in c# and tell me about this project. Please help me

Thank you.Smile | :)

Virus@comscI

GeneralRe: Some problem when i add shockwave Flash object Pin
Nimesha Ranasinghe11-Feb-07 22:18
Nimesha Ranasinghe11-Feb-07 22:18 
Questionhow to grab frames in c#? Pin
sallows200725-Oct-06 15:07
sallows200725-Oct-06 15:07 
AnswerRe: how to grab frames in c#? Pin
Nimesha Ranasinghe30-Oct-06 4:09
Nimesha Ranasinghe30-Oct-06 4:09 
Questionhow it is done?? Pin
LipKee2-Oct-06 4:31
LipKee2-Oct-06 4:31 
GeneralIdea: save image to disk when motion is detected Pin
tkdmaster20-Jul-06 4:19
tkdmaster20-Jul-06 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.