null 未声明的标识符错误

发布于 2024-12-09 02:14:34 字数 2932 浏览 1 评论 0原文

我不知道发生了什么,因为几天前它正在运行,但现在我在 detectcircle() 方法中收到有关未声明的空标识符的错误。 if(p==null){return;} 我不知道发生了什么。

 #include <stdio.h>
    #include "cv.h"
    #include "highgui.h"
    #include <iostream>
    #include <math.h>
    #include <string.h>
    #include <conio.h>

using namespace std;

IplImage* img = 0;
CvMemStorage * cstorage;
CvMemStorage * hstorage;

void detectCircle( IplImage *frame );


int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    hstorage = cvCreateMemStorage( 0 );
    cstorage = cvCreateMemStorage( 0 );

    //CvVideoWriter *writer = 0;
    //int colour = 1;
    //int fps = 25;
    //int frameW = 640;
    //int frameH = 480;
    //writer = cvCreateVideoWriter("test.avi",CV_FOURCC('P', 'I', 'M', '1'),fps,cvSize(frameW,frameH),colour);

    //initialise camera
    capture = cvCaptureFromCAM( 0 );

    //check if camera present
    if ( !capture )
    {
        fprintf( stderr, "cannot open webcam\n");
        return 1;
    }

    //create a window
    cvNamedWindow( "Snooker", CV_WINDOW_AUTOSIZE );

    while(key !='q') 
    {

    //get frame
        frame = cvQueryFrame(capture);
        //int nFrames = 50;
        //for (int i=0; i<nFrames;i++){
            //cvGrabFrame(capture);
            //frame = cvRetrieveFrame(capture);
            //cvWriteFrame(writer, frame);
        //}

    //check for frame
        if( !frame ) break;

        detectCircle(frame);


    //display current frame
        //cvShowImage ("Snooker", frame );

        //exit if Q pressed
        key = cvWaitKey( 20 );

    }
    // free memory
    cvDestroyWindow( "Snooker" );
    cvReleaseCapture( &capture );
    cvReleaseMemStorage( &cstorage);
    cvReleaseMemStorage( &hstorage);
    //cvReleaseVideoWriter(&writer);

    return 0;
}
void detectCircle( IplImage * img )
{
    int edge_thresh = 1;
    IplImage *gray = cvCreateImage( cvSize(img->width,img->height), 8, 1);
    IplImage *edge = cvCreateImage( cvSize(img->width,img->height), 8, 1);

    cvCvtColor(img, gray, CV_BGR2GRAY);

    gray->origin = 1;

    // color threshold
    cvThreshold(gray,gray,100,255,CV_THRESH_BINARY);    

    // smooths out image
    cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11);

    // get edges
    cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5); 

    // detects circle
    CvSeq* circle =  cvHoughCircles(edge, cstorage, CV_HOUGH_GRADIENT, 1,
        edge->height/50, 5, 35);

    // draws circle and its centerpoint
    float* p = (float*)cvGetSeqElem( circle, 0 );
    if( p==null ){ return;}

    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(255,0,0), -1, 8, 0 );
    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(200,0,0), 1, 8, 0 );

    cvShowImage ("Snooker", img );
}

I dont know what happened as this was running grand a few days ago but now im getting an error about an undelcared null identifier in the detectcircle() method. if(p==null){return;} I dont know whats going on.

 #include <stdio.h>
    #include "cv.h"
    #include "highgui.h"
    #include <iostream>
    #include <math.h>
    #include <string.h>
    #include <conio.h>

using namespace std;

IplImage* img = 0;
CvMemStorage * cstorage;
CvMemStorage * hstorage;

void detectCircle( IplImage *frame );


int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    hstorage = cvCreateMemStorage( 0 );
    cstorage = cvCreateMemStorage( 0 );

    //CvVideoWriter *writer = 0;
    //int colour = 1;
    //int fps = 25;
    //int frameW = 640;
    //int frameH = 480;
    //writer = cvCreateVideoWriter("test.avi",CV_FOURCC('P', 'I', 'M', '1'),fps,cvSize(frameW,frameH),colour);

    //initialise camera
    capture = cvCaptureFromCAM( 0 );

    //check if camera present
    if ( !capture )
    {
        fprintf( stderr, "cannot open webcam\n");
        return 1;
    }

    //create a window
    cvNamedWindow( "Snooker", CV_WINDOW_AUTOSIZE );

    while(key !='q') 
    {

    //get frame
        frame = cvQueryFrame(capture);
        //int nFrames = 50;
        //for (int i=0; i<nFrames;i++){
            //cvGrabFrame(capture);
            //frame = cvRetrieveFrame(capture);
            //cvWriteFrame(writer, frame);
        //}

    //check for frame
        if( !frame ) break;

        detectCircle(frame);


    //display current frame
        //cvShowImage ("Snooker", frame );

        //exit if Q pressed
        key = cvWaitKey( 20 );

    }
    // free memory
    cvDestroyWindow( "Snooker" );
    cvReleaseCapture( &capture );
    cvReleaseMemStorage( &cstorage);
    cvReleaseMemStorage( &hstorage);
    //cvReleaseVideoWriter(&writer);

    return 0;
}
void detectCircle( IplImage * img )
{
    int edge_thresh = 1;
    IplImage *gray = cvCreateImage( cvSize(img->width,img->height), 8, 1);
    IplImage *edge = cvCreateImage( cvSize(img->width,img->height), 8, 1);

    cvCvtColor(img, gray, CV_BGR2GRAY);

    gray->origin = 1;

    // color threshold
    cvThreshold(gray,gray,100,255,CV_THRESH_BINARY);    

    // smooths out image
    cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11);

    // get edges
    cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5); 

    // detects circle
    CvSeq* circle =  cvHoughCircles(edge, cstorage, CV_HOUGH_GRADIENT, 1,
        edge->height/50, 5, 35);

    // draws circle and its centerpoint
    float* p = (float*)cvGetSeqElem( circle, 0 );
    if( p==null ){ return;}

    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(255,0,0), -1, 8, 0 );
    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(200,0,0), 1, 8, 0 );

    cvShowImage ("Snooker", img );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人问我粥可暖 2024-12-16 02:14:34

null 替换为 NULLNULL 是一个实现定义的宏,表示空指针常量(标准中的 18.1.4)。通常,它是:

#define NULL 0

Replace null with NULL. NULL is a implementation-defined macro that represents the null pointer constant (18.1.4 in the standard). Usually, it's:

#define NULL 0
不弃不离 2024-12-16 02:14:34

自从我不得不用 C 编程以来,我不得不查找这个,但我认为你的意思是 NULL

它将“null”视为未声明的变量。

It's so long since I had to program in C that I had to look this up, but I think you mean NULL
.

It is taking "null" as an undeclared variable.

若能看破又如何 2024-12-16 02:14:34

区分大小写,NULL 而不是 null,不是吗?

case-sensitive, NULL instead of null, isn't it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文