Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6733123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:43:54+00:00 2026-05-26T10:43:54+00:00

I am runnng the motion detection algorithm against a video (file) and following the

  • 0

I am runnng the motion detection algorithm against a video (file) and following the code sample motion detection, and trying to find the angle of each component and the overall motion. I do get a motion value back, with blobs etc., but the motion direction of each component always is always 0 degrees or 360 degrees and make no sense. What could I be doing wrong? Please help, thanks.

This is the constructor

_motionHistory = new MotionHistory(
                                              10.0, //in second, the duration of motion history you wants to keep
                                              0.05, //in second, parameter for cvCalcMotionGradient
                                              0.5); //in second, parameter for cvCalcMotionGradient

The following is the code for looping through the motion components:

foreach (MCvConnectedComp comp in motionComponents)
                    {
                        //reject the components that have small area;
                        if (comp.area < 1) continue;

                        // find the angle and motion pixel count of the specific area
                            double angle, motionPixelCount;
                            _motionHistory.MotionInfo(comp.rect, out angle, out motionPixelCount);

                            string motion_direction = GetMotionDescriptor(comp.rect);
Console.writeline (motion_direction);


                    }

                    // find and draw the overall motion angle
                    double overallAngle, overallMotionPixelCount;
                    _motionHistory.MotionInfo(motionMask.ROI, out overallAngle, out overallMotionPixelCount);

And this where I get my motion descriptor angle

private string GetMotionDescriptor(Rectangle motionRegion)
        {
            float circleRadius = (motionRegion.Width + motionRegion.Height) >> 2;
            Point center = new Point(motionRegion.X + motionRegion.Width >> 1, motionRegion.Y + motionRegion.Height >> 1);

            int xDirection = (int)(Math.Cos(angle * (Math.PI / 180.0)) * circleRadius);
            int yDirection = (int)(Math.Sin(angle * (Math.PI / 180.0)) * circleRadius);
            //double movementAngle = Math.Atan(xDirection / yDirection) * 180 / Math.PI;
            Point pointOnCircle = new Point(center.X + xDirection, center.Y - yDirection);
            double slope = (double)(pointOnCircle.Y - center.Y)/(double)(pointOnCircle.X - center.X);
            double ang = Math.Atan(slope) * 180/Math.PI;
            return (ang).ToString() + " degrees";
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:43:54+00:00Added an answer on May 26, 2026 at 10:43 am

    aha! I figured out the reason and posting here if anyone is running into the same problem. The

    _motionHistory = new MotionHistory(mhi, maxDelta, minDelta); 
    

    Should be adjusted to the frame rate and the motion. The trick lies in the 3 params
    (1) motion history to keep, (2) max time delta, (3) min time delta.

    They need to be adjusted in some way to reflect the motion you wish to capture.
    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running the following JavaScript code shows 63 in both cases: alert( 0xff >> 2
Running the following code in Delphi XE2 Win32 platform works. However, the same code
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
I have a software-hardware related issue that I'm trying to troubleshoot. My app was
I am working on an iPhone app where we are trying to calculate the
Running this in python will result in a WindowsError stating it cannot find the
I'm running into a problem with some of my code on iPhone3GS running iOS5.0
i have a function(initialize) inside the a.as File.i want to access the that Variable
Running on: mehoggan@mehoggan-laptop:~/Code/svn_playground/C++/timer/timer0$ uname -a Linux mehoggan-laptop 2.6.32-37-generic #81-Ubuntu SMP Fri Dec 2 20:32:42
Running on MySQL 5.5.9 with InnoDB. I created the following trigger: CREATE TRIGGER TRIGGER_Products_Insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.