前言


一、简介

Ref:IplImage, CvMat, Mat 的关系

Mat是opencv2.0推出的处理图像的新的数据结构,现在越来越有趋势取代之前的cvMat和lplImage。

相比之下Mat最大的好处就是能够更加方便的进行内存管理,不再需要程序员手动管理内存的释放。

opencv2.3中提到Mat是一个多维的密集数据数组,可以用来处理向量和矩阵、图像、直方图等等常见的多维数据。

/* implement */

基本操作


操作Mat元素时:I.at<double>(1,1) = CV_PI;

本博客原内容

/*
*
* cvout_sample just demonstrates the serial out capabilities of cv::Mat
* That is, cv::Mat M(...); cout << M; Now works.
*
*/ #include "opencv2/core/core.hpp"
#include <iostream> using namespace std;
using namespace cv; static void help()
{
cout
<< "\n------------------------------------------------------------------\n"
<< " This program shows the serial out capabilities of cv::Mat\n"
<< "That is, cv::Mat M(...); cout << M; Now works.\n"
<< "Output can be formated to OpenCV, matlab, python, numpy, csv and \n"
<< "C styles Usage:\n"
<< "./cvout_sample\n"
<< "------------------------------------------------------------------\n\n"
<< endl;
} int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv, "{help h||}");
if (parser.has("help"))
{
help();
return ;
} /**************************************************************************/
// Jeff --> Define Diagnal Mat.
Mat I = Mat::eye(, , CV_64F);
I.at<double>(,) = CV_PI;
cout << "I = \n" << I << ";" << endl << endl; /*------------------------------------------------------------------------*/
Mat r = Mat(, , CV_8UC3);
randu(r, Scalar::all(), Scalar::all()); // Jeff --> Matrix Format transform.
cout << "r (default) = \n" << r << ";" << endl << endl;
cout << "r (matlab) = \n" << format(r, Formatter::FMT_MATLAB) << ";" << endl << endl;
cout << "r (python) = \n" << format(r, Formatter::FMT_PYTHON) << ";" << endl << endl;
cout << "r (numpy) = \n" << format(r, Formatter::FMT_NUMPY) << ";" << endl << endl;
cout << "r (csv) = \n" << format(r, Formatter::FMT_CSV) << ";" << endl << endl;
cout << "r (c) = \n" << format(r, Formatter::FMT_C) << ";" << endl << endl; /**************************************************************************/
Point2f p(, );
cout << "p = " << p << ";" << endl; /*------------------------------------------------------------------------*/
Point3f p3f(, , );
cout << "p3f = " << p3f << ";" << endl; /**************************************************************************/
// Jeff --> vector.
vector<float> v;
v.push_back(1.1);
v.push_back(2.2);
v.push_back(3.3); cout << "shortvec = " << Mat(v) << endl; /*------------------------------------------------------------------------*/
vector<Point2f> points();
for (size_t i = ; i < points.size(); ++i)
points[i] = Point2f((float)(i * ), (float)(i % )); cout << "points = " << points << ";" << endl;
return ;
}


Result
: Matrix Format for不同的工具。

