Configuring an c++ OpenCV project with Cmake

First: create a folder Project containing two subfolders src and include, and a file called CMakeLists.txt. Second: Put your cpp inside the src folder and your headers in the include folders. Third: Your CMakeLists.txt should look like this: cmake_minimum_required(VERSION 2.8) PROJECT (name) find_package(OpenCV REQUIRED ) set( NAME_SRC src/main.cpp ) set( NAME_HEADERS include/header.h ) INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include … Read more

How to capture the desktop in OpenCV (ie. turn a bitmap into a Mat)?

After MUCH trial and error, I managed to write a function to do it. here it is for anyone else who might want it: #include “stdafx.h” #include “opencv2/core/core.hpp” #include “opencv2/imgproc/imgproc.hpp” #include <opencv2/highgui/highgui.hpp> #include <Windows.h> #include <iostream> #include <string> using namespace std; using namespace cv; Mat hwnd2mat(HWND hwnd){ HDC hwindowDC,hwindowCompatibleDC; int height,width,srcheight,srcwidth; HBITMAP hbwindow; Mat src; … Read more

Computing camera pose with homography matrix based on 4 coplanar points

If you have your Homography, you can calculate the camera pose with something like this: void cameraPoseFromHomography(const Mat& H, Mat& pose) { pose = Mat::eye(3, 4, CV_32FC1); // 3×4 matrix, the camera pose float norm1 = (float)norm(H.col(0)); float norm2 = (float)norm(H.col(1)); float tnorm = (norm1 + norm2) / 2.0f; // Normalization value Mat p1 = … Read more

How to define the markers for Watershed in OpenCV?

First of all: the function minMaxLoc finds only the global minimum and global maximum for a given input, so it is mostly useless for determining regional minima and/or regional maxima. But your idea is right, extracting markers based on regional minima/maxima for performing a Watershed Transform based on markers is totally fine. Let me try … Read more