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 7806565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:34:36+00:00 2026-06-02T02:34:36+00:00

I want to draw a sine wave on a image using openCV. I developed

  • 0

I want to draw a sine wave on a image using openCV. I developed the following code, but the output is not coming as expected:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
void main()
{ 
double y[100]; 
      float x; 


  for(x=0;x<100;x++)
  {
      y[(int)floor(x)]=sin(x);

  }

  IplImage *grf = cvCreateImage( cvSize( 200, 200), IPL_DEPTH_8U, 1 );


  for(int x=0;x<100;x++)
  {
  cvLine(grf ,                         /* the dest image */
          cvPoint(x, y[x]),  /* start point */

           cvPoint(x+1, y[x+1]),            /* end point */
           CV_RGB(255, 0, 0),      /* the color; green */
           2, 4, 0);                    /* thickness, line type, shift */

  }


  cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
    cvShowImage("img", grf);
    cvWaitKey(0);
    cvDestroyWindow("img");
    cvReleaseImage(&grf);
}

I have verified the values coming in y array is correct, and plotted these y values using MATLAB. The MATLAB plot is coming a sine wave. Can you tell me why i am not getting correct plot using above code.

My output plot of sine wave is coming as below: you can see I am just getting a horizontal line instead of the sine wave. Any help regarding this?

enter image description here

SOLVED: After following the answer I got the following image:

enter image description here
Thanks

  • 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-02T02:34:37+00:00Added an answer on June 2, 2026 at 2:34 am

    The sin function returns you a value [-1:1], thus you are setting coordinates between line 0 and 1 on your image.
    You need to increase amplitude of your sin, shift it’s zero value and reduce a frequency of the sine wave (as sin accepts angle in radians, so you’ll pass a period in 4 steps):

    y[(int)floor(x)]=10 + 10*sin(2*.1*PI*x);
    

    So, you will be able to see a sine wave.

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

Sidebar

Related Questions

I want to draw UIButton in following shape : I have cut the image,
Drawing flat waves is easy, but I want to draw the wave between two
I want to draw text into UIView 's subview using drawInRect:withFont:lineBreakMode call but that
I want to draw an alpha mask image in code. Right now I do:
I want to draw a moving sine wave with variable frequency and variable amplitude
I want to draw text just like the following style -- the image is
I want to draw line on UIImageView. I already draw line on UIImageView but
I want to draw a stock chart using Google Chart Tools. My self-written webservice
I want to draw an image on the left of an EditText. I don't
I want to Draw a hyper Link in C# using stringbuilder when i create

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.