球碰撞检测

我试图检测白球最初接触的颜色球。

所有球的坐标和颜色都是已知的,并且球的video输入将是顶视图,因此只有xy中的坐标

我检测到的球的代码如下

*//draw all detected circles for (int i = 0; i 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: %dy: %dr: %d\n",center.x,center.y, radius); }* 

由于你知道球的中心坐标,你可以计算每个球中心白球中心的欧氏距离。 一旦两个球中心之间的距离是它们的半径之和,那么你就会发生碰撞。 希望有所帮助。