opencv multi channel element access

typedef struct elem_ { float f1; float f2; } elem; elem data[9] = { 0.0f }; CvMat mat = cvMat(3, 3, CV_32FC2, data ); float f1 = CV_MAT_ELEM(mat, elem, row, col).f1; float f2 = CV_MAT_ELEM(mat, elem, row, col).f2; CV_MAT_ELEM(mat, elem, row, col).f1 = 1212.0f; CV_MAT_ELEM(mat, elem, row, col).f2 = 326.0f; Update : for OpenCV2.0 1. … Read more

Automatic calculation of low and high thresholds for the Canny operation in opencv

I stumbled upon this answer while I was searching for a way to automatically compute Canny’s threshold values. Hope this helps anyone who comes looking for a good method for determining automatic threshold values for Canny’s algorithm… If your image consists of distinct foreground and background, then the edge of foreground object can use extracted … Read more

Automatic contrast and brightness adjustment of a color photo of a sheet of paper with OpenCV

Contrast and brightness can be adjusted using alpha (α) and beta (β), respectively. These variables are often called the gain and bias parameters. The expression can be written as OpenCV already implements this as cv2.convertScaleAbs() so we can just use this function with user defined alpha and beta values. import cv2 image = cv2.imread(‘1.jpg’) alpha … Read more

How to read files in sequence from a directory in OpenCV?

If you’re using a recent version of OpenCV, you’re better off avoiding OS-specific methods: vector<string> fn; // std::string in opencv2.4, but cv::String in 3.0 string path = “e:/code/vlc/faces2/*.png”; cv::glob(path,fn,false); // Now you got a list of filenames in fn. (Ohh, and again, avoid deprecated C-API functions like cvLoad like hell, please!!)

OpenCV for Python 3.x under Windows [duplicate]

For those on Windows who don’t want to mess with building OpenCV 3.0 from source, Christoph Gohlke maintains Windows binaries for many Python packages, including OpenCV 3.0 with Python 3.x bindings! See here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv To install, just download the 64-bit or 32-bit .whl file appropriate for your system, then run pip install [filename]. Then the … Read more

Why OpenCV Using BGR Colour Space Instead of RGB

“The reason why the early developers at OpenCV chose BGR color format is probably that back then BGR color format was popular among camera manufacturers and software providers. E.g. in Windows, when specifying color value using COLORREF they use the BGR format 0x00bbggrr. BGR was a choice made for historical reasons and now we have … Read more