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 ...
随机推荐
- 在notepad++中编辑时光标消失不见
在notepad++进行编辑时,会不知道的情况下,鼠标光标由竖线变成了下划线,如图 解决方法很简单,是点击”insert“键或者”ins“键,即可改变光标形状.
- Matlab相关函数使用
1.cat:拼接两个数组.
- brython的问题
brython 挺不错,但有bug. 再brython中使用mpmath做精确计算. 发现: int((103654973826275244659954807217085022028357821605 ...
- 【新手可看懂】ubuntu配置appium环境
1.node安装: 在node官网:https://nodejs.org/en/download/ 下载对应的安装包(这里建议下载最新的版本)下载好后放在liunx指定路径下 我这里放到opt这个文件 ...
- SAP开源的持续集成-持续交付的解决方案
SAP开源的持续集成/持续交付的解决方案: (1) 一个叫做piper的github项目,包含一个针对Jenkins的共享库和一个方便大家快速搭建CI/CD环境的Docker镜像: (2) 一套SAP ...
- JDBC中PreparedStatement相比Statement的好处
Statement对象: 用于执行不带参数的简单SQL语句: 特点: a. 只执行单条的sql语句: b. 只能执行不带参数的sql语句: c.运行原理的角度,数据库接收到sql语句后需要对该条sql ...
- Scrapy 概览笔记
本项目代码可参考 imzhizi/myspider: a scrapy demo with elasticsearch 虚拟环境的创建 建议爬虫项目都创建虚拟环境 虚拟环境在 Python 项目中真的 ...
- p2.BTC-数据结构
hash pointers:哈希指针,除了保存值的地址,还要存这整个区块的内容的hash值.这样就既能访问到值,还能确定访问的值有没有被篡改. 一 Blockchain Block chain is ...
- Django图书管理系统(前端对有外键的数据表增删改查)
图书管理 书籍管理 book name 项目源码位置:https://gitee.com/machangwei-8/learning_materials/tree/master/%E9%A1%B9%E ...
- Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学
Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ...