Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. void testOnes() {
  2. int x=2; int y=2; //arbitrary
  3.  
  4. // 1 channel
  5. cv::Mat img_C1 = cv::Mat::ones(x,y,CV_8UC1);
  6. uchar px1 = img_C1.at<uchar>(0,0); //not sure of correct data type for px in 1-channel img
  7. printf("px of 1-channel img: %d n", (int)px1); //prints 1
  8.  
  9. // 3 channels
  10. cv::Mat img_C3 = cv::Mat::ones(x,y,CV_8UC3); //note 8UC3 instead of 8UC1
  11. cv::Vec3b px3 = img_C3.at<cv::Vec3b>(0,0);
  12. printf("px of 3-channel img: %d %d %d n", (int)px3[0], (int)px3[1], (int)px3[2]); //prints 1 0 0
  13. }
  14.  
  15. cv::Mat img_C3( x, y, CV_8UC3, CV_RGB(1,1,1) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement