Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

can we create a 5*5 kernel np array in c++

I have made a 5*5 kernel using np array in python. how should I create it in c++?

kernel_sharpen_3 = np.array([[-1, -1, -1, -1, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, -1, -1, -1, -1]]) / 8
rescaled_image = cv2.filter2D(rescaled_image, -1, kernel_sharpen_3)

can we create a 5*5 kernel np array in c++

I have made a 5*5 kernel using np array in python. how should I create it in c++?

kernel_sharpen_3 = np.array([[-1, -1, -1, -1, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, -1, -1, -1, -1]]) / 8
rescaled_image = cv2.filter2D(rescaled_image, -1, kernel_sharpen_3)

Edit: Python output

C++ code:

float kdata[] = { -1, -1, -1, -1, -1,
                  -1, 2, 2, 2, -1,
                  -1, 2, 2, 2, -1,
                  -1, 2, 2, 2, -1,
                  -1, -1, -1, -1, -1 };

 Mat kernel_sharp(5, 5, CV_32F, kdata);

 kernel /= 8;

 filter2D(rescaled_image, rescaled_image, -1,kernel_sharp);

C++ Output:

can we create a 5*5 kernel np array in c++

I have made a 5*5 kernel using np array in python. how should I create it in c++?

kernel_sharpen_3 = np.array([[-1, -1, -1, -1, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, 2, 2, 2, -1],
                             [-1, -1, -1, -1, -1]]) / 8
rescaled_image = cv2.filter2D(rescaled_image, -1, kernel_sharpen_3)

Edit: Python output

C++ code:

float kdata[] k[] = { -1, -1, -1, -1, -1,
                  -1, 2, 2, 2, -1,
                  -1, 2, 2, 2, -1,
                  -1, 2, 2, 2, -1,
                  -1, -1, -1, -1, -1 };

 Mat kernel_sharp(5, 5, CV_32F, kdata);
k);

 kernel /= 8;

 filter2D(rescaled_image, rescaled_image, -1,kernel_sharp);

C++ Output: