我想使用openCV在图像上绘制正弦波。我公司开发了下面的代码,但输出不来预期:使用opencv绘制正弦波
#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);
}
我已经验证值y中数组来是正确的,并绘制利用MATLAB这些y值。 MATLAB绘图正在出现一个正弦波。你能告诉我为什么我没有使用上面的代码得到正确的阴谋。
我的正弦波输出图如下图所示:您可以看到我只是得到一条水平线而不是正弦波。有关于此的任何帮助?
解决:下面的答案后,我得到了下面的图片:
感谢
完美!感谢您的快速帮助 – geeta 2012-04-18 13:48:20
@geeta欢迎您! – Alex 2012-04-18 13:58:44
代替你的建议,y [(int)floor(x)] = 100 + 20 * sin(0.4 * .1 * PI * x)情节在上面。谢谢 – geeta 2012-04-18 13:59:31