Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Examples of Matlab to OpenCV conversions

Tags:

c++

opencv

matlab

From time to time I have to port some Matlab Code to OpenCV.

Almost always there is a way to do it and an appropriate function in OpenCV. Nevertheless its not always easy to find.

Therefore I would like to start this summary to find and gather some equivalents between Matlab and OpenCV.

I use the Matlab function as heading and append its description from Matlab help. Afterwards a OpenCV example or links to solutions are appreciated.

like image 887
FSaccilotto Avatar asked Sep 26 '13 07:09

FSaccilotto


People also ask

Can you use OpenCV with MATLAB?

OpenCV integrates with MATLAB® and Simulink® for collaborative development, simulation, testing, and implementation of image processing and computer vision based systems. Through interfaces using the OpenCV C++ API, MATLAB and Simulink support integration with OpenCV.

Which is better OpenCV or MATLAB?

Well, MATLAB is more convenient in developing and data presentation, however, OpenCV is much faster in execution. In the case of OpenCV, the speed ratio reaches more than 80 in some cases. However, OpenCV is comparatively harder to learn due to a lack of documentation and error handling codes.

How do I download OpenCV in MATLAB?

Select Get Add-ons from the Add-ons drop-down menu from the MATLAB® toolstrip. In the Add-Ons Explorer window, find and click the Computer Vision Toolbox Interface for OpenCV in Simulink support package, and then click Install. Type visionSupportPackages in a MATLAB Command Window and follow the prompts.


1 Answers

Repmat

Replicate and tile an array. B = repmat(A,M,N) creates a large matrix B consisting of an M-by-N tiling of copies of A. The size of B is [size(A,1)*M, size(A,2)*N]. The statement repmat(A,N) creates an N-by-N tiling.

B = repeat(A, M, N)

OpenCV Docs

Find

Find indices of nonzero elements. I = find(X) returns the linear indices corresponding to the nonzero entries of the array X. X may be a logical expression. Use IND2SUB(SIZE(X),I) to calculate multiple subscripts from the linear indices I.

Similar to Matlab's find

Conv2

Two dimensional convolution. C = conv2(A, B) performs the 2-D convolution of matrices A and B. If [ma,na] = size(A), [mb,nb] = size(B), and [mc,nc] = size(C), then mc = max([ma+mb-1,ma,mb]) and nc = max([na+nb-1,na,nb]).

Similar to Conv2

Imagesc

Scale data and display as image. imagesc(...) is the same as IMAGE(...) except the data is scaled to use the full colormap.

SO Imagesc

Imfilter

N-D filtering of multidimensional images. B = imfilter(A,H) filters the multidimensional array A with the multidimensional filter H. A can be logical or it can be a nonsparse numeric array of any class and dimension. The result, B, has the same size and class as A.

SO Imfilter

Imregionalmax

Regional maxima. BW = imregionalmax(I) computes the regional maxima of I. imregionalmax returns a binary image, BW, the same size as I, that identifies the locations of the regional maxima in I. In BW, pixels that are set to 1 identify regional maxima; all other pixels are set to 0.

SO Imregionalmax

Ordfilt2

2-D order-statistic filtering. B=ordfilt2(A,ORDER,DOMAIN) replaces each element in A by the ORDER-th element in the sorted set of neighbors specified by the nonzero elements in DOMAIN.

SO Ordfilt2

Roipoly

Select polygonal region of interest. Use roipoly to select a polygonal region of interest within an image. roipoly returns a binary image that you can use as a mask for masked filtering.

SO Roipoly

Gradient

Approximate gradient. [FX,FY] = gradient(F) returns the numerical gradient of the matrix F. FX corresponds to dF/dx, the differences in x (horizontal) direction. FY corresponds to dF/dy, the differences in y (vertical) direction. The spacing between points in each direction is assumed to be one. When F is a vector, DF = gradient(F)is the 1-D gradient.

SO Gradient

Sub2Ind

Linear index from multiple subscripts. sub2ind is used to determine the equivalent single index corresponding to a given set of subscript values.

SO sub2ind

backslash operator or mldivide

solves the system of linear equations A*x = B. The matrices A and B must have the same number of rows.

cv::solve

like image 55
3 revs, 2 users 89% Avatar answered Sep 21 '22 15:09

3 revs, 2 users 89%