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. 虚拟机与宿主机可以互相ping通,但是外网不能

    http://rickcheung.blog.51cto.com/913220/354429 1.CentOS 修改DNS 修改对应网卡的DNS的配置文件 # vi /etc/resolv.conf  ...

  2. Attribute与Property关系

    总的来说,其实是HTML Attribute 与 DOM property之间的关系. 1 什么是Property? JS DOM Object对象有property.一个property可能是不同数 ...

  3. ABAP开发者上云的时候到了 - 现在大家可以免费使用SAP云平台ABAP环境的试用版了

    之前Jerry已经写了一系列SAP Cloud Platform ABAP编程环境的文章,当时使用的环境,是SAP专门为SAP社区导师们创建的. 当时也有朋友留言,询问大家何时才能使用到免费的SAP云 ...

  4. 安装folly库以及folly的ConcurrentHashMap的简单使用

    我在写grpc的实例时, 需要使用一个多线程的hash map, C++标准库中没有多线程的hash map, facebook开源的folly中存在大量的基础类, 中间存在一个高性能的hash ma ...

  5. IAR8.X安装教程

    安装教程 1.下载 2.安装 3.和谐 1.下载 打开官网  找到要下载的版本3. 下载8.4下载地址 不支持中文路径,有点坑https://netstorage.iar.com/SuppDB/Pro ...

  6. Linux/Windows下安装SonarCube

    1. 下载合适的版本,尽量不要下载最新的版本,最新的版本要求Java 11+,如果没有安装最新版的Java的话,尽量用 SonarQube 7.0 以下的版本,SonarQube 7.0是可以用jdk ...

  7. 用js刷剑指offer(丑数)

    题目描述 把只包含质因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含质因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路 ...

  8. 隐藏按钮button

    <td> <input id="del" type="button" value="删除" onclick="u ...

  9. 【转】使用JavaParser获得Java代码中的类名、方法形参列表中的参数名以及统计总的文件个数与不能解析的文件个数

    遍历目录查找Java文件: public static void ergodicDir(File dir, HashSet<String> argNameSet, HashSet<S ...

  10. Codeforces D. Powerful array(莫队)

    题目描述: Problem Description An array of positive integers a1, a2, ..., an is given. Let us consider it ...