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

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

Multi otsu(multi-thresholding) with openCV

To extend Otsu’s thresholding method to multi-level thresholding the between class variance equation becomes: Please check out Deng-Yuan Huang, Ta-Wei Lin, Wu-Chih Hu, Automatic Multilevel Thresholding Based on Two-Stage Otsu’s Method with Cluster Determination by Valley Estimation, Int. Journal of Innovative Computing, 2011, 7:5631-5644 for more information. http://www.ijicic.org/ijicic-10-05033.pdf Here is my C# implementation of Otsu … Read more

How to use Bazel to build project uses OpenCV [closed]

There are a couple of options. The easiest way is probably to install locally in the way the OpenCV site recommends: git clone https://github.com/Itseez/opencv.git cd opencv/ mkdir build install cd build cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/path/to/opencv/install .. make install Then add the following to your WORKSPACE file: new_local_repository( name = “opencv”, path = “/path/to/opencv/install”, build_file … Read more

Camera pose estimation (OpenCV PnP)

I solved this a while ago, apologies for the year delay. In the python OpenCV 2.1 I was using, and the newer version 3.0.0-dev, I have verified that to get the pose of the camera in the global frame you must: _, rVec, tVec = cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs) Rt = cv2.Rodrigues(rvec) R = Rt.transpose() … Read more

OpenCV floodfill with mask

All zero-valued pixels in the same connected component as the seed point of the mask are replaced by the value you specify. This value must be added to the flags parameter, left-shifted by 8 bits: uchar fillValue = 128; cv::floodFill(img, mask, seed, cv::Scalar(255) ,0, cv::Scalar(), cv::Scalar(), 4 | cv::FLOODFILL_MASK_ONLY | (fillValue << 8)); A simple, … Read more

cv2.imshow() function is opening a window that always says not responding – python opencv

You missed one more line: cv2.waitKey(0) Then the window shows the image until you press any key on keyboard. Or you can pass as following: cv2.waitKey(1000) cv2.destroyAllWindows() Here, window shows image for 1000 ms, or 1 second. After that, the window would disappear itself. But in some cases, it won’t. So you can forcefully destroy … Read more

Filling gaps in shape edges

Another, simpler way, that will probably translate better into OpenCV as it uses convolution rather than sequential Perl/C code. Basically set all the black pixels to value 10, and all the white pixels to value 0, then convolve the image with the following 3×3 kernel: 1 1 1 1 10 1 1 1 1 Now, … Read more