Ask Your Question

dumbledad's profile - activity

2020-07-01 14:37:31 -0500 received badge  Notable Question (source)
2019-02-07 18:01:13 -0500 received badge  Notable Question (source)
2018-06-05 03:07:17 -0500 received badge  Notable Question (source)
2018-05-31 03:59:16 -0500 received badge  Popular Question (source)
2016-12-16 09:56:14 -0500 received badge  Popular Question (source)
2016-08-01 05:44:04 -0500 received badge  Popular Question (source)
2014-12-09 13:57:50 -0500 marked best answer const float union ptr in Bradski & Kaehler's “Learning OpenCV” Example 3-9

In "Learning OpenCV" by Gary Bradski & Adrian Kaehler there is a section on the CvMat matrix structure that contains the following example code (it is Example 3-9: Summing all the elements in a single-channel matrix)

float sum( const CvMat* mat ) { 

  float s = 0.0f;
  for(int row=0; row<mat->rows; row++ ) {
    const float* ptr = (const float *)(mat->data.ptr + row * mat->step);
    for(int col=0; col<mat->cols; col++ ) {
      s += *ptr++;
    }
  }
  return( s );
}

There are a couple of things I do not understand about this code, but they may be the result of me not using C for many many years rather than OpenCV questions.

  1. Why const? Since ptr is incremented later in the function I do not understand why it is declared const.

  2. Why .ptr? The authors point out that "When computing the pointer into the matrix, remember that the matrix element data is a union. Therefore, when de-referencing this pointer, you must indicate the correct element of the union in order to obtain the correct pointer type." So why not use the union member fl with type float* so that the line of code would be

    float* ptr = mat->data.fl + row * mat->step;
    

instead of taking ptr with type uchar* and requiring an additional cast?

2013-10-28 07:59:41 -0500 answered a question Why would video files not open in OpenCV (both C & C++ APIs)?

It appears that, following advice from Tobias Senst on a stackoverflow answer, I needed to build OpenCV on my local machine rather than rely on the DLLs that are provided with the standard distribution. It has been a headache to get OpenCV to build locally (see here, here, and here) but now that I reference to a copy of OpenCV 2.4.6 that was built on this machine I can open the video files.

I have no idea why this works, why it is not mentioned in the requirements, why others are not more frequently having this problem, nor what is failing with the default deployment, but at least I have it fixed.

2013-10-28 03:58:31 -0500 commented question Where are the correct include directories for OpenCV projects using a local build / self-build of OpenCV?

Thanks @berak, that works. If you copy that advice into an answer I'll mark it as such.

2013-10-27 13:12:45 -0500 received badge  Student (source)
2013-10-27 05:39:58 -0500 asked a question Where are the correct include directories for OpenCV projects using a local build / self-build of OpenCV?

I'm trying to debug a frustrating problem whereby I cannot load video files in OpenCV. One suggestion is to abandon the OpenCV pre-built libraries and instead build OpenCV on the same machine as the failing project.

That is what I am now trying to do.

In the OpenCV Quick Start about how to build applications with OpenCV inside the Microsoft Visual Studio one important step is to add the additional include directories to the project property sheet by opening the project's property pages, navigating to Configuration Properties -> C/C++ -> General -> Additional Include Directories. Using the pre-built distribution I am advised to add the directory C:\OpenCV2.4.6\build\include and indeed inside that directory are sub-directories opencv and opencv2. One of the files my project (like most OpenCV projects) will need is highgui.hpp from the line

#include "opencv2/highgui/highgui.hpp"

In the pre-built OpenCV distribution highgui.hpp ends up in C:\OpenCV2.4.6\build\include\opencv2\highgui and is thus correctly picked up at compile time because of the additional include directory.

Having generated with CMake and built with Visual Studio 2012 the latest version of OpenCV on my machine (though perhaps unsuccessfully) I cannot find highgui.hpp. It is not in C:\Users\timregan\Documents\GitHub\opencv\build\include (in fact there are no sub-directories opencv nor opencv2 in there). It is in C:\opencv-2.4\modules\highgui\include\opencv2\highgui.

