5,661,954 members and growing! (13,945 online)
Email Password   helpLost your password?
Languages » C++ / CLI » General     Intermediate

Easy Motion Detection

By Nimesha Ranasinghe

Detect Motions using any webcam
C++/CLI, Windows, .NET, Visual Studio, Dev

Posted: 19 Jul 2006
Updated: 25 Jul 2006
Views: 33,402
Bookmarked: 29 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
10 votes for this Article.
Popularity: 3.48 Rating: 3.48 out of 5
1 vote, 10.0%
1
0 votes, 0.0%
2
2 votes, 20.0%
3
2 votes, 20.0%
4
5 votes, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

How it response to a motion.

Introduction

When I did another project, I got this stupid method to implement motion detection.

I tried some other way to do this motion detection. And I got frustrated when I use them. Because I don t really need any advanced algorithms to do this one. I was in thinking and got a nice idea to do it. And U also can do it now.

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

Select the COM

Background + Prerequisites

You should be pre installed the .NET version 1.1 and Flash player 6 or higher for testing this code. They are freely available here.

Download .NET 1.1 redistributable package from here. and Flash player http://www.adobe.com/products/flashplayer/

Using the code

The first message is coming when the application starts. And the others are coming when it detects motion. The camera preview part and the motion detecting part are being actually done by the flash scripts. And 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 happened 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nimesha Ranasinghe


I am an undergraduate @ Faculty of Information Technology, University of Moratuwa. Sri Lanka.
Occupation: Software Developer
Company: Interblocks Pvt Ltd.
Location: Sri Lanka Sri Lanka

Other popular C++ / CLI articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
GeneralHow to handle flash event ?memberFeiluHang19:49 24 May '07  
GeneralRe: How to handle flash event ?memberNimesha Ranasinghe20:38 29 Oct '07  
GeneralSome problem when i add shockwave Flash objectmemberYJunsom17:46 11 Feb '07  
GeneralRe: Some problem when i add shockwave Flash objectmemberNimesha Ranasinghe23:18 11 Feb '07  
Generalhow to grab frames in c#?membersallows200716:07 25 Oct '06  
AnswerRe: how to grab frames in c#?memberNimesha Ranasinghe5:09 30 Oct '06  
Generalhow it is done??memberLipKee5:31 2 Oct '06  
GeneralIdea: save image to disk when motion is detectedmembertkdmaster5: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:
Copyright 2006 by Nimesha Ranasinghe
Everything else Copyright © CodeProject, 1999-2008
Web11 | Advertise on the Code Project