已定义值的未定义值错误
我有一个像这样的 for 循环,
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]);
int num_red = 0;
//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]);
if (s.val[2]<=255 && s.val[2]>=230 && s.val[1]<=40 && s.val[1]>=0 && s.val[0] <=40 && s.val[0]>=0)
{
printf("Red Ball\n");
num_red++;
}
它正在工作。但后来在我的代码中,我尝试使用 s.val[]
和 num_red
就像这样,
int count_red = 0;
int red_pot = 0;
if(s.val[2]<=255 && s.val[2]>=230 && s.val[1]<=40 && s.val[1]>=0 && s.val[0] <=40 && s.val[0]>=0)
count_red ++;//count the reds detected
num_red - count_red = red_pot;//originally detected - whats left = whats potted
我收到了 's' 的未声明标识符错误。 .val 的左侧必须具有类/结构和 'num_red' :未声明的标识符。我不明白为什么程序不能从上面向下读取这些值。有人能帮忙吗?
I have a for loop like so
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]);
int num_red = 0;
//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]);
if (s.val[2]<=255 && s.val[2]>=230 && s.val[1]<=40 && s.val[1]>=0 && s.val[0] <=40 && s.val[0]>=0)
{
printf("Red Ball\n");
num_red++;
}
which is working. but later on in my code i tried to use the s.val[]
and num_red
like this
int count_red = 0;
int red_pot = 0;
if(s.val[2]<=255 && s.val[2]>=230 && s.val[1]<=40 && s.val[1]>=0 && s.val[0] <=40 && s.val[0]>=0)
count_red ++;//count the reds detected
num_red - count_red = red_pot;//originally detected - whats left = whats potted
im getting undeclared identifier error for 's'. Left of .val must have class/struct and 'num_red' : undeclared identifier. I dont understand why the program doesnt can't read these values from above further down. anyone able to help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
for
循环内创建s
。因此,一旦for
循环终止,s
就会超出范围。您需要在一个范围内创建一个变量,该范围包括您打算访问它的每个范围。You create
s
inside thefor
loop. So as soon as thefor
loop terminates,s
goes out of scope. You need to create a variable at a scope that includes every scope in which you intend to access it.