What step, flag, etc. did I omit in order to generate place it correctly on my machine? Why are the opencv and opencv2 sub-directories missing completely from C:\Users\timregan\Documents\GitHub\opencv\build\include after I have generated and built OpenCV?

(N.B. I'm using CMake 2.8.12 and Visual Studio 2012 on a Windows 8 machine.)

2013-10-27 05:09:29 -0500 asked a question 404 Not Found from bug reporting site

The OpenCV homepage includes a link titled "Report a bug" to http://code.opencv.org/projects/OpenCV/wiki/WikiStart#Creating-new-tickets. I get the HTTP '404 Not Found' error from that URL, as I do from http://code.opencv.org/projects/OpenCV/wiki/WikiStart and from http://code.opencv.org/ (which redirects to http://code.opencv.org/projects/opencv/wiki)

Where should we report suspected bugs?

2013-10-27 04:32:50 -0500 asked a question Plethora of CMake errors about absolute and relative destinations

Having downloaded the latest OpenCV source code from github on the 26th of October 2013 I have run CMake (cmake-gui 2.8.12) first 'Configue' and then 'Generate'. Generating the build directory throws a bunch of errors, starting with Error in generation process, project files may be invalid:

error screenshot

The first group I think it is safe for me to ignore, they look like this:

CMake Warning (dev) in apps/haartraining/CMakeLists.txt:
Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link interface. Run "cmake --help-policy CMP0022" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Static library target "opencv_haartraining_engine" has a
INTERFACE_LINK_LIBRARIES property. This should be preferred as the source of the link interface for this library. Ignoring the property and using the link implementation as the link interface instead. This warning is for project developers. Use -Wno-dev to suppress it.

But the last list of errors has me more worried. What are these? Should I act on them? How should I fix them?

CMake Error: install(EXPORT "OpenCVModules") given absolute DESTINATION "/lib" but the export references an installation of target "opencv_core" which has relative DESTINATION "lib".

CMake Error: install(EXPORT "OpenCVModules") given absolute DESTINATION "/lib" but the export references an installation of target "opencv_core" which has relative DESTINATION "bin".

CMake Error: install(EXPORT "OpenCVModules") given absolute DESTINATION "/lib" but the export references an installation of target "opencv_flann" which has relative DESTINATION "lib".

CMake Error: install(EXPORT "OpenCVModules") given absolute DESTINATION "/lib" but the export references an installation of target "opencv_flann" which has relative DESTINATION "bin".

[...]

CMake Error: install(EXPORT "OpenCVModules") given absolute DESTINATION "/lib" but the export references an installation of target "opencv_videostab" which has relative DESTINATION "lib".

CMake Error: install(EXPORT "OpenCVModules") given absolute DESTINATION "/lib" but the export references an installation of target "opencv_videostab" which has relative DESTINATION "bin".

cmake-gui screenshot with errors showing

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

I wonder if the problem here is that the CMake value CMAKE_USE_RELATIVE_PATHS which is present when running CMake on the code for release 2.4.6 is not present when running CMake on the latest code. If so, what is the fix?

(N.B. I have added this as an OpenCV issue/bug.)

2013-10-25 15:29:00 -0500 commented question Why would video files not open in OpenCV (both C & C++ APIs)?

It has opencv_ffmpeg246.dll in there already, should that do?

2013-10-25 12:10:27 -0500 asked a question Why would video files not open in OpenCV (both C & C++ APIs)?

I am swapping from EmguCV to OpenCV so that I can try some of the OpenCV functions that are not yet wrapped by EmguCV. However I'm failing to load my simple test video file, which loads without issue in EmguCV. Looking at the EmguCV source code I notice that they call the OpenCV C functions rather than C++ to initialise capture from a file (or a webcam) so I wrote the following test code (with help from stackoverflow). Here is my simple code

int _tmain()
{
    string filename = "sample.wmv";
    if (!FileExists(filename.c_str))
    {
        cout << "File does not exist" << endl;  
        return -1;
    }
    else
    {
        cout << "File exists" << endl;
        VideoCapture cap (filename);
        if(!cap.isOpened())
        {
            cout << "Failed to open file in OpenCV C++" << endl;
            //Trying C API too just-in-case
            CvCapture* capture = cvCreateFileCapture(filename.c_str());
            if (!capture)
            {
                cout << "Failed to open file in OpenCV C" << endl;  
            }
            else
            {
                //Grab frames and do stuff
                cvReleaseCapture(&capture);
            }
            return -1;
        }
        else
        {
            //Grab frames and do stuff
        }
    }
    return 0;
}

When I run this I get the output

File exists

Failed to open file in OpenCV C++

Failed to open file in OpenCV C

This happens regardless of the file, i.e. it happens for "sample.wmv", "sample.avi", and even one of the OpenCV sample files "tree.avi".

Why? What is going on?

(I'm running OpenCV 2.4.6 on a Windows 8 and a Windows 8.1 machine.)

2013-10-17 18:19:54 -0500 asked a question 'min (& max) not a member of std' errors when building OpenCV 2.4.6 on Windows 8 for Visual Studio 2012

I'm trying to build OpenCV 2.4.6 on Windows 8 in Visual Studio 2012. Having downloaded the source from https://github.com/Itseez/opencv I generate (leaving the default configuration) using cmake and then load the resulting file ALL_BUILD.vcxproj into Visual Studio 2012. I then try to build it. Several of the modules do indeed build (e.g. core, flann, imgproc, ...) but I am trying to build highgui so that I can use the PDB file for debugging my code (which fails to open a video file). The build errors start with this and many similar errors:

error C2039: 'max' : is not a member of 'std' C:\OpenCV2.4.6\3rdparty\openexr\Imath\ImathMatrixAlgo.cpp 1094 1 IlmImf

One fix for errors like this (e.g. in this answer on StackOverflow) is to add #include <algorithm> to the failing files. I tried that on a few files and it seems to work but I'm nervous about locally changing the source for a popular library. It must build on Windows (you can download the binaries, though not the PDB files, from the OpenCV sourceforge site) so I would like to understand how to build it on my machine without changing the source.

Am I missing something out in the configuration step? Is there some path setting etc. missing on my machine? Why am I getting these errors and how should I fix them?

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

Looking at the directory path this appears to be a problem with one of the 3rd party dependencies, OpenEXR. Looking on Github it appears to be version 1.7.1 of OpenEXR that is used in OpenCV 2.4.6. The instructions in the OpenCV's Quick Start Installation on Windows state:

  • In case of the Eigen library it is again a case of download and extract to the D:/OpenCV/dep directory.
  • Same as above with OpenEXR.

so I downloaded the OpenEXR 1.7.1 source code release and extracted the resulting files putting the directory openexr-1.7.1 into C:\OpenCV2.4.6\dep.

Then I ran cmake and tried to build the resulting Visual Studio solution. Sadly I see the same errors.

2013-10-17 15:40:17 -0500 asked a question How & where to add debugging symbols for Visual C++ OpenCV project

I've set up an OpenCV C++ project in Visual Studio 2012. To get it working I have use various project property pages to

  1. Additional Include Directories: $(SolutionDir)..\Libs\OpenCV\2.4.6\include
  2. Additional Library Directories: $(SolutionDir)..\Libs\OpenCV\2.4.6\$(Platform)\$(Configuration)
  3. Additional Dependencies: various files including opencv_highgui246d.dll
  4. Post-Build Event, Command Line: copies over the DLLs and lib files and some sample content thus:

    xcopy /y $(SolutionDir)..\Libs\OpenCV\2.4.6\$(Platform)\$(Configuration)*.dll $(ProjectDir)$(Platform)\$(Configuration)\ xcopy /y $(SolutionDir)..\Libs\OpenCV\2.4.6\$(Platform)\$(Configuration)*.lib $(ProjectDir)$(Platform)\$(Configuration)\ xcopy /y $(ProjectDir)opencv-logo.jpg $(ProjectDir)$(Platform)\$(Configuration)\ xcopy /y $(ProjectDir)sample.wmv $(ProjectDir)$(Platform)\$(Configuration)\

The lines of code I'm trying to debug are more-or-less the same as those in the sample code given for the VideoCapture OpenCV class here: http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html

VideoCapture cap(0); // open the default camera
if(!cap.isOpened())  // check if we succeeded
    return -1;

but I am opening a file

VideoCapture cap ("sample.wmv");
if (FileExists("sample.wmv"))
{
    OutputDebugString("File exists\n");
}
else
{
    OutputDebugString("File does not exist\n");
}
if(!cap.isOpened())
{
    cout <<"Failed to open camera" << endl;
    OutputDebugString("Failed to open camera\n");   
    return -1;
}

Something's going wrong so I want to check what the properties are on cap by setting a breakpoint on the line if(!cap.isOpened()). But if I try to examine cap in the locals window in Visual Studio 2012 I get the error:

"Information not available, no symbols loaded for opencv_highgui246d.dll"

I'm unfamiliar with setting up C++ projects in Visual Studio (I've been using mostly C# for years now); what do I need to do to enable this debugging? Do I have to build OpenCV myself (and if so what output should I use where) or are there more files I can copy over and include in my build?

2013-10-14 11:14:04 -0500 received badge  Supporter (source)
2013-10-14 09:45:26 -0500 commented answer Why is the blob tracking code 'legacy'? What's replaced it?

Thanks; detection's half the job, CvBlobTrackerAuto tracked them too. Is this now spread across classes?

2013-10-14 07:19:01 -0500 asked a question Why is the blob tracking code 'legacy'? What's replaced it?

I was struggling to find where in the OpenCV API the blob tracking code that EmguCV uses is. I think I have found it religated to legacy code: https://github.com/Itseez/opencv/blob/master/modules/legacy/src/blobtrackingauto.cpp

Why is it legacy code and where is any blob tracking code APIs that have replaced it?

2013-10-10 06:57:42 -0500 commented question What are the five arguments in the 'How to build applications with OpenCV inside the Microsoft Visual Studio' sample code?

berak - sure it's not just a copy-and-paste issue and this was the intended sample code: https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp

2013-10-10 05:46:27 -0500 asked a question What are the five arguments in the 'How to build applications with OpenCV inside the Microsoft Visual Studio' sample code?

I'm following the instructions in How to build applications with OpenCV inside the Microsoft Visual Studio but I'm confused by the sample code.

When the author calls the built sample he or she uses the single argument exampleImage.jpg either supplied on the command line or set in the Property Pages, as I have done here

Setting Command Arguments in the property pages screenshot

But the first few lines of main in the sample code are:

help();
if (argc != 5)
{
    cout << "Not enough parameters" << endl;
    return -1;
}

i.e. the application requires five arguments. If the function requires five arguments then what are they and why is only one supplied? If the function only requires one argument then what is this checking code for?

========== EDIT 1 ==========

Actually the more I look at it the more confused I am by the sample code. The tutorial sample code purports to be about loading and displaying an image, but looking at the code listing it is all about videos and Gaussian functions. This tutorial is supposed to be the introduction to getting started with Visual Studio, linked to from the primary OpenCV Quick Start page, I cannot be the first person to try the code. Why is it so different from what it purports to be?

========== EDIT 2 ==========

I've submitted this as a documentation bug.

2013-10-10 05:12:03 -0500 commented question CAP_PROP_FRAME_WIDTH undeclared in 'How to build applications with OpenCV inside the Microsoft Visual Studio' sample code

Moster, that didn't work. But berak, that works. If you want to add it as an answer I'll mark it as such.

2013-10-09 11:53:26 -0500 edited question CAP_PROP_FRAME_WIDTH undeclared in 'How to build applications with OpenCV inside the Microsoft Visual Studio' sample code

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 (are) 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 (are) declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?