OpenCV E盘相关资料

1、访问Mat数据的行数:
Mat image
Cout<<image.rows
输出Mat
Mat image;
Cout<<image<<endl;
2、定义Mat
整型CV_32U CV_32S
浮点型 CV_32F
3、Mat image(240,360,8UC3)
无法通过image.atcv::Vec3b(2,2)[0]访问(2,2)元素的第0通道值;
可以:
Int n= image.atcv::Vec3b(2,2)[0];
Cout<<n
访问,n不能定义为unsigned char ,否则无法访问。
240是高度,360是宽度。
4、imshow必须碰到waitkey()才输出图像
5、判断Mat的元素类型:
Mat image;
Cout<<Image.type();

6、查询一个Mat的成员参数的常用函数:
https://www.cnblogs.com/justkong/p/7278579.html
7、CV_EXPORTS 导出数据、函数等用的,不用看它。
8、定义SIFT ORBSURF等检测器、描述子、匹配器:
http://www.360doc.com/content/17/1202/15/18306241_709241757.shtml
9、templatestruct cv::Ptr
https://docs.opencv.org/3.4/d0/de7/structcv_1_1Ptr.html
A?Ptr pretends to be a pointer to an object of type T. Unlike an ordinary pointer, however, the object will be automatically cleaned up once all?Ptr?instances pointing to it are destroyed.
10、imread()函数可以加载的mode ,默认是RGB,还可以是grayscale
CV_LOAD_IMAGE_COLOR——BGR
CV_LOAD_IMAGE_GRAYSCALE——grayscale
11、Keypoint 数据结构中并不保存特征点的描述信息。
https://blog.csdn.net/suntingsheng123/article/details/79218441
12、Mat r=(Mat_(1,3)<<1,2,3)
1行3列
Mat.at(行号,列号)
13、Mat.convertTo()
Mat A; A.converTo(B,CV_8U,255,25)
则B(x,y)=A(x,y)255+25。
14、OpenCV-Python
Compared to languages like C/C++, Python is slower. That said, Python can be easily extended with C/C++, which allows us to write computationally intensive code in C/C++ and create Python wrappers that can be used as Python modules. This gives us two advantages: first, the code is as fast as the original C/C++ code (since it is the actual C++ code working in background) and second, it easier to code in Python than C/C++. OpenCV-Python is a Python wrapper for the original OpenCV C++ implementation.
OpenCV-Python makes use of?Numpy, which is a highly optimized library for numerical operations with a MATLAB-style syntax. All the OpenCV array structures are converted to and from Numpy arrays. This also makes it easier to integrate with other libraries that use Numpy such as SciPy and Matplotlib.
15、为Python2设置OpenCV: sudo apt-get install python-opencv
为Python3设置OpenCV:sudo apt-get install python3-opencv
16、OpenCV中的Point类:https://blog.csdn.net/weicao1990/article/details/53517751/
17、
配置OpenCV+contrib:
1、如果已安装OpenCV,则先卸载OpenCV,进入OpenCV的build文件夹,执行:
sudo make uninstall
cd …
sudo rm -r build
删除其余的:
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv
/usr/local/lib/libopencv
这一步如果有错,完全忽略。
进入/usr/local/include/下查看,是否有OpenCV文档,如果没有,说明卸载成功。
2、安装依赖项
sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libopenexr-dev libtbb-dev libjasper-dev
安装libjasper-dev如果安不上,则:
sudo add-apt-repository “deb?http://security.ubuntu.com/ubuntu?xenial-security main”
sudo apt update
sudo apt install libjasper1 libjasper-dev
可能还要安装:
sudo apt-get install pkg-config libavcode-dev libavformat-dev libswscale-dev
3、下载OpenCV的source版和对应的contrib,contrib到github下载,在release选项下,找对应的版本。
4、解压
5、contrib里还有一个contrib文件夹,然后才是modules等文件夹,把第二层的contrib文件夹复制出来,到openCV文件夹下。
6、安装cmake-gui
7、cd OpenCV
mkdir build
cd build
8、打开cmake-gui,配置好source和build,source处就是OpenCV文件夹位置。点Configure,选择默认的compilers.

