Click here to Skip to main content
6,292,426 members and growing! (11,150 online)
Email Password   helpLost your password?
Languages » C++ / CLI » General     Intermediate License: The Code Project Open License (CPOL)

Easy Motion Detection

By Nimesha Ranasinghe

Detect motion using any webcam
C++/CLI, Windows, .NET, Visual Studio, Dev
Version:2 (See All)
Posted:19 Jul 2006
Updated:25 Jul 2006
Views:40,440
Bookmarked:36 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
10 votes for this article.
Popularity: 3.48 Rating: 3.48 out of 5
1 vote, 10.0%
1

2
2 votes, 20.0%
3
2 votes, 20.0%
4
5 votes, 50.0%
5
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();

//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++.

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)

About the Author

Nimesha Ranasinghe


Member
Graduate student of Mixed Reality Lab, National University of Singapore
Occupation: Engineer
Company: Mixed Reality Lab, National University of Singapor
Location: Singapore Singapore

Other popular C++ / CLI articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
GeneralAxShockwaveFlash time duration? Pinmembervictorace22:22 4 Feb '09  
GeneralHow to handle flash event ? PinmemberFeiluHang19:49 24 May '07  
GeneralRe: How to handle flash event ? PinmemberNimesha Ranasinghe20:38 29 Oct '07  
GeneralSome problem when i add shockwave Flash object PinmemberYJunsom17:46 11 Feb '07  
GeneralRe: Some problem when i add shockwave Flash object PinmemberNimesha Ranasinghe23:18 11 Feb '07  
Generalhow to grab frames in c#? Pinmembersallows200716:07 25 Oct '06  
AnswerRe: how to grab frames in c#? PinmemberNimesha Ranasinghe5:09 30 Oct '06  
Generalhow it is done?? PinmemberLipKee5:31 2 Oct '06  
GeneralIdea: save image to disk when motion is detected Pinmembertkdmaster5:19 20 Jul '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Jul 2006
Editor: Deeksha Shenoy
Copyright 2006 by Nimesha Ranasinghe
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project