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

  • Home
  • SEARCH
  • 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 8059421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:40:06+00:00 2026-06-05T09:40:06+00:00

I am trying to plot velocity vectors like in matlab we use quiver function

  • 0

I am trying to plot velocity vectors like in matlab we use “quiver” function http://www.mathworks.com/help/techdoc/ref/quiver.html

I need to port same methodology in C++ using OpenCV library.

I have heard There are a few optical flow methods, i.e. Lucas and Kanade (cvCalOpticalFlowLK) or Horn and Schunck (cvCalOpticalFlowHS) or Block Matching method (cvCalOpticalFlowBM)

but all of these functions take two images , while i need to use one image because i am working on fingerprints.

Kindly help me …

[Edit]
Solution found

void cvQuiver(IplImage*Image,int x,int y,int u,int v,CvScalar Color,
                                            int Size,int Thickness){
cv::Point pt1,pt2;
double Theta;
double PI = 3.1416;

if(u==0)
    Theta=PI/2;
else
    Theta=atan2(double(v),(double)(u));

pt1.x=x;
pt1.y=y;

pt2.x=x+u;
pt2.y=y+v;

cv::line(Image,pt1,pt2,Color,Thickness,8);  //Draw Line


Size=(int)(Size*0.707);


if(Theta==PI/2 && pt1.y > pt2.y)
    {
    pt1.x=(int)(Size*cos(Theta)-Size*sin(Theta)+pt2.x);
    pt1.y=(int)(Size*sin(Theta)+Size*cos(Theta)+pt2.y);
    cv::line(Image,pt1,pt2,Color,Thickness,8);  //Draw Line

    pt1.x=(int)(Size*cos(Theta)+Size*sin(Theta)+pt2.x);
    pt1.y=(int)(Size*sin(Theta)-Size*cos(Theta)+pt2.y);
    cv::line(Image,pt1,pt2,Color,Thickness,8);  //Draw Line
  }
else{
    pt1.x=(int)(-Size*cos(Theta)-Size*sin(Theta)+pt2.x);
    pt1.y=(int)(-Size*sin(Theta)+Size*cos(Theta)+pt2.y);
    cv::line(Image,pt1,pt2,Color,Thickness,8);  //Draw Line

    pt1.x=(int)(-Size*cos(Theta)+Size*sin(Theta)+pt2.x);
    pt1.y=(int)(-Size*sin(Theta)-Size*cos(Theta)+pt2.y);
    cv::line(Image,pt1,pt2,Color,Thickness,8);  //Draw Line
    }

}
  • 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-06-05T09:40:08+00:00Added an answer on June 5, 2026 at 9:40 am

    I am kind of completing the current answer here, which fails in giving the right size of each of the arrows’ tip. MATLAB does it in a way that when an arrow is nearly a dot, it doesn’t have any tip, while for long arrows it shows a big tip, as the following image shows.

    enter image description here

    To get this effect, we need to normalise the “tip size” of each of the arrow over the range of arrows’ length. The following code does the trick

        double l_max = -10;
    
        for (int y = 0; y < img_sz.height; y+=10)                                                           // First iteration, to compute the maximum l (longest flow)
        {
            for (int x = 0; x < img_sz.width; x+=10)
            {
                double dx = cvGetReal2D(velx, y, x);                                                        // Gets X component of the flow
                double dy = cvGetReal2D(vely, y, x);                                                        // Gets Y component of the flow
    
                CvPoint p = cvPoint(x, y);
    
                double l = sqrt(dx*dx + dy*dy);                                                             // This function sets a basic threshold for drawing on the image
    
                if(l>l_max) l_max = l;
            }
        }
    
    
        for (int y = 0; y < img_sz.height; y+=10)
    {
        for (int x = 0; x < img_sz.width; x+=10)
        {
            double dx = cvGetReal2D(velx, y, x);                                                        // Gets X component of the flow
            double dy = cvGetReal2D(vely, y, x);                                                        // Gets Y component of the flow
    
            CvPoint p = cvPoint(x, y);
    
            double l = sqrt(dx*dx + dy*dy);                                                             // This function sets a basic threshold for drawing on the image
            if (l > 0)
            {
                double spinSize = 5.0 * l/l_max;                                                        // Factor to normalise the size of the spin depeding on the length of the arrow
    
                CvPoint p2 = cvPoint(p.x + (int)(dx), p.y + (int)(dy));
                cvLine(resultDenseOpticalFlow, p, p2, CV_RGB(0,255,0), 1, CV_AA);
    
                double angle;                                                                           // Draws the spin of the arrow
                angle = atan2( (double) p.y - p2.y, (double) p.x - p2.x );
    
                p.x = (int) (p2.x + spinSize * cos(angle + 3.1416 / 4));
                p.y = (int) (p2.y + spinSize * sin(angle + 3.1416 / 4));
                cvLine( resultDenseOpticalFlow, p, p2, CV_RGB(0,255,0), 1, CV_AA, 0 );
    
                p.x = (int) (p2.x + spinSize * cos(angle - 3.1416 / 4));
                p.y = (int) (p2.y + spinSize * sin(angle - 3.1416 / 4));
                cvLine( resultDenseOpticalFlow, p, p2, CV_RGB(0,255,0), 1, CV_AA, 0 );
    
            }
       }
    }
    

    And this is an example of how this OpenCV code would look like

    enter image description here

    I hope this help other people Googling for the same issue.

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

Sidebar

Related Questions

Trying to plot a signal function of 0 and 1, much like the solution
I'm trying to plot some arrows using matploblib with the quiver function. But I
I'm trying to plot data in matplotlib. I would like to hide the upper
I am trying to plot some one-dimensional data onto a 2-D plot in MATLAB.
Trying to plot a spectrum, ie, velocity versus intensity, with lower x axis =
I'm currently trying to use the core-plot library to graph some data I get
I am trying to plot the following equation in MATLAB: ratio = sqrt(1+1/(kr)^2) With
I am trying to plot roots of a function that is composed of multiple
I'm trying to plot some cities on Google's Geochart. This function works perfectly fine
I have been trying to plot a map on axmapcontrol and use the same

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.