openCV C++

Hello, I've just started to learn opencv, so I used code that I found github but I have problem these lines. the program output is undeclared identifier.



1
2
3
4
5
6

cv::cvtColor(imgOriginal, imgGrayscale, CV_BGR2GRAY);


cv::namedWindow("imgOriginal", CV_WINDOW_AUTOSIZE);





this is full code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 // CannyStill.cpp

#include<opencv2/opencv.hpp>

#include<iostream>
#include<conio.h>           // may have to modify this line if not using Windows

///////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
	cv::Mat imgOriginal;        // input image
	cv::Mat imgGrayscale;       // grayscale of input image
	cv::Mat imgBlurred;         // intermediate blured image
	cv::Mat imgCanny;           // Canny edge image

	imgOriginal = cv::imread("image.png");          // open image

	if (imgOriginal.empty()) {                                  // if unable to open image
		std::cout << "error: image not read from file\n\n";     // show error message on command line
		_getch();                                               // may have to modify this line if not using Windows
		return(0);                                              // and exit program
	}

	cv::cvtColor(imgOriginal, imgGrayscale, CV_BGR2GRAY);       // convert to grayscale

	cv::GaussianBlur(imgGrayscale,          // input image
		imgBlurred,                         // output image
		cv::Size(5, 5),                     // smoothing window width and height in pixels
		1.5);                               // sigma value, determines how much the image will be blurred

	cv::Canny(imgBlurred,           // input image
		imgCanny,                   // output image
		82,                         // low threshold
		164);                       // high threshold

									// declare windows
	cv::namedWindow("imgOriginal", CV_WINDOW_AUTOSIZE);     // note: you can use CV_WINDOW_NORMAL which allows resizing the window
	cv::namedWindow("imgCanny", CV_WINDOW_AUTOSIZE);        // or CV_WINDOW_AUTOSIZE for a fixed size window matching the resolution of the image
															// CV_WINDOW_AUTOSIZE is the default
	cv::imshow("imgOriginal", imgOriginal);     // show windows
	cv::imshow("imgCanny", imgCanny);

	cv::waitKey(0);                 // hold windows open until user presses a key

	return(0);
}


the program output is undeclared identifier.

Is there a reason you decided not to tell us which identifier is undeclared?

Presumably, there's a header file that declares whatever the secret thing is, that you've forgotten to include.
> cv::cvtColor(imgOriginal, imgGrayscale, CV_BGR2GRAY);
> cv::namedWindow("imgOriginal", CV_WINDOW_AUTOSIZE);
Did you think about putting cv:: as namespace qualifiers on the enum symbols as well?

The symbols will be there somewhere, you just need the right qualifier.

@MikeyBoy sorry I forgot,


E0020	identifier "CV_BGR2GRAY" is undefined	
E0020	identifier "CV_WINDOW_AUTOSIZE" is undefined	
@salem I put namespace but it did not fix.
Looking at this example of use of OpenCV code, they're using different header files from the ones you've used:

http://www.swarthmore.edu/NatSci/mzucker1/opencv-2.4.10-docs/doc/tutorials/introduction/load_save_image/load_save_image.html
the header is correct opencv2/opencv.hpp will include everything else

¿what version of opencv?
for version 3 the flags should be
1
2
cv::COLOR_BGR2GRAY
cv::WINDOW_AUTOSIZE


edit: yes, version 3 includes the header opencv2/opencv.hpp
Last edited on
my opencv version is 4.1.0, should I use opencv version 3?
Last edited on
no
read the documentation that corresponds to your version (what I said about version 3 seems to be valid for version 4)
Last edited on
Topic archived. No new replies allowed.