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 ...
随机推荐
- OO第三单元(地铁,JML)单元总结
OO第三单元(地铁,JML)单元总结 这是我们OO课程的第二个单元,这个单元的主要目的是让我们熟悉并了解JML来是我们具有规格化编程架构的思想.这个单元的主题一开始并不明了,从第一次作业的路径到第二次 ...
- 【转载】Java对象的生命周期
Java对象的生命周期 在Java中,对象的生命周期包括以下几个阶段: 1. 创建阶段(Created) 2. 应用阶段(In Use) 3. 不可见阶段(Invisib ...
- jupyter安装出现问题:安装后无法打开
jupyter安装出现问题:安装后无法打开 traitlets.traitlets.TraitError: Could not decode 'C:\Users\\xce\xa2\xcc\xf0\xd ...
- 'adb' 不是内部或外部命令,也不是可运行的程序 或批处理文件—解决方法
Windows键 + R → 输入cmd → 输入adb,提示“adb不是内部或外部命令,也不是可运行的程序 或批处理文件“,错误信息如下: 解决方法: 此电脑(右击)→ 属性 → 高级系统设置 → ...
- src属性与浏览器渲染
img标签 只要设置了src属性, 就会开始下载,因此可以使用这个特性,配合display:none,默默的下载一些图片,用的时候直接用,快了那么一丢丢~ 注意:不一定要添加到文档后才会开始下载,是只 ...
- Delphi-RzDbgrid-绘制表格式设置某行颜色或者其他格式-以及隔行换色的属性
参考文章:https://www.cnblogs.com/OSKnown/p/8568740.html 在DbgridEh和原生的Dbgrid直接在DrawColumnCell事件中写重绘代码就好了, ...
- [https][tls] 如何使用wireshark查看tls/https加密消息--使用keylog
姊妹篇: [ipsec][strongswan] 使用wireshark查看strongswan ipsec esp ikev1 ikev2的加密内容 [https][tls] 如何使用wiresha ...
- 17.centos7基础学习与积累-003-命令练习01
1.从头开始积累centos7系统运用 大牛博客:https://blog.51cto.com/yangrong/p5 linux命令的学习: 创建目录:mkdir mkdir /data mkdir ...
- XSL-FO知识点【一】
XSL-FO 用于格式化供输出的 XML 数据. 什么是 XSL-FO? XSL-FO 是用于格式化 XML 数据的语言 XSL-FO 指可扩展样式表语言格式化对象(Extensible Styles ...
- node gm图片操作
1,安首先要安装 GraphicsMagick或者ImageMagick 2,npm install gm --save 3,编码测试 var fs = require('fs') //graph ...