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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv4-图像操作

發布時間:2025/3/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv4-图像操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這里Vex3f 也可以是Vec3b

#include<opencv2\opencv.hpp> #include<iostream> #include<math.h> using namespace cv; using namespace std;//讀寫圖像, //讀寫像素, //修改像素值 int main() {Mat src = imread("E:\\vs2015\\opencvstudy\\2.jpg", 1);if (!src.data){cout << "could not load image!" << endl;return -1;}//imshow("inputImage", src);//單通道取反Mat gray_src;cvtColor(src, gray_src, CV_BGR2GRAY);//imshow("gray_src", gray_src);int rows = gray_src.rows;int cols = gray_src.cols;Mat gray_src_invert = Mat::zeros(gray_src.size(), gray_src.type());/*for (int row = 0; row < rows; row++){for (int col = 0; col < cols; col++){int gray_pixel = gray_src.at<uchar>(row, col);gray_src_invert.at<uchar>(row, col) = 255 - gray_pixel;}}imshow("gray_src_invert", gray_src_invert);*///3通道取反Mat dst,dst2;dst.create(src.size(), src.type());dst2.create(src.size(), src.type());int height = src.rows;int width = src.cols;int nc = src.channels();for (int row = 0; row < height; row++){for (int col = 0; col < width; col++){if (nc == 1){int gray_pixel = gray_src.at<uchar>(row, col);gray_src_invert.at<uchar>(row, col) = 255 - gray_pixel;}else if (nc == 3){int b = src.at<Vec3b>(row, col)[0];int g = src.at<Vec3b>(row, col)[1];int r = src.at<Vec3b>(row, col)[2];dst.at<Vec3b>(row, col)[0] = 255 - b;dst.at<Vec3b>(row, col)[1] = 255 - g;dst.at<Vec3b>(row, col)[2] = 255 - r;dst2.at<Vec3b>(row, col) = (r, max(g, b));}}}//imshow("3通道取反像素操作", dst);Mat bitwise_not_dst;bitwise_not(src, bitwise_not_dst); //位操作取反。等價于上面的像素操作//imshow("3通道取反bitwise_not", bitwise_not_dst);imshow("dst2", dst2);//空白圖像賦值Mat M3;M3.create(gray_src.size(), gray_src.type());M3 = Scalar(0);imshow("空白圖像", M3);//ROI選擇Rect r(300, 300, 1000, 400); //左上角的橫坐標,縱坐標,矩形高度,寬度cout << "gray_image height:" << gray_src.rows << endl;cout << "gray_image width:" << gray_src.cols << endl;Mat smallImg = gray_src(r);imshow("ROI截取圖像", smallImg);waitKey(0);return 0; }

?

總結

以上是生活随笔為你收集整理的opencv4-图像操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。