日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【OpenCV入门学习笔记1】:Mat对象的指针操作和掩膜操作

發(fā)布時(shí)間:2025/3/13 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【OpenCV入门学习笔记1】:Mat对象的指针操作和掩膜操作 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

b站:https://www.bilibili.com/video/BV1uW411d7Wf?p=5
下面是我在b站上看視頻學(xué)習(xí)的筆記和操作的示例代碼

實(shí)例代碼

#include<opencv2/opencv.hpp> #include<iostream> #include<math.h>using namespace cv;int main(int argc, char** argv) {Mat src, dst;src = imread("E:/picture/pic_cv/pic.jpg");if (!src.data) {printf("Could not load image...\n");return -1;}namedWindow("input image", WINDOW_AUTOSIZE);imshow("input image", src);//-------------------------------------------------------------------------//----------------------【自定義掩膜操作過(guò)程】-----------------------------//------------------------------------------------------------------------int cols = src.cols * src.channels();//RGB圖像是三通道圖像int offsetx = src.channels();//左右漂移多少是通道數(shù)決定的int rows = src.rows;dst = Mat::zeros(src.size(), src.type());//對(duì)dst圖像矩陣初始化為src的大小和類型 //一定要注意初始化!!for (int row = 1; row < (rows - 1); row++) {const uchar* previous = src.ptr<uchar>(row - 1);uchar* current = src.ptr<uchar>(row);const uchar* next = src.ptr<uchar>(row + 1);uchar* output = dst.ptr<uchar>(row);//創(chuàng)建指針指向dst的row行for (int col = offsetx; col < cols - offsetx; col++){//方法一:這樣出來(lái)的圖像跟麻臉一樣,因?yàn)橛械臄?shù)據(jù)超過(guò)了255,或小于0,造成溢出//output[col] = 5 * current[col] - (current[col - offsetx] + current[col + offsetx] + previous[col] + next[col]);//方法二:用saturate_cast(飽和函數(shù))函數(shù) 處理溢出數(shù)據(jù)output[col] = saturate_cast<uchar>(5 * current[col] - (current[col - offsetx] + current[col + offsetx] + previous[col] + next[col]));}}//-------------------------------------------------------------------------//----------------------【end1】-----------------------------//------------------------------------------------------------------------namedWindow("contrast image demo 1", WINDOW_AUTOSIZE);imshow("contrast image demo 1", dst);//-------------------------------------------------------------------------//----------------------【調(diào)用filter2D函數(shù)操作】-----------------------------//------------------------------------------------------------------------double t = getTickCount();Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0,-1, 5, -1,0, -1, 0);filter2D(src, dst, src.depth(), kernel);double timeconsume = (getTickCount() - t) / getTickFrequency();printf("time consume :%.2lf", timeconsume);//-------------------------------------------------------------------------//----------------------【end2】-----------------------------//------------------------------------------------------------------------namedWindow("contrast image demo 2", WINDOW_AUTOSIZE);imshow("contrast image demo 2", dst);waitKey(0);return 0; }

總結(jié)

以上是生活随笔為你收集整理的【OpenCV入门学习笔记1】:Mat对象的指针操作和掩膜操作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。