gpt4 book ai didi

彩球碰撞

转载 作者:太空宇宙 更新时间:2023-11-03 21:55:00 24 4
gpt4 key购买 nike

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);

上面的代码检测了 22 个彩色球并提取了每个球的 rgb 值。我可以使用此 rgb 值来确定每个球的颜色。我正在尝试检测白球先击中哪个颜色的球。我的想法是等待白球中心改变(即移动),下一个中心改变的彩球就是它击中的球。但是我在编码时遇到了问题?

最佳答案

您可以将之前的 x,y 保存在变量中,并在每次迭代时检查它们,以确定它们是否已更改。我建议您检查白球中心与其他球中心之间的距离,而不是这样做 - 当距离是半径之和时发生碰撞。

顺便说一句,这不是 C。

关于彩球碰撞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8887391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com