isContinuous() 判定 矩阵 row 是否是连续存储 | 笔记

网友投稿 581 2022-05-30

isContinuous() | 判定 矩阵 row 是否是连续存储

Reports whether the matrix is continuous or not.— isContinuous() 方法原文档

判定 矩阵 row 是否是连续存储,是连续存储,那么在进行矩阵元素操作时,一些处理 function 就可以把整个矩阵元素 视为 width * height 的一维向量 【long single-row vectors】

对应处理方法,在对 Mat 进行运算变换之后, 返回 Mat 的 clone() ;

isContinuous() 测试验证

该代码参考的博文

测试代码如下

# 实际用不到这么多 头文件 #include #include #include #include #include #include #include using namespace cv; using namespace std; // 判定 Mat 连续方法测试 void isContinuousTest() { Mat src = imread("eat.jpg");//原始图像是256*256 cv::imshow("src", src); printf("---src.isContinuous=%d", src.isContinuous()); printf("\n");//直接imread的Mat是连续的 cv::Rect rect(1, 1, 100, 100); cv::Mat crop_img = src(rect);//裁剪后的图像是不连续的 cv::imshow("crop_img", crop_img); printf("---crop_img.isContinuous=%d", crop_img.isContinuous()); printf("\n"); cv::Mat crop_img2; //crop_img2.create(crop_img2.size(), crop_img2.type()); crop_img2 = crop_img.clone();//重新clone()后的图像是连续的 printf("---crop_img2.isContinuous=%d", crop_img2.isContinuous()); printf("\n"); } int main() { isContinuousTest(); cout << "end ..." << endl; return 0; }

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

isContinuous() 判定 矩阵 row 是否是连续存储 | 笔记

26

27

28

29

30

31

32

33

34

35

36

37

38

39

为什么会关注这个问题

原因: 在对Mat 元素进行变换操作后,返回的Mat 变得不连续,导致 OpenCV 方法 后续 Mat 计算数值存在误差

解决方法:return dst.clone(); 返回一个 连续的 Mat 出去 | 在做一些变换操作之后,进行连续性判定,如果不连续,则 进行 clone() ;

face_identification.cpp

process.cpp – 具体原因分析

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何在使用ModelArts的时候构建自定义的python环境
下一篇:Android学习笔记05:ProgressBar的使用
相关文章

 发表评论

暂时没有评论,来抢沙发吧~