9、安装contrib

其中OPENCV_EXTRA_MODULES_PATH地方改为:/opencv-3.4.7/contrib/modules/

其余配置默认
10、点configure,然后generate
11、进入OpenCV,进入build
make
sudo make install
18、
从逻辑上考虑,图像模糊是因为图像中物体的轮廓不明显,轮廓边缘灰度变化不强烈,层次感不强造成的。微分就是求函数的变化率,即导数(梯度),那么对于图像来说,可不可以用微分来表示图像灰度的变化率呢,当然是可以的,前面我们提到过,图像就是函数嘛。

100和90之间亮度相差10,并不是很明显,与一大群90的连续灰度值在一起,轮廓必然是模糊的。我们注意到,如果相邻像素灰度值有变化,那么梯度就有值,如果相邻像素灰度值没有变化,那么梯度就为0。如果我们把梯度值与对应的像素相加,那么灰度值没有变化的,像素值不变,而有梯度值的,灰度值变大了。

相加后的新图像,原图像像素点100与90亮度只相差10,现在是110与90,亮度相差20了,对比度显然增强了,尤其是图像中物体的轮廓和边缘,与背景大大加强了区别,这就是用梯度来增强图像的原理。
4K图像就是指水平方向每行像素值达到或者接近4096个的图像,多数情况下特指40962160分辨率。
19、OpenCV下载下来本身是个CMake的工程。
20、
OpenCV 计时工具cv::getTickCount https://www.cnblogs.com/zhibei/p/12400948.html
21、.xml和.yaml文件是两种类似.json的文件,.xml是标签文件,类似HTML,.yaml文件类似.json文件。https://docs.opencv.org/master/dd/d74/tutorial_file_input_output_with_xml_yml.html
22、Opencv中waitkey(a)的用法,如果a小于等于0,等待键盘按键,如果大于0,延迟一定毫秒。
23、OpenCV
cv::CommandLineParser用法
CommandLineParser parser( argc, argv, “{input2 | 00.jpg | input 455533image}”"{input1 | 0.jpg | input image}" );
src2 = imread( samples::findFile( parser.get( “input2” ) ), IMREAD_COLOR );
src1 = imread( samples::findFile( parser.get( “input1” ) ), IMREAD_COLOR );
cout<<“rows18828:”<<src1.rows<<endl;
cout<<“rows18828:”<<src2.rows<<endl;
CommandLineParser用于解释输入命令行,此时命令行输入./opencvlearn即可,不用输入具体图片变量,” ”中的格式是:{ name_param | default_value | description},即变量名,变量,变量描述。name_param 前面可以带有@,这样定义了这个参数的默认输入值。https://yq.aliyun.com/articles/233160/
24、namedWindow()是定义一个窗口,moveWindow()是移动这个窗口,即改变它在屏幕上的位置。
25、把几个Mat融合到一个Mat,size不变,channel增加。
Mat m1 = (Mat_(2,2) << 1,4,7,10);
Mat m2 = (Mat_(2,2) << 2,5,8,11);
Mat m3 = (Mat_(2,2) << 3,6,9,12);
Mat channels[3] = {m1, m2, m3};
Mat m;
merge(channels, 3, m);
新建的m为2
2,3通道,(0,0)位置为1,2,3;(0,1)位置为4,5,6。
https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7d7b4d6c6ee504b30a20b1680029c7b4
相反,把一个Mat按channel,分解为几个Mat
char d[] = {1,2,3,4,5,6,7,8,9,10,11,12};
Mat m(2, 2, CV_8UC3, d);
Mat channels[3];
split(m, channels);
其中,channels[0]是1,4,7,10;channels[1]是2,5,8,11。
https://docs.opencv.org/master/d2/de8/group__core__array.html#ga0547c7fed86152d7e9d0096029c8518a

