1 #include<opencv2/opencv.hpp> 2 #include<iostream> 3 #include<cassert> 4 #include<vector> 5 #include<stdio.h> 6 #include <sys/time.h> 7 8 using namespace cv; 9 using namespace std; 10 11 int main(int argc, char** argv) 12 { 13 Mat srcImage=imread(argv[1], CV_LOAD_IMAGE_COLOR); 14 printf("srcImage-data address:%p\n", srcImage.data); 15 Mat m = srcImage.clone(); 16 printf("m-data address:%p\n", m.data); 17 cout << "m.depth:" << m.depth() << endl; 18 cout << "m.type:" << m.type() << "-" << CV_8UC3 << endl; 19 20 Mat m_64; 21 m.convertTo(m_64, CV_64FC3); 22 printf("m_64-data address:%p\n", m_64.data); 23 cout << "m_64.depth:" << m_64.depth() << endl; 24 cout << "m_64.type:" << m_64.type() <<"-" << CV_64FC3 << endl; 25 26 Mat m_8; 27 m_64.convertTo(m_8, CV_8UC3); 28 printf("m_8-data address:%p\n", m_8.data); 29 cout << "m_8.depth:" << m_8.depth() << endl; 30 cout << "m_8.type:" << m_8.type() <<"-" << CV_8UC3 << endl; 31 32 //cout << m_64 << endl; 33 cout << m_8 << endl; 34 35 36 //result:convertTo转换data会存储在新的地方 37 //srcImage-data address:0x7fa6ac1bb020 38 //m-data address:0x7fa6ac0fa020 39 //m.depth:0 40 //m.type:16-16 41 //m_64-data address:0x7fa69dcba020 42 //m_64.depth:6 43 //m_64.type:22-22 44 //m_8-data address:0x7fa69dbf9020 45 //m_8.depth:0 46 //m_8.type:16-16 47 48 vector<Mat> channels; 49 Mat imageBlue,imageGreen,imageRed; 50 Mat mergeImage; 51 52 split(m, channels); 53 imageBlue = channels.at(0); 54 55 for (int i = 0; i < imageBlue.rows; i++) 56 for (int j = 0; j < imageBlue.cols; j++) 57 { 58 imageBlue.at<uchar>(i, j) = i; 59 } 60 61 imageGreen = channels.at(1); 62 imageRed = channels.at(2); 63 merge(channels, m); 64 65 //result:67 //m-data address:0x7f8058621020 68 69 //cout << srcImage << endl; 70 //cout << m << endl; 71 //cout << mergeImage << endl; 72 cout << endl; 73 74 return 0; 75 }
时间: 2024-10-10 08:16:35