opencv reshape函数说明
转自http://blog.csdn.net/yang6464158/article/details/20129991
reshape有两个参数:
其中,参数:cn为新的通道数,如果cn = 0,表示通道数不会改变。
参数rows为新的行数,如果rows = 0,表示行数不会改变。
注意:新的行*列必须与原来的行*列相等。就是说,如果原来是5行3列,新的行和列可以是1行15列,3行5列,5行3列,15行1列。仅此几种,否则会报错。
具体调用也很简单,代码如下所示:
- #include <iostream>
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- int main()
- {
- cv::Mat testMat = cv::Mat::zeros ( 5, 3, CV_8UC3 );
- std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout<<"testMat = "<<testMat<<std::endl;
- cv::Mat result = testMat.reshape ( 0, 3 );
- std::cout << " size of original testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout << " size of reshaped testMat: " << result.rows << " x " << result.cols << std::endl;
- std::cout << "result = " << result << std::endl;
- cv::waitKey(0);
- system("pause");
- return 0;
- }
结果如下:
比如说:下面的情况就会报错:
- #include <iostream>
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- int main()
- {
- cv::Mat testMat = cv::Mat::ones ( 5, 3, CV_8UC3 );
- std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout<<"testMat = "<<testMat<<std::endl;
- cv::Mat result = testMat.reshape ( 0, 6 );
- std::cout << " size of original testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout << " size of reshaped testMat: " << result.rows << " x " << result.cols << std::endl;
- std::cout << "result = " << result << std::endl;
- cv::waitKey(0);
- system("pause");
- return 0;
- }
因为行和列的乘积不相等
结果如下:
我们在使用reshape的时候一定不能用定义的Mat类型赋给原来的类型,必须重新定义一个新类。
可以这样:
- unsigned char v11[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
- cv::Mat A = cv::Mat(3, 4, CV_8U, v11);
- cv::Mat B = A.reshape(1, 12);
但不能这样:
- cv::Mat testMat = cv::Mat::zeros ( 5, 3, CV_8UC3 );
- std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- testMat.reshape ( 0, 1 );
- std::cout << " size of reshaped testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
opencv reshape函数说明的更多相关文章
- opencv3学习:reshape函数
在opencv中,reshape函数比较有意思,它既可以改变矩阵的通道数,又可以对矩阵元素进行序列化,非常有用的一个函数. 函数原型: C++: Mat Mat::reshape() const 参数 ...
- Matlab 的reshape函数
看Matlab的help文档讲得不是清楚. 先给上一段代码: >> a=[1 2 3;4 5 6;7 8 9;10 11 12]; >> b=reshape(a,2,6); 这 ...
- Matlab 的reshape函数(转)
看Matlab的help文档讲得不是清楚. 先给上一段代码: >> a=[1 2 3;4 5 6;7 8 9;10 11 12]; >> b=reshape(a,2,6); 这 ...
- 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 ...
- python numpy.shape 和 numpy.reshape函数
导入numpy模块 from numpy import * import numpy as np ############################################### ...
- opencv-6-图像绘制与opencv Line 函数剖析
opencv-6-图像绘制与opencv Line 函数剖析 opencvc++qt 开始之前 越到后面, 写的越慢, 之前还抽空去看了下 学堂在线那篇文章提供的方法, 博客第一个人评论的我, 想想还 ...
- 【记录一个问题】macos下lldb调试opencv的一个程序,出现“failed to load objfile for”错误,并且无法调试进入opencv的函数
opencv编译使用了Debug版本,打开了BUILD_WITH_DEBUG_INFO=ON选项. 发现问题后,我又在CMAKE_CXX_FLAGS_DEBUG中设置为 -g -ggdb3,在CMAK ...
- 学习OpenCV——Gabor函数的应用
原文:http://blog.csdn.net/yao_zhuang/article/details/2532279 下载cvgabor.cpp和cvgabor.h到你的C/C++工程目录下 注:在我 ...
- 【麦子学院】OpenCV教程函数总结
个自带样例. parter 1: No1. adaptiveskindetector.cpp 利用HSV空间的色调信息的皮肤检測,背景不能有太多与肤色相似的颜色.效果不是特别好. No2. bagof ...
随机推荐
- JVM_总结_03_Java发展史
一.前言 通过上一节,我们对整个java的技术体系有了一定的了解. 这一节我们来看下Java的发展史. 二.Java发展史 1.时间线 序号 发布日期 JDK 版本 新特性 详细说明 0 1991.0 ...
- 配合Jenkins自动化构建,bat脚本(一)
C:\Windows\System32\inetsrv\appcmd.exe stop site ServiceIIS C:\Windows\System32\inetsrv\appcmd.exe s ...
- 2018-2019-2 20165210《网络对抗技术》Exp6 信息搜集与漏洞扫描
2018-2019-2 20165210<网络对抗技术>Exp6 信息搜集与漏洞扫描 一.实验目标: 掌握信息搜集的最基础技能与常用工具的使用方法. 二.实验内容: 各种搜索技巧的应用 G ...
- mysql定时任务备份bat命令-记录一下待日后使用
最近有个任务,需要每日备份数据库到某个磁盘,使用window定时任务调用bat文件实现. %Date:~0,2%获取星期几,这个要根据系统进行尝试, 有 星期几 7/25/2018 有 2018/ ...
- 普通方法实现——远程方法调用RMI代码演示
1.spring_RMI01_server服务端 package com.wisezone.service; import java.rmi.Remote; import java.rmi.Remot ...
- Js中获取键盘的事件
使用方法: <script type="text/javascript" language=JavaScript charset="UTF-8"> ...
- mysql之 xtrabackup原理、备份日志分析、备份信息获取
一. xtrabackup备份恢复工作原理: extrabackup备份简要步骤 InnoDB引擎很大程度上与Oracle类似,使用redo,undo机制,XtraBackup在备份的时候,以read ...
- es5中foreach的用法
HTML代码: <p id="result"></p> JS代码: var eleResult = document.getElementById(&quo ...
- Swing编程把图片放入frame里。先不作为背景图片
总结: 总之遵循一条,所有的组件都不是直接放入frame里的.还要label的重要性,panel.面板类 虽然我还是不会做,但总算出了个图片出来~~~~~~~~~~~~~ package com.kk ...
- PAT L3-008. 喊山(BFS)C4 初赛30分
喊山(30 分) 喊山,是人双手围在嘴边成喇叭状,对着远方高山发出“喂—喂喂—喂喂喂……”的呼唤.呼唤声通过空气的传递,回荡于深谷之间,传送到人们耳中,发出约定俗成的“讯号”,达到声讯传递交流的目的. ...