3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
按照OPENCV教學文件 純C++ 範例練習紀錄 ~ [opencv_ex04-圖像單純複製clone、圖像轉換+複製cvtColor、判斷是RGB或者為灰階圖channels、抓取/設定圖像每一彩色像素點的RGB值at(y, x)、抓取/設定圖像每一灰階像素點的值at(y, x)] GITHUB:https://github.com/jash-git/CPP_opencv249_ex #include #include #include #include #include #include #include #if defined(WIN32)     #define  TIMEB    _timeb     #define  ftime    _ftime     typedef __int64 TIME_T; #else     #define TIMEB timeb     typedef long long TIME_T; #endif using namespace cv; using namespace std; void Pause() {     printf("Press Enter key to continue...");     fgetc(stdin); } int main() {     Mat src00, dst00,dst000; Mat src01, dst01; src00 = imread("image-20150507-1245-fctkfq.jpg");//imread("Lena_original.jpg"); if (!src00.data) { printf("could not load image...\n"); } else     {         namedWindow("Lena_original", CV_WINDOW_AUTOSIZE);         imshow("Lena_original", src00);         cvtColor(src00, src01, CV_BGR2GRAY);//imread("Lena_original.jpg",IMREAD_GRAYSCALE);         namedWindow("cvtColor()~CV_BGR2GRAY", CV_WINDOW_AUTOSIZE);         imshow("cvtColor()~CV_BGR2GRAY", src01);         int cols = src00.cols;         int rows = src00.rows;         int channels00 = src00.channels();         int channels01 = src01.channels();         printf("rows : %d cols : %d\n", rows, cols);         printf("channels00 : %d channels01 : %d\n", channels00, channels01);         dst00=src00.clone();         dst01=src01.clone();         dst000.create(src00.size(),src00.type());         for(int x=0;x(y, x)= 255-dst01.at(y, x);                 Vec3b ReadRGB = dst00.at(y, x);                 int b=ReadRGB.val[0];                 int g=ReadRGB.val[1];                 int r=ReadRGB.val[2];                 dst00.at(y,x)[0]=255-b;                 dst00.at(y,x)[1]=255-g;                 dst00.at(y,x)[2]=255-r;                 dst000.at(y,x)[0]=0;                 dst000.at(y,x)[2]=g;                 dst000.at(y,x)[3]=r;             }         }         namedWindow("Lena_test01", CV_WINDOW_AUTOSIZE);         imshow("Lena_test01", dst00);         namedWindow("Lena_test02", CV_WINDOW_AUTOSIZE);         imshow("Lena_test02", dst01);         namedWindow("Lena_test03", CV_WINDOW_AUTOSIZE);         imshow("Lena_test03", dst000);     } waitKey(0);     Pause();     return 0; }

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