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/

OpenCV reshape The Matrix is not continuous, thus its number of rows can not be changed的更多相关文章

  1. Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  2. LeetCode 566. Reshape the Matrix (重塑矩阵)

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  3. leetcode算法:Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  4. [LeetCode] Reshape the Matrix 重塑矩阵

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  5. 566. Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  6. [Swift]LeetCode566. 重塑矩阵 | Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  7. LeetCode 566 Reshape the Matrix 解题报告

    题目要求 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ...

  8. [LeetCode&Python] Problem 566. Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  9. LeetCode 566. Reshape the Matrix (C++)

    题目: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a n ...

随机推荐

  1. 【开发笔记】- MD5加密

    主要用于对用户密码的加密,保护用户账户安全: /** * @author shenruihai * */ import java.security.MessageDigest; import org. ...

  2. 移动端vue2.5去哪儿项目-常见问题整理

    一.项目中遇到的问题.难点及解决方式 1. 移动端开发中的1px边框问题,由于在不同设备屏幕上,可能会使得1px实际在移动端显示不是1px,怎么解决? 2. 移动端click点击事件,会延迟300ms ...

  3. 设置 SQL*Plus 的运行环境

    SQL*Plus 的运行环境是用来输入.执行 SQL*Plus 命令和显示返回结果的场所,设置合适的 SQL*Plus 运行环境,可以使 SQL*Plus 按照用户的要求运行和执行各种操作.set 命 ...

  4. Springboot项目统一异常处理

    Springboot项目统一异常处理 一.接口返回值封装 1. 定义Result对象,作为通用返回结果封装 2. 定义CodeMsg对象,作为通用状态码和消息封装 二.定义全局异常类 三.定义异常处理 ...

  5. requests爬虫get请求

    1.简单get请求 url = 'https://www.baidu.com' headers = { 'accept': 'text/html,application/xhtml+xml,appli ...

  6. ORA-01031:insufficient privileges 解决方法

    使用sys或system帐号登录plSql时,提示ORA-01031:insufficient privileges 错误.使用其他的帐号能正常登录,在cmd命令中用system帐号也是可以正常登录. ...

  7. 使用Cloudera Manager搭建YARN集群及YARN HA

    使用Cloudera Manager搭建YARN集群及YARN HA 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.使用Cloudera Manager搭建YARN集群 1& ...

  8. IP和网络互联

    IP和网络互联 IP网络互连机制: IP地址分类方法及原因: CIDR地址(无分类地址): IP分组首部格式: 数据分片方法: IP分组传输思路:

  9. 加速 Unity 不同平台打包的一种思路

    Unity打包总的来说还不是一件特别复杂的事情, 但是我们知道任何关于跨平台(多线程等)这类问题, 总是会把事情搞得复杂起来. 以前项目的打包是通过Jenkins对一个工程下对不同平台多次打包, 不可 ...

  10. java连接Oracle数据库的操作说明

    在测试中,我们常常需要连接Oracle数据库来进行查询对比.下面,我们就来看看,如何使用java代码来连接数据库,并且取出我们想要的数值. 首先,java中如果要连接Oracle数据库,需要jdbc的 ...