Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv python code equivalent in C++

Tags:

c++

python

opencv

I have this piece of code that works fine on Python. I want to do the same thing in C/C++ but i do not understand how works kernel in C++:

kernel = np.ones((3,3),np.uint8)
opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel, iterations = 2)

kernel and opening are Mat objects.

I have also

mat1=np.uint8(mat1)

I do not understand what is this np prefix.

like image 504
testpresta Avatar asked Sep 27 '22 01:09

testpresta


1 Answers

This line:

kernal = np.ones((3,3)), np.uint8)

is the same as doing this in C++:

Mat m = Mat(3, 3, CV_8UC1, cv::Scalar(1));

As MaruisSiuram said the np prefix is for the numpy library, this is not used in C++ you can just use the OpenCV Matrix container.

This line:

mat1=np.uint8(mat1)

is casting mat1 to the type uint8 which can be done like so:

mat1.convertTo(mat1, CV_8UC1);
like image 152
GPPK Avatar answered Oct 10 '22 12:10

GPPK