2

This is the code snippet to display an AVI video and it works.

int main(int argc, char** argv) {

    //    cvNamedWindow(“Example2”, CV_WINDOW_AUTOSIZE);

    CvCapture* capture = cvCreateFileCapture("video.avi");
    IplImage* frame;

    while(1) {
        frame = cvQueryFrame(capture);
        if(!frame)
            break;
        cvShowImage("Example2", frame);
        char c = cvWaitKey(33);
        if(c == 27)
            break;
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("Example2");

    return 0;
}

However, when I remove the comment // from the second line, it doesn't work. The error that I get is:

Invoking: GCC C Compiler
gcc -I/usr/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.c"
../main.c: In function ‘main’:
../main.c:5:5: error: stray ‘\342’ in program
../main.c:5:5: error: stray ‘\200’ in program
../main.c:5:5: error: stray ‘\234’ in program
../main.c:5:5: error: stray ‘\342’ in program
../main.c:5:5: error: stray ‘\200’ in program
../main.c:5:5: error: stray ‘\235’ in program
../main.c:5:23: error: ‘Example2’ undeclared (first use in this function)
../main.c:5:23: note: each undeclared identifier is reported only once for each function it appears in
make: *** [main.o] Error 1

How is 'Example2' undeclared? Isn't cvNamedwindow supposed to do that job?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wrahool
  • 1,101
  • 4
  • 18
  • 42
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 26 '23 at 23:28
  • In this case: 342 200 234 (octal) → 0xE2 0x80 0x9C (hexadecimal) → UTF-8 sequence for Unicode code point U+201C ([LEFT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9)). And 342 200 235 (octal) → 0xE2 0x80 0x9D (hexadecimal) → UTF-8 sequence for Unicode code point U+201D ([RIGHT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9)). They can be searched for (and replaced) using regular expression `\x{201C}|\x{201D}` in any modern text editor. – Peter Mortensen Apr 26 '23 at 23:29
  • In this case, it was revealed [the code was copied from an ebook](https://stackoverflow.com/questions/8686210/cvnamedwindow-not-working-in-opencv-on-eclipse-on-ubuntu-11-10#comment10801409_8686226) (whatever that is (in particular)), – Peter Mortensen Apr 26 '23 at 23:43
  • Note: The notation is different in Visual Studio Code (and probably others): `\u201C|\u201D` – Peter Mortensen Apr 27 '23 at 13:07

1 Answers1

1
cvNamedWindow( “Example2”, CV_WINDOW_AUTOSIZE );

Those are some seriously funny quotes. Try replacing them with standard quotes: " and recompile.

sarnold
  • 102,305
  • 22
  • 181
  • 238