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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With