26、求两个Mat对应位置值的平方和,再开方。
用magnitude(x,y,z),假如x是3,3,3,3;y是4,4,4,4;z是5,5,5,5。
注意此时x,y和z的数据类型要一致.否则报错。
error: (-215:Assertion failed) src1.size() == src2.size() && type == src2.type() && (depth == CV_32F || depth == CV_64F) in function ‘magnitude’
https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6d3b097586bca4409873d64a90fe64c3
27、rect()用法
Mat q1(image, Rect(a, b, x, y));a,b代表起始点坐标a为横向,b为纵向,x,y代表宽(col)和高(row),这种方式,改变q1会改变image。
Rect rect(0, 0, cx, cy); Mat q1 = image(rect);这种方式,改变q1不会改变image。
28、Opencv用于处理图像,所以尽量避免不必要的复制图像,浪费时间。?a matrix may be shared between two?Mat?objects by having their matrix pointers point to the same address. Moreover, the copy operators?will only copy the headers?and the pointer to the large matrix, not the data itself.point to the same single data matrix and making a modification using any of them will affect all the other ones as well.The real interesting part is that you can create headers which refer to only a subsection of the full data.
Now you may ask – if the matrix itself may belong to multiple?Mat?objects who takes responsibility for cleaning it up when it’s no longer needed. The short answer is: the last object that used it. This is handled by using a reference counting mechanism. Whenever somebody copies a header of a?Mat?object, a counter is increased for the matrix. Whenever a header is cleaned, this counter is decreased. When the counter reaches zero the matrix is freed.
29、迭代器
Mat img = Mat::eye(3,3,CV_8U);
cout<<img<<endl;
Mat_::iterator it = img.begin();
Mat_::iterator itend = img.end();//end是最后一行最后一列的再后一位
for(; it != itend; ++it)
{
*it = *it * 2 + 1;
cout<<(int)*it<<endl;
}

如果开始定义Mat img = Mat::eye(3,3,CV_8U);

Mat img = Mat::eye(3,3,CV_8UC3);
cout<<img<<endl;
MatIterator_ it = img.begin();
MatIterator_ itend = img.end();//end是最后一行最后一列的再后一位

for(; it != itend; ++it)
{
    (*it)[1] = (*it)[1] * 2 + 3;
    //cout<<(int)(*it)<<endl;
}
cout << img<<endl;

In case of color images we have three uchar items per column. This may be considered a short vector of uchar items, that has been baptized in OpenCV with the?Vec3b?name. To access the n-th sub column we use simple operator[] access. It’s important to remember that OpenCV iterators go through the columns and automatically skip to the next row. Therefore in case of color images if you use a simple?uchar?iterator you’ll be able to access only the blue channel values.
29、Cv::Mat_ img;这是定义了一个Mat,其中Cv::Mat_时opencv的一种数据结构.
定义一个Mat: Mat I(1,3,CV_8U);
Mat img = Mat::eye(3,3,CV_8UC3);
Mat_ img;
uchar lutData[255];
Mat lut(1, 256, CV_8UC1, lutData);
Mat img.creat(4,4,CV_8UC2);
Mat new_image = Mat::zeros( image.size(), image.type() );

30、访问Mat中的值:指针uchar*p=I.ptr();
at()函数img.at(0,i)=5;img.at(1,2)[0];
Int intensity = img.at(y, x);或Int intensity = img.at(Point(x,y));
Scalar intensity=img.at(y, x);输出是一个数组

uchar green = intensity.val[1];输出可能是乱码
int green1 = intensity.val[1];输出为整数

31、Cv::lut在使用时注意第二个参数的size是256。https://blog.csdn.net/y363703390/article/details/79431450
32、在opencv中,竖下表示row,是y轴;水平向右,表示为列,column,是x轴。
(int)img.at(50,90)和(int)img.at(Point(90,50))输出是一样的。

(int)img.at(50,90)和(int)img.at(Point(50,90))输出是不一样的。

33、在使用Opencv时,尽量用库中已有的函数,因为快。
Mat的各种属性https://blog.csdn.net/daaizjh/article/details/81053165
Cv::CV_Assert(myImage.depth() == CV_8U);
如果Cv::CV_Assert()括号内的内容为false则报错
在图像中写字putText()函数
34、blur()函数参数解释https://blog.csdn.net/cau_eric/article/details/27378503
35、OpenCV的金字塔,用高斯卷积,然后删除偶数行和列,所以图像面积为1/4.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值