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. VBA 字符串-相关函数(1-5)

    Instr()函数 InStr()函数返回一个字符串第一次出现在一个字符串,从左到右搜索.返回搜索到的字符索引位置. 语法 InStr([start,]string1,string2[,compare ...

  2. PHP写的简单数字验证码

    用PHP写的随机生成的5位数字验证码 $yzm = ""; for($i=0;$i<5;$i++) { $a = rand(0,9); $yzm.= $a; } echo $ ...

  3. OS UIButton之UIButtonType详解-转

    我做了一个关于UIButtonType的Demo,效果如下图: UIButtonType各个类型的解释: typedef NS_ENUM(NSInteger, UIButtonType) { UIBu ...

  4. MySQL DataType--隐式类型转换

    隐式类型转换 在官方文档中对隐式类型转换规则有如下描述: 1. If one or both arguments are NULL, the result of the comparison is N ...

  5. 16.centos7基础学习与积累-002

    1.从头开始积累centos7系统运用 大牛博客:https://blog.51cto.com/yangrong/p5 互联网公司服务器品牌: dell 服务器品牌: 1U=4.45CM 2010年以 ...

  6. python协程详解,gevent asyncio

    python协程详解,gevent asyncio 新建模板小书匠 #协程的概念 #模块操作协程 # gevent 扩展模块 # asyncio 内置模块 # 基础的语法 1.生成器实现切换 [1] ...

  7. unity 之 背包系统

    此方法只是用于学习和实验所以细节不必要求 一.Ui设置. 画布配置如下: 布局: 说明: 画布里面首先建立一个panel命名为weapon1,在其内部再建立4个panel用于装备的卡槽,装备以imag ...

  8. c++第四次作业

    继承与派生--访问控制 一.知识要点 (一)知识回顾: 基类的成员可以有public.protected.private三种访问属性.基类的自身成员可以对基类中任何一个其他成员进行访问,但是通过基类的 ...

  9. MySQL将某个数据库下的所有表的存储引擎修改为InnoDB类型语句

    如何将mysql数据库中的MyISAM类型表更改为InnoDB类型的表 改单个表 ALTER TABLE TABLENAME ENGINE=InnoDB; ALTER TABLE TABLENAME ...

  10. [牛客网 -leetcode在线编程 -02] minimum-depth-of-binary-tree -树的最短深度

    题目描述 题目描述 Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along ...