for (int i = 0; i < circles->total; i++)
{
// round the floats to an int
float* p = (float*)cvGetSeqElem(circles, i);
cv::Point center(cvRound(p[0]), cvRound(p[1]));
int radius = cvRound(p[2]);
//uchar* ptr;
//ptr = cvPtr2D(img, center.y, center.x, NULL);
//printf("B: %d G: %d R: %d\n", ptr[0],ptr[1],ptr[2]);
CvScalar s;
s = cvGet2D(img,center.y, center.x);//colour of circle
printf("B: %f G: %f R: %f\n",s.val[0],s.val[1],s.val[2]);
// draw the circle center
cvCircle(img, center, 3, CV_RGB(0,255,0), -1, 8, 0 );
// draw the circle outline
cvCircle(img, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );
//display coordinates
printf("x: %d y: %d r: %d\n",center.x,center.y, radius);
the code above detects 22 colored balls and extracts rgb value of each ball. ican use this rgb value to determine color of each ball. i am trying to implement detection of which color ball the white ball hits first. my idea was to wait for white balls centre to change(i.e. move) and the next color ball whose center changes is the ball it hits. but i am having trouble coding this?
You can save the previous x,y in variables, and check them every iteration, to determinate if they had changed.
I recommend you, instead of this, to check the distance between the center of the white ball to the center of the others – a collision is when the distance is the sum of the radiuses.
BTW, It’s not C.