openCV学习路线
参考数目:《openCV入门教程》
程序一
- 实现图像的生成,对像素点的遍历操作
- 实现图像的展示
#include<iostream>
#include"opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(int argc, char const *argv[])
{
Mat grayim(600,800,CV_8UC1);
Mat colorim(600,800,CV_8UC3);
for (int i = 0; i < grayim.rows; ++i)//row,表示行
{
uchar *p = grayim.ptr<uchar>(i);
for (int j = 0; j < grayim.colos; ++j)
{
p[j]=(i+j)%255;
}
}
for (int i = 0; i < colorim.rows; ++i)
{
Vec3b *p=colorim.ptr<Vec3b>(i);
for (int j = 0; j < colorim.colos; ++j)
{
p[j][0]=i%255;
p[j][1]=j%255;
p[j][2]=0;
}
}
imshow("grayim",grayim);
imshow("colorim",colorim);
waitKey(0);
return 0;
}
实验结果
程序二
实现基本的矩阵操作
/**
* @description: Mat的使用方法
*/
#include<iostream>
#include"opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(int argc,char* argv[]){
Mat A = Mat::eye(4,4,CV_32SC1);
Mat B = A*3+1;
Mat C = B.diag(0)+B.col(1);
cout<<"A="<<A<<endl;
cout<<"B="<<A<<endl;
cout<<"C="<<A<<endl;
cout<<"C.*diag(B)="<<C.dot(B.diag(0))<<endl;//表示点积
return 0
}
实验结果
本文主要参考自《opencv入门一书》,侵删。