2

I'm following the instructions in How to build applications with OpenCV inside the Microsoft Visual Studio but I'm getting errors from the sample code:

  • error C2065: 'CAP_PROP_FRAME_WIDTH' : undeclared identifier
  • error C2065: 'CAP_PROP_FRAME_HEIGHT' : undeclared identifier
  • error C2065: 'CAP_PROP_FRAME_COUNT' : undeclared identifier

I think the identifiers that are undeclared should be declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?

Here are the steps I have taken.

  1. I've unpacked the OpenCV (Version 2.4.6) files into C:\OpenCV, run setx -m OPENCV_DIR C:\OpenCV\Build\x64\vc11 from an elevated command prompt and added %OPENCV_DIR%\bin to my path (following instructions in Installation in Windows). Then using the Property pages (View -> Property Pages or Shift-F4) set to 'All Configurations'

  2. I've added $(OPENCV_DIR)\..\..\include to my C/C++ Additional Include Directories

VS12 Property Page Screenshot

  1. I've added $(OPENCV_DIR)\lib to the linker Additional Library Directories

VS12 Property Page Screenshot

  1. I've cut-an-paste the directory listing of the lib files in C:\OpenCV\build\x64\vc11\lib into my input Additional Dependencies

VS12 Property Page Screenshot

  1. I've copied the sample code from the article into a new C++ console app (with ATL). I had to change one line in the template code from int _tmain(int argc, _TCHAR* argv[]) to int _tmain(int argc, char* argv[])

I think the identifiers that are undeclared should be (are) declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?

Other people having similar issues getting this sample code working in the How to build applications with OpenCV inside the Microsoft Visual Studio note seem to fall over with link errors (e.g. here and here) but I am getting past the linker.

========== EDIT ==========

There appear to be more insurmountable difficulties with the sample code. It is documented as a simple example to load and display an image whose path is supplied as the sole argument to main, while the code listing itself is video code requiring four command line arguments (i.e. it first checks and stops if argc != 5). I've submitted a documentation bug. I think the sample code listing should have been be taken from this: https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp

Community
  • 1
  • 1
dumbledad
  • 16,305
  • 23
  • 120
  • 273
  • I have also asked this on the OpenCV forum, I hope that's not poor etiquette http://answers.opencv.org/question/22190/cap_prop_frame_width-undeclared-in-how-to-build/ – dumbledad Oct 09 '13 at 16:49
  • 1
    I do not know if this might be a problem here but you use x64 binaries for x86 configuration. You have set C:\OpenCV\Build\x64\vc11, note that \x64\ prefix. Edit your path to C:\OpenCV\Build\x86\vc11 if you want to run code on 32-bit architecture machines. Otherwise create new Active Solution Platform under Configuration Manager > Active Solution Platfrom > > x64 – OpenMinded Oct 09 '13 at 17:18
  • @OpenMinded you are right. Once I fixed the issue that the question is about using [morynicz's answer](http://stackoverflow.com/a/19288246/575530) I then get a link error: `error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'` which your suggestion fixes. – dumbledad Oct 10 '13 at 10:21

2 Answers2

9

Try with CV_CAP_ or cv::CAP_... It looks like there were some changes aiming to improve consistency of constants in OpenCV...

morynicz
  • 2,322
  • 2
  • 20
  • 34
  • 1
    That's it, thanks @morynicz. Over on the OpenCV forum berak notes that it looks like there was some mix-up (in the tutorial) with the constants and suggests I use CV_CAP_PROP_* in 2.4.6 or cv::CAP_PROP_* in 3.0 – dumbledad Oct 10 '13 at 10:24
0

I am using the opencv 2.4.6 and this has helped me do the trick

change CAP_PROP_FRAME_WIDTH into CV_CAP_PROP_FRAME_WIDTH
change CAP_PROP_FRAME_HEIGHT into CV_CAP_PROP_FRAME_HEIGHT
change CAP_PROP_FRAME_COUNT into CV_CAP_PROP_FRAME_COUNT

and similarly if there are any other cap prop keywords into cv cap prop keywords

try this.

divyanshm
  • 6,600
  • 7
  • 43
  • 72