slope
Usage
Calculates the gradient of an image, that is, the first-order differential.
Interface
1 | void kcv_slope_acc(const double *_src, size_t rows, size_t cols, double *_dst); |
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Input image. |
Not null. The size of the allocated memory is rows*cols*sizeof(double). |
Input |
rows |
Number of rows of the input image. |
(2, 16384] |
Input |
cols |
Number of columns of the input image. |
(2,16384] |
Input |
dst |
Output image. |
Not null. The size of the allocated memory is the same as that of src. |
Output |
Return Values
- Success: LITHO_IMG_STS_NO_ERR
- Failure: an error code
Error Codes
Error Code |
Description |
|---|---|
LITHO_IMG_STS_NULL_PTR_ERR |
The src or dst parameter has a null pointer. |
LITHO_IMG_STS_SIZE_ERR |
The value of rows or cols is less than or equal to 2. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <vector> #include <complex> #include "kp_litho_img.h" // Test function void test_kcv_slope_acc() { const size_t rows = 5; const size_t cols = 5; // Create an input image. std::vector<double> src(rows * cols); double src_data[5][5] = { {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 1, 0, 1, 0}, {0, 1, 1, 1, 0}, {0, 0, 0, 0, 0} }; for (size_t i = 0; i < rows; i++) { for (size_t j = 0; j < cols; j++) { src[i * cols + j] = src_data[i][j]; } } // Create an output image. std::vector<double> dst(rows * cols); // Call the function. cv::kcv_slope_acc(src.data(), rows, cols, dst.data()); // Print the result. std::cout << "Gradient Image:\n"; for (size_t i = 0; i < rows; i++) { for (size_t j = 0; j < cols; j++) { std::cout << dst[i * cols + j] << " "; } std::cout << "\n"; } } int main() { test_kcv_slope_acc(); return 0; } |
Output:
1 2 3 4 5 6 | Gradient Image: 0 0 0 0 0 0 0.707107 0 0.707107 0 0 0 0 0 0 0 0.707107 0 0.707107 0 0 0 0 0 0 |
Parent topic: Interface Definition