Video cannot be openend using cv::VideoCapture

Make sure, opencv_ffmpeg300_64.dll can be found by the system, i.e, this DLL is in your .exe folder or it can be found by your PATH variable!

Access data from a cv::Mat

see here how to do this

Copy one matrix row to another matrix

You can read here that the following intuitive approach unfortunately does NOT work!

Mat m1,m2;
m1.row(i) = m2.row(j); // will not work

So what works? This one:

m1.row(0) = m2.row(0) + 0;

or alternatively:

m2.row(0).copyTo( m1.row(2) );

Here is an example:

        cv::Mat m1(3,3, CV_32FC1);
	m1 = 0;
	cv::Mat m2(3,3, CV_32FC1);
	m2 = 3;
	std::cout << "m1";
	std::cout << m1 << std::endl;
	std::cout << "m2";
	std::cout << m2 << std::endl;
	m1.row(0) = m2.row(0) + 0;  // does work
	std::cout << "\ncurrent state of m1" << std::endl;
	std::cout << m1 << std::endl;
	m2.row(0).copyTo( m1.row(2) ); // does work
	std::cout << "\ncurrent state of m1" << std::endl;
	std::cout << m1 << std::endl;


m1[0, 0, 0;
  0, 0, 0;
  0, 0, 0]
m2[3, 3, 3;
  3, 3, 3;
  3, 3, 3]

current state of m1
[3, 3, 3;
  0, 0, 0;
  0, 0, 0]

current state of m1
[3, 3, 3;
  0, 0, 0;
  3, 3, 3]


Learning OpenCV

Building the current OpenCV development branch

  • install TortoiseGit
  • clone the repository
  • install CMake and start Cmake GUI
  • set “Where is the source code” folder
  • set “Where to build the binaries” folder (use the same as the source folder, ignore the warning)
  • click “Configure” + choose Visual Studio 2010 + press “Finish”

  • select build options and click “Configure” again
  • click “Generate”: this will create a OpenCV.sln file

  • open the OpenCV.sln with Visual Studio
  • choose Debug configuration and start building
  • after ~10min:

  • choose Release configuration and start building
  • build results are in
    • W:\20_src\90_thirdparty_libs\opencv\mybuild\bin\Debug (.exe +.dll files) and Release, respectively
    • W:\20_src\90_thirdparty_libs\opencv\mybuild\lib\Debug (.lib files) and Release, respectively

For further details see the OpenCV InstallGuide.

How to get the latest release version of OpenCV for Visual Studio 2010 without building it?

The nice thing is, you do not even need to compile it by your own!

Make sure, you add the path with all of OpenCV's DLLs to your PATH environment variable. On my computer it was the path


Image filtering with OpenCV

Two ways to do so. Read this.

  • C++ style: filter2D() method
  • C style: cvFilter2D() method


imshow() magically also visualize matrices. How? Read here:

void imshow(const string& winname, const Mat& image)

    Displays the image in the specified window

        winname – Name of the window.
        image – Image to be shown.

The function imshow displays the image in the specified window. If the window was created with the CV_WINDOW_AUTOSIZE flag then the image is shown with its original size, otherwise the image is scaled to fit in the window. The function may scale the image, depending on its depth:

    If the image is 8-bit unsigned, it is displayed as is.
    If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].
    If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].

It took me 1 hour to get my old project correctly linking with the new OpenCV 2.2 lib. Here is my .lib list with which I managed to do it:


Color histogram computation

OpenCV's new Detector/Descriptor/Matcher framework

Cross-Check Descriptor Matching

Using OpenCV this can be done as explained here:

BruteForceMatcher<L2<float> > descriptorMatcher;
vector<DMatch> filteredMatches12, matches12, matches21;
descriptorMatcher.match( descriptors1, descriptors2, matches12 );
descriptorMatcher.match( descriptors2, descriptors1, matches21 );
for( size_t i = 0; i < matches12.size(); i++ )
    DMatch forward = matches12[i];
    DMatch backward = matches21[forward.trainIdx];
    if( backward.trainIdx == forward.queryIdx )
        filteredMatches12.push_back( forward );

OpenCV conversions

Linear algebra with OpenCV

public/opencv.txt · Last modified: 2014/04/01 15:44 (external edit) · []
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki