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.
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:
.NET 1.1 redistributable package
Flash player
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();
Collapse Copy Code//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++.
Collapse Copy Codeprivate:
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
Macromedia Flash Live Doc (Camera class)
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
Other popular C++ / CLI articles:
.NET Dynamic Software Load Balancing
A Draft Implementation of an Idea for .NET Dynamic Software Load Balancing
Quake II .NET
A port of the famous C-language based game engine to Visual C++ with a .NET managed heads-up display.
A first look at C++/CLI
A brief look at the new C++/CLI syntax and how it improves over the old MC++ syntax
OLE DB - Bound controls
Shows how you can use data bound controls with OLE DB
How to get the clients IP address using TcpClient in Managed C++
How to get the clients IP address using TcpClient in Managed C++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment