initialize an OpenCV Mat with an 2D array

Originally, I used the mnemonic from OpenCV online guides: Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP) But I didn’t understand what the document meant by size_t step=AUTO_STEP. And this means that I can omit the step argument with which OpenCV will automatically choose AUTO_STEP I’ve tried and this works: A = Mat(2, 5, CV_32FC1, … Read more

What is the difference between UMat and Mat in OpenCV?

Perhaps section 3 of this document will help: [link now broken] https://software.intel.com/sites/default/files/managed/2f/19/inde_opencv_3.0_arch_guide.pdf Specifically, section 3.1: A unified abstraction cv::UMat that enables the same APIs to be implemented using CPU or OpenCL code, without a requirement to call OpenCL accelerated version explicitly. These functions use an OpenCL-enabled GPU if exists in the system, and automatically switch … Read more

Extracting HoG Features using OpenCV

You can use hog class in opencv as follows HOGDescriptor hog; vector<float> ders; vector<Point> locs; This function computes the hog features for you hog.compute(grayImg, ders, Size(32, 32), Size(0, 0), locs); The HOG features computed for grayImg are stored in ders vector to make it into a matrix, which can be used later for training. Mat … Read more

Detect semicircle in OpenCV

Use houghCircle directly on your image, don’t extract edges first. Then test for each detected circle, how much percentage is really present in the image: int main() { cv::Mat color = cv::imread(“../houghCircles.png”); cv::namedWindow(“input”); cv::imshow(“input”, color); cv::Mat canny; cv::Mat gray; /// Convert it to gray cv::cvtColor( color, gray, CV_BGR2GRAY ); // compute canny (don’t blur with … Read more

OpenCV / SURF How to generate a image hash / fingerprint / signature out of the descriptors?

The feature data you mention (position, laplacian, size, orientation, hessian) is insufficient for your purpose (these are actually the less relevant parts of the descriptor if you want to do matching). The data you want to look at are the “descriptors” (the 4th argument): void cvExtractSURF(const CvArr* image, const CvArr* mask, CvSeq** keypoints, CvSeq** descriptors, … Read more

What is the difference between the fundamental, essential and homography matrices?

Without any extra assumption on the world scene geometry, you cannot affirm that there is a projective transformation between the two views. This is only true if the scene is planar. A good reference on that topic is the book Multiple View Geometry in Computer Vision by Hartley and Zisserman. If the world scene is … Read more

Matrix multiplication in OpenCV

You say that the matrices are the same dimensions, and yet you are trying to perform matrix multiplication on them. Multiplication of matrices with the same dimension is only possible if they are square. In your case, you get an assertion error, because the dimensions are not square. You have to be careful when multiplying … Read more

OpenCV Mat element types and their sizes

Developing from Miki’s answer, In OpenCV 3 definition has moved to modules/core/include/opencv2/core/traits.hpp, where you can find: /** @brief A helper class for cv::DataType The class is specialized for each fundamental numerical data type supported by OpenCV. It provides DataDepth<T>::value constant. */ template<typename _Tp> class DataDepth { public: enum { value = DataType<_Tp>::depth, fmt = DataType<_Tp>::fmt … Read more