我想使用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