Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 球碰撞检测_C_Opencv_Collision Detection_Geometry - Fatal编程技术网

C 球碰撞检测

C 球碰撞检测,c,opencv,collision-detection,geometry,C,Opencv,Collision Detection,Geometry,我试着检测一个白色的球最初接触的是什么颜色的球 所有球的坐标和颜色都是已知的,球的视频馈送将是俯视图,因此只有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

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

所有球的坐标和颜色都是已知的,球的视频馈送将是俯视图,因此只有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);
}* 
*//绘制所有检测到的圆
对于(int i=0;itotal;i++)
{
//将浮点数四舍五入为整数
float*p=(float*)cvGetSeqElem(圆,i);
cv::点中心(cvRound(p[0]),cvRound(p[1]);
int radius=cvRound(p[2]);
//乌查尔*ptr;
//ptr=cvPtr2D(img,center.y,center.x,NULL);
//printf(“B:%d G:%d R:%d\n”,ptr[0],ptr[1],ptr[2]);
cvs;
s=cvGet2D(img,center.y,center.x);//圆的颜色
printf(“B:%f G:%f R:%f\n”,s.val[0],s.val[1],s.val[2]);
//画圆心
CV圆(img,中心,3,CV_RGB(0255,0),-1,8,0);
//画圆的轮廓
CV圆(img,中心,半径+1,CV_RGB(0,0255),2,8,0);
//显示坐标
printf(“x:%d y:%d r:%d\n”,中心x,中心y,半径);
}* 

既然你知道球中心的坐标,你就可以计算每个球中心到白色球中心的欧几里德距离。一旦两个球中心之间的距离是它们半径的总和,那么就有了碰撞。
希望有帮助。

这是什么编程语言?应该放进去的。它的C.im使用opencv对我来说似乎很简单,如果你有x1,y1作为球1中心的坐标,r1作为半径,x2,y2,r2作为第二个球,那么如果sqrt(pow((x1-x2),2)+pow((y1-y2),2))=r1+r2,你有一个碰撞