定义的值上的未定义值错误

时间:2011-11-02 01:15:20

标签: opencv undefined identifier

我有一个像这样的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的左边必须有class / struct和'num_red':未声明的标识符。我不明白为什么程序不能从上面进一步读取这些值。有人能帮忙吗?

1 个答案:

答案 0 :(得分:0)

您在s循环中创建for。因此,只要for循环终止,s就会超出范围。您需要在包含您打算访问它的每个范围的范围内创建变量。

相关问题