When using OpenCV  reshape and gets this error:

OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number
of rows can not be changed) in unknown function,

Let's look at the documentation of the reshape function, Wrong parameters can also cause this error

According to the documentation the signature is

Mat Mat::reshape(int cn, int rows=) const

With the following meaning of the arguments:

  • cn – New number of channels. If the parameter is 0, the number of channels remains the same.
  • rows – New number of rows. If the parameter is 0, the number of rows remains the same.

Note that the number of columns is implicit -- it's calculated from the existing matrix properties and the two parameters.

According to this, the code

data = mu.reshape(, );

creates a 5-channel matrix of 5 rows and 1 column.

In order to reshape you matrix to a single channel 5x5 matrix, you have to do the following:

data = mu.reshape(, );

Alternately, since the input matrix is already single channel, you can also use

data = mu.reshape(, );

Besides:

there are 3 cases, where you'd get non-continuous Mat's.

  • it's a roi
  • bmp images and the like sometimes come padded
  • you made a mat from a pixel pointer ( i.e some non-opencv capture device ) and that might be padded, too

since you have to reorder the memory in all those cases, checking for continuity and a clone() acll will solve it.

 
if ( ! mat.isContinuous() )
{
mat = mat.clone();
}

参考:

https://stackoverflow.com/questions/36191118/opencv-reshape-function-does-not-work-properly

https://answers.opencv.org/question/22742/create-a-memory-continuous-cvmat-any-api-could-do-that/

最新文章

  1. 从零开始编写自己的C#框架(25)——网站部署
  2. 学习C的笔记
  3. jquery实现 复选框 全选
  4. 批量修改一张表格的多个sheet名
  5. Cauchy 级数浓缩判别法
  6. nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 56; cvc-complex-type.2.4.c通配符的匹配很全面, 但无法找到元素 'dubbo:application' 的声明
  7. js 获取随机数
  8. Web学习资源及手册查询整理
  9. console调试--转
  10. Week16(12月23日):复习
  11. 对于IE6版本图片透明。
  12. ACdream 1031 Cut
  13. JsonArray转List,list转json字符串
  14. C语言与java语言中数据类型的差别总结
  15. 用Nifi 从web api 取数据到HDFS
  16. 004_为什么不推荐APP使用SSL-PINNING
  17. 为Hexo Next主题添加分享及打赏功能
  18. 【BZOJ3529】数表
  19. IAR中的 identifier "FILE" is undefined 问题
  20. SpringMVC由浅入深day01_9商品修改功能开发

热门文章

  1. go语言 goquery爬虫
  2. java web编程 servlet2
  3. 【Redis】基本数据类型及命令操作(超详细)
  4. 【zookeeper】apache-zookeeper-3.5.5的安装测试
  5. Flink原理(五)——容错机制
  6. Linux磁盘管理——MBR 与 GPT
  7. 高并发架构系列:Redis并发竞争key的解决方案详解
  8. SpringCloud2.0 Config 分布式配置中心 基础教程(十一)
  9. Murach ASP.NET 4.5 C# With Visual Studio 2013 翻译
  10. Ajax -异步请求 -jquery中ajax分类 -第一层 $.ajax -第二层($.get /$.post) -第三层($.getJson/$.getScript) -相应演示