r (default) =
[ 91, 2, 79, 179, 52, 205, 236, 8, 181;
239, 26, 248, 207, 218, 45, 183, 158, 101;
102, 18, 118, 68, 210, 139, 198, 207, 211;
181, 162, 197, 191, 196, 40, 7, 243, 230;
45, 6, 48, 173, 242, 125, 175, 90, 63;
90, 22, 112, 221, 167, 224, 113, 208, 123;
214, 35, 229, 6, 143, 138, 98, 81, 118;
187, 167, 140, 218, 178, 23, 43, 133, 154;
150, 76, 101, 8, 38, 238, 84, 47, 7;
117, 246, 163, 237, 69, 129, 60, 101, 41]; r (matlab) =
(:, :, 1) =
91, 179, 236;
239, 207, 183;
102, 68, 198;
181, 191, 7;
45, 173, 175;
90, 221, 113;
214, 6, 98;
187, 218, 43;
150, 8, 84;
117, 237, 60
(:, :, 2) =
2, 52, 8;
26, 218, 158;
18, 210, 207;
162, 196, 243;
6, 242, 90;
22, 167, 208;
35, 143, 81;
167, 178, 133;
76, 38, 47;
246, 69, 101
(:, :, 3) =
79, 205, 181;
248, 45, 101;
118, 139, 211;
197, 40, 230;
48, 125, 63;
112, 224, 123;
229, 138, 118;
140, 23, 154;
101, 238, 7;
163, 129, 41; r (python) =
[[[ 91, 2, 79], [179, 52, 205], [236, 8, 181]],
[[239, 26, 248], [207, 218, 45], [183, 158, 101]],
[[102, 18, 118], [ 68, 210, 139], [198, 207, 211]],
[[181, 162, 197], [191, 196, 40], [ 7, 243, 230]],
[[ 45, 6, 48], [173, 242, 125], [175, 90, 63]],
[[ 90, 22, 112], [221, 167, 224], [113, 208, 123]],
[[214, 35, 229], [ 6, 143, 138], [ 98, 81, 118]],
[[187, 167, 140], [218, 178, 23], [ 43, 133, 154]],
[[150, 76, 101], [ 8, 38, 238], [ 84, 47, 7]],
[[117, 246, 163], [237, 69, 129], [ 60, 101, 41]]]; r (numpy) =
array([[[ 91, 2, 79], [179, 52, 205], [236, 8, 181]],
[[239, 26, 248], [207, 218, 45], [183, 158, 101]],
[[102, 18, 118], [ 68, 210, 139], [198, 207, 211]],
[[181, 162, 197], [191, 196, 40], [ 7, 243, 230]],
[[ 45, 6, 48], [173, 242, 125], [175, 90, 63]],
[[ 90, 22, 112], [221, 167, 224], [113, 208, 123]],
[[214, 35, 229], [ 6, 143, 138], [ 98, 81, 118]],
[[187, 167, 140], [218, 178, 23], [ 43, 133, 154]],
[[150, 76, 101], [ 8, 38, 238], [ 84, 47, 7]],
[[117, 246, 163], [237, 69, 129], [ 60, 101, 41]]], dtype='uint8'); r (csv) =
91, 2, 79, 179, 52, 205, 236, 8, 181
239, 26, 248, 207, 218, 45, 183, 158, 101
102, 18, 118, 68, 210, 139, 198, 207, 211
181, 162, 197, 191, 196, 40, 7, 243, 230
45, 6, 48, 173, 242, 125, 175, 90, 63
90, 22, 112, 221, 167, 224, 113, 208, 123
214, 35, 229, 6, 143, 138, 98, 81, 118
187, 167, 140, 218, 178, 23, 43, 133, 154
150, 76, 101, 8, 38, 238, 84, 47, 7
117, 246, 163, 237, 69, 129, 60, 101, 41
; r (c) =
{ 91, 2, 79, 179, 52, 205, 236, 8, 181,
239, 26, 248, 207, 218, 45, 183, 158, 101,
102, 18, 118, 68, 210, 139, 198, 207, 211,
181, 162, 197, 191, 196, 40, 7, 243, 230,
45, 6, 48, 173, 242, 125, 175, 90, 63,
90, 22, 112, 221, 167, 224, 113, 208, 123,
214, 35, 229, 6, 143, 138, 98, 81, 118,
187, 167, 140, 218, 178, 23, 43, 133, 154,
150, 76, 101, 8, 38, 238, 84, 47, 7,
117, 246, 163, 237, 69, 129, 60, 101, 41};

  

