@@ -27,6 +27,49 @@ cv::Mat read_image(std::string image_name) {
2727 return image;
2828}
2929
30+ constexpr int width = 10 ;
31+ constexpr int height = 10 ;
32+ constexpr int channel = 3 ;
33+
34+
35+ // Generate buffer for a matrix 10x10x3
36+ std::vector<uint8_t > generateBuffer () {
37+ std::vector<uint8_t > matrice;
38+ const int size = width * height * channel;
39+ matrice.reserve (size);
40+ for (int i = 0 ; i < size; ++i) {
41+ matrice.push_back (i);
42+ }
43+ return matrice;
44+ }
45+
46+
47+ // Generate matrix 10x10x3
48+ // Example of function that return a matrix by value
49+ cv::Mat generateMatrix () {
50+ const std::vector<uint8_t > buffer = generateBuffer ();
51+ return cv::Mat (buffer, true ).reshape (3 , {10 , 10 });
52+ }
53+
54+
55+ // Example of function that take a matrix as argument
56+ bool checkMatrixContent (const cv::Mat& mat) {
57+ // I don't compare buffer from the matrix with expected buffer to correctly manage slicing.
58+ const std::vector<uint8_t > expectedBuffer = generateBuffer ();
59+ bool match = true ;
60+ for (int j = 0 ; j < height; ++j) {
61+ for (int i = 0 ; i < width; ++i) {
62+ const cv::Vec3b values = mat.at <cv::Vec3b>(cv::Point (i,j));
63+ match &= values (0 ) == expectedBuffer[j * width * 3 + i * 3 + 0 ];
64+ match &= values (1 ) == expectedBuffer[j * width * 3 + i * 3 + 1 ];
65+ match &= values (2 ) == expectedBuffer[j * width * 3 + i * 3 + 2 ];
66+ }
67+ }
68+ return match;
69+ }
70+
71+
72+
3073cv::Mat passthru (cv::Mat image) {
3174 return image;
3275}
@@ -66,6 +109,12 @@ PYBIND11_MODULE(test_module, m) {
66109 m.def (" show_image" , &show_image, " A function that show an image" ,
67110 py::arg (" image" ));
68111
112+
113+ m.def (" generate_matrix" , &generateMatrix, " A function that generate a image" );
114+
115+ m.def (" check_matrix_content" , &checkMatrixContent, " A function that check the content a an image" ,
116+ py::arg (" image" ));
117+
69118 m.def (" passthru" , &passthru, " Passthru function" , py::arg (" image" ));
70119 m.def (" clone" , &cloneimg, " Clone function" , py::arg (" image" ));
71120
0 commit comments