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 ...
随机推荐
- 【洛谷 P2597】 [ZJOI2012]灾难(LCA)
题目链接 考虑建一棵树,使一个生物灭绝时他的子树都会灭绝,显然这样答案就是以每个点为根的子树大小-1. 为什么原图不是一棵树,因为一个生物可能会以多个生物为食,所以按拓扑序来建树,把每个遍历到的点的父 ...
- CSS标签选择器&类选择器
基本选择器包括标签选择器.类选择器和ID选择器三类,其他选择器都是在这三类选择器的基础上组合形成 ##标签选择器 示例: <style type="text/css"> ...
- webpack--splitChunksPlugin配置学习随笔
该配置用于代码抽离.官方文档 官方默认配置: module.exports = { //... optimization: { splitChunks: { chunks: 'async', // 异 ...
- Qt QListWidget
以下代码是 List Widget 添加数据项的代码,一般放在构造函数即可. /*********************添加数据项*********************/ QIcon icon1 ...
- linux对象系统---kobject, ktype, kset, subsys
本文转自:linux中kobject/ktype/kset/subsys之间的关系 随着内核版本的发展,会有一些变化,无论怎样,变化的是形式,不变的是思想! 那么他们之间具有什么关系?那应该不是'小3 ...
- SpringBoot+SpringCloud+vue+Element开发项目——集成Swagger文档
在pom.xml文件中添加Maven依赖 <!--swagger--> <dependency> <groupId>io.springfox</groupId ...
- NFS启动文件系统
NFS启动文件系统 一.软硬件平台 1.开发板:创龙AM3359核心板,网口采用RMII形式. 2.UBOOT版本:U-Boot-2016.05,采用FDT和DM. 3.交换芯片MARVELL的88E ...
- HTML&CSS基础-CSS的语法
HTML&CSS基础-CSS的语法 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.dome.html源代码 <!DOCTYPE html> <html ...
- python3 生成二维码并存入word文档
#二维码的制作与解析 import qrcode,zxing,os s='https:////www.baidu.com/' res=qrcode.make(data=s) res.show() re ...
- 怎么保证redis集群的高并发和高可用的?
redis不支持高并发的瓶颈在哪里? 单机.单机版的redis支持上万到几万的QPS不等. 主要根据你的业务操作的复杂性,redis提供了很多复杂的操作,lua脚本. 2.如果redis要支撑超过10 ...