OpenCV reshape The Matrix is not continuous, thus its number of rows can not be changed
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的更多相关文章
- Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- LeetCode 566. Reshape the Matrix (重塑矩阵)
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- leetcode算法:Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- [LeetCode] Reshape the Matrix 重塑矩阵
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- 566. Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- [Swift]LeetCode566. 重塑矩阵 | Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- LeetCode 566 Reshape the Matrix 解题报告
题目要求 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ...
- [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 ...
- LeetCode 566. Reshape the Matrix (C++)
题目: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a n ...
随机推荐
- DateTimePicker控件CustomFormat格式字符串及其说明
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wuzhanwen/article/details/78800720格式字符串 描述 d 一个或两位数 ...
- vue+vant-UI框架写的购物车的复选框全选和反选
购物车页面的设计图 商品的列表 代码: <ul v-if="shoppingListData.rows.length"> <li v-for="(ite ...
- Java 之 web服务器—Tomcat
一.服务器 1.服务器 服务器:安装了服务器软件的计算机 2.服务器软件 服务器软件:接收用户的请求,处理请求,做出响应 3.Web 服务器软件 web 服务器软件:接收用户的请求,处理请求,做出响应 ...
- UCOSIII钩子函数
OSIdleTaskHook 空闲任务调用这个函数,可以用来让CPU进入低功耗模式 void OSIdleTaskHook (void) { #if OS_CFG_APP_HOOKS_EN > ...
- mysql如何让有数据的表的自增主键重新设置从1开始连续自增
项目开发中,有些固定数据在数据表中,主键是从1自增的,有时候我们会删除一些数据, 这种情况下,主键就会不连续.如何恢复到像第一次插入数据一样主键从1开始连续增长, 这里我找到一种解决方法: 如上面一张 ...
- js 数组的深度拷贝 的四种实现方法
首先声明本人资质尚浅,本文只用于个人总结.如有错误,欢迎指正.共同提高. --------------------------------------------------------------- ...
- 【kafka】安装部署kafka集群(kafka版本:kafka_2.12-2.3.0)
3.2.1 下载kafka并安装kafka_2.12-2.3.0.tgz tar -zxvf kafka_2.12-2.3.0.tgz 3.2.2 配置kafka集群 在config/server.p ...
- svn忘记密码怎么办?如何获取svn账号和密码?
SVN作为一种开放源代码的集中式版本控制系统,一直以来都深受所有公司的喜爱.伴随着它使用范围的广泛,一系列问题也随之接踵而至. 我们今天就来谈谈比较常见的但一般除了一个人干着急没办法解决的问题,那就是 ...
- CentOS上使用ntfs-3g挂载NTFS分区
U盘做过系统盘,是NTFS格式的,Centos7竟然不识别,而且因为一些原因,我的服务器没有联网,只能用U盘 查过资料才知道Centos7上默认是不支持挂载NTFS格式的分区的,需要安装ntfs-3g ...
- 分配swap分区空间
1. 分区,并修改为swap分区ID [root@centos2 ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux ). 更改将停留在内存中,直到您决定将更改写入磁盘 ...