【问题标题】:ball collision detection球碰撞检测
【发布时间】:2012-01-07 03:50:10
【问题描述】:

我试图检测一个白球最初接触的是什么颜色的球。

所有球的坐标和颜色都是已知的,球的视频输入将是顶视图,因此只有 x-y 坐标

我检测到的球的代码如下

*//draw all detected circles
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);
}* 

【问题讨论】:

  • 这是什么编程语言?
  • 应该把它放进去。它的 C.im 也使用 opencv

标签: c opencv collision-detection geometry


【解决方案1】:

由于您知道球中心的坐标,因此您只需计算每个球中心与白球中心的欧几里得距离。一旦两个球心之间的距离是它们的半径之和,那么你就会发生碰撞。 希望对您有所帮助。

【讨论】:

  • 如果你有 x1,y1 作为球 1 中心的坐标,r1 作为半径,x2,y2,r2 作为第二个球然后如果 sqrt(pow((x1-x2) ,2) + pow((y1-y2),2)) = r1 + r2 你有碰撞
猜你喜欢
  • 1970-01-01
  • 2015-10-06
  • 2010-09-25
  • 2016-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多