标签:show imshow name res ast under 检查 1.2 article
1 ////////https://blog.csdn.net/uestc_c2_403/article/details/72814206 2 #include "opencv2/highgui/highgui.hpp" 3 #include "opencv2/imgproc/imgproc.hpp" 4 #include "opencv2/opencv.hpp" 5 #include "opencv2/core/core.hpp" 6 #include <iostream> 7 using namespace std; 8 using namespace cv; 9 //图像线性变换操作 10 cv::Mat linearTransform(cv::Mat srcImage, float a, int b) 11 { 12 if (srcImage.empty()) 13 { 14 std::cout << "No data!" << std::endl; 15 } 16 const int nRows = srcImage.rows; 17 const int nCols = srcImage.cols; 18 cv:; Mat resultImage = 19 cv::Mat::zeros(srcImage.size(), srcImage.type()); 20 //图像元素遍历 21 for (int i = 0; i < nRows; i++) 22 { 23 for (int j = 0; j < nCols; j++) 24 { 25 for (int c = 0; c < 3; c++) 26 { 27 //矩阵at操作,检查下标防止越界 28 resultImage.at<Vec3b>(i, j)[c] = saturate_cast<uchar>(a * (srcImage.at<Vec3b>(i, j)[c]) + b); 29 } 30 } 31 } 32 return resultImage; 33 } 34 int main() 35 { 36 cv::Mat srcImage = cv::imread("D:\\大海.jpg"); 37 if (srcImage.empty()) 38 { 39 return -1; 40 } 41 42 cv::imshow("源图像", srcImage); 43 //线性变换 44 float a = 1.2; 45 int b = 50; 46 cv::Mat new_image = linearTransform(srcImage, a, b); 47 cv::imshow("dst", new_image); 48 cv::waitKey(0); 49 return 0; 50 }
标签:show imshow name res ast under 检查 1.2 article
原文地址:https://www.cnblogs.com/thebreakofdawn/p/9489562.html