Please tell me what's wrong with my code! New OpenCV User
Below is my code. It is supposed to draw lines from the center of the circle to the edge of the circle, but some of the lines are too short while others are too long. Does anyone have a fix for this?
cvNamedWindow("Shapes",CV_WINDOW_AUTOSIZE);
//Image structure
IplImage* shape=cvLoadImage("white2.jpg");
//Drawing a Rectangle
int x = shape->width;
int y = shape->height;
int m = 0;
int l = 2;
int q = 300;
int z = shape->width / l;
int a = shape->height / l;
int b = 10;
int f = -255;
int g = 255;
cvRectangle(shape,cvPoint(x,m),cvPoint(m,y),CV_RGB(m,g,m),f,g);
//Drawing a Circle
cvCircle(shape,cvPoint(z,a),q,CV_RGB(m,m,g),f);
cvCircle(shape,cvPoint(z,a),b,CV_RGB(m,g,m),f);
for(int o = 2; o < 800; o+=45){
for(int n = 2; n < 800; n +=45){
cvLine(shape, cvPoint(z,a), cvPoint(o,n), CV_RGB(0,255,0),1,8);
}
}
//Showing the image
cvShowImage("Shapes",shape);
//Escape Sequence
cvWaitKey(0);
//CleanUp
cvReleaseImage(&shape);
cvDestroyAllWindows();
}
The dimensions of the image are 600 x 600.
Think about converting to C++ interface instead of legacy interface that you are using.
the other answer showed you, how to get a point for a certain angle. look at that again, and make 1 loop over angles, not 2 for x and y