[OpenCV] Samples 02: [ML] kmeans的更多相关文章

  1. [OpenCV] Samples 06: [ML] logistic regression

    logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...

  2. [OpenCV] Samples 02: Mat - 图像矩阵

    前言 一.简介 Ref:IplImage, CvMat, Mat 的关系 Mat是opencv2.0推出的处理图像的新的数据结构,现在越来越有趋势取代之前的cvMat和lplImage. 相比之下Ma ...

  3. [OpenCV] Samples 10: imagelist_creator

    yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic re ...

  4. [OpenCV] Samples 16: Decompose and Analyse RGB channels

    物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...

  5. [OpenCV] Samples 03: kmeans

    注意Mat作为kmeans的参数的含义. 扩展:高维向量的聚类. 一.像素聚类 #include "opencv2/highgui.hpp" #include "open ...

  6. [OpenCV] Samples 06: logistic regression

    logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...

  7. [OpenCV] Samples 03: cout_mat

    操作Mat元素时:I.at<double>(1,1) = CV_PI; /* * * cvout_sample just demonstrates the serial out capab ...

  8. OpenCV学习(23) 使用kmeans算法实现图像分割

          本章我们用kmeans算法实现一个简单图像的分割.如下面的图像,我们知道图像分3个簇,背景.白色的任务,红色的丝带以及帽子.       Mat img = cv::imread(&quo ...

  9. [OpenCV] Samples 13: opencv_version

    cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true whe ...

随机推荐

  1. android camera 自定义开发

    1.检测是否有摄像头 /** Check if this device has a camera */ private boolean checkCameraHardware(Context cont ...

  2. 各廠商ERP系統架構圖連結 (ERP流程圖)(轉)

    各廠商ERP系統架構圖連結 (ERP流程圖)   資料來源 Google圖片搜尋ERP整理而來 資通電腦 ArgoERP 資通電腦 Oracle ERP 鼎新電腦 Workflow ERP鼎新電腦 S ...

  3. 插入排序-java

    排序-插入排序 基本思想:将待排序表看作左右两部分,其中左边为有序区,右边为无序区, 整个排序过程就是将右边无序区中的元素逐个插入到左边的有序区中,以构成新的有序区. 平均时间:O(n2) 最好情况: ...

  4. onBlur事件与onfocus事件(js)

      onFocus事件就是当光标落在文本框中时发生的事件. onBlur事件是光标失去焦点时发生的事件. 可以编如下例子 1.html <HTML><HEAD><TITL ...

  5. hdoj 1022 Train Problem I

    #include<stdio.h> int main() { int n,i,j,k; ],]; ]; while(scanf("%d %s %s",&n,in ...

  6. 团队spring会议1

    一.我们在近期进行了第一次计划会议,会议过程大致如下: 1.确定所做项目的方向: 2.将调查问卷的结果进行统计,做了需求分析,大致了解了用户的想法: 3.确定了团队计划backlog: 4.将任务进行 ...

  7. Oracle Created (Default) Database Users

    http://www.idevelopment.info/data/Oracle/DBA_tips/Database_Administration/DBA_26.shtml DBA Tips Arch ...

  8. Linux之脚本安装软件

      查看启动程序   ps aux    准备工作 1.保证yum源正常使用 2.关闭SELinux和防火墙   下载脚本文件包 解压缩 运行 ./centors.sh

  9. 在线教学、视频会议 Webus Fox(1)文本、语音、视频聊天及电子白板基本用法

    Webus Fox是基于网页的在线教学.视频会议软件,不用安装,直接使用.它提供文本.语音.视频聊天,文件共享.电子白板等功能. 1. 登录 访问 http://flash.webus.cn/#,用自 ...

  10. 【TypeScript】如何在TypeScript中使用async/await,让你的代码更像C#。

    [TypeScript]如何在TypeScript中使用async/await,让你的代码更像C#. async/await 提到这个东西,大家应该都很熟悉.最出名的可能就是C#中的,但也有其它语言也 ...