Ask Your Question
0

Window name as unidentified identifier in simple program

asked 2015-05-17 03:46:03 -0600

galaxyeagle gravatar image

I am a beginner in OpenCV and VC++. I wrote the below introductory program to display a picture :

#include "stdafx.h"
#include <highgui.h>
int main(int argc, char** argv) {
IplImage* img = cvLoadImage("C:\\flower.jpg",1);
cvNamedWindow(“Example1”, CV_WINDOW_AUTOSIZE);
cvShowImage(“Example1”, img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow(“Example1”);
  }

In this , I'm getting the following error :

Error   1   error C2065: '“Example1”' : undeclared identifier   C:\opencv_examples\opencv_sanitytest\ex1\ex1\ex1.cpp    5   1   ex1
Error   2   error C2065: '“Example1”' : undeclared identifier   C:\opencv_examples\opencv_sanitytest\ex1\ex1\ex1.cpp    6   1   ex1
Error   3   error C2065: '“Example1”' : undeclared identifier   C:\opencv_examples\opencv_sanitytest\ex1\ex1\ex1.cpp    9   1   ex1
4   IntelliSense: identifier "“Example1”" is undefined  c:\opencv_examples\opencv_sanitytest\ex1\ex1\ex1.cpp    5   16  ex1

I think that some header files are missing perhaps. Any help would be appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2015-05-17 03:49:54 -0600

berak gravatar image

updated 2015-05-17 03:55:45 -0600

oh, please, you must not use opencv's arcane c-api, but the c++ one:

#include <opencv2/opencv.hpp>
int main(int argc, char** argv) {

    cv::Mat img = cv::imread("C:\\flower.jpg",1);
    cv::namedWindow("Example1", cv::WINDOW_AUTOSIZE);
    cv::imshow("Example1", img);
    cv::waitKey(0);
    return 0;
 }

also, it has to be "Example1" , not “Example1”

edit flag offensive delete link more

Comments

yea, that error is avoided. However two more errors have come :

Error   1   error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'   C:\opencv_examples\opencv_sanitytest\ex1\ex1\opencv_highgui300.lib(window.obj)  ex1
    2   IntelliSense: PCH warning:  c:\opencv_examples\opencv_sanitytest\ex1\ex1\ex1.cpp    1   1   ex1

I have an x86 machine but chose x64 as the solution platform as there was no x86 option

galaxyeagle gravatar imagegalaxyeagle ( 2015-05-17 05:17:12 -0600 )edit

ok, when I changedall imported lib and .h files from build\x64 folder, the error 1 above is removed but

Error   2   error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?   C:\opencv_examples\opencv_sanitytest\ex1\ex1\ex1.cpp    10  1   ex1

is now coming. If I include the stdafx.h, a huge number of other errors come. Please help

galaxyeagle gravatar imagegalaxyeagle ( 2015-05-17 05:29:40 -0600 )edit
  • if you build for x64, you need to link x64 libs, not the x86 ones.
  • please avoid precompiled headers and stdafx in general.

start with an empty project (not with a 'console' or 'gui' one.)

berak gravatar imageberak ( 2015-05-17 05:32:19 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-05-17 03:46:03 -0600

Seen: 2,391 times

Last updated: May 17 '15