2011-10-10 5 views
1

며칠 전이 프로그램이 웅장한 상태로 실행되었지만 이제는 detectcircle() 메서드에서 오류가없는 null 식별자에 대한 오류가 발생했는지 알지 못합니다. if(p==null){return;} 무슨 일인지 모르겠다. 나는 이것을 지켜 볼 수밖에 없었습니다 C로 프로그래밍했다 이후null 선언되지 않은 식별자 오류

#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); 
} 
+0

C 또는 C++의 언어는 무엇입니까? – Staven

답변

4

nullNULL으로 바꿉니다. NULL은 널 포인터 상수 (표준의 18.1.4)를 나타내는 구현 정의 매크로입니다. 일반적으로 다음과 같습니다.

#define NULL 0 
0

그것은 너무 오래,하지만 난 당신이 NULL 을 의미 생각합니다.

선언되지 않은 변수로 "null"을 사용 중입니다.

+0

예, 어떤 아이디어로 해결할 수 있습니까? – user966890

+2

나는 그것을 어떻게 고쳐야한다고 말했 을까. –

0

대소 문자를 구분하면 null 대신 NULL이 아니겠습니까?

+0

예. 감사. – user966890

+0

@ user966890 너무 명확하다면, 왜 스스로 알아낼 수 없었겠습니까? –

관련 문제