Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. IplImage * I = cvLoadImage( "myimage.tif" );
  2. CvScalar pixel = cvGet2D( I, y, x );
  3.  
  4. cv::Mat I = cv::imread( "myimage.tif" );
  5. if( I.depth() == CV_8U && I.channels() == 3 )
  6. cv::Vec3b pixel = I.at<cv::Vec3b>( x, y );
  7. else if( I.depth() == CV_32F && I.channels() == 1 )
  8. float pixel = I.at<cv::float>( x, y );
  9.  
  10. Mat img; // My input mat, initialized elsewhere
  11.  
  12. // Pretty fast operation, Will only create an iplHeader pointing to the data in the mat
  13. // No data is copied and no memory is mallocated.
  14. // The Header resides on the stack (note its type is "IplImage" not "IplImage*")
  15. IplImage iplImg = (IplImage)img;
  16.  
  17. // Then you may use the old (slow converting) legacy-functions if you like
  18. CvScalar s = cvGet2D( &iplImg, y, x );
  19.  
  20. cv::Mat mat = ...; // something
  21. cv::Scalar value = cv::mean(mat(cv::Rect(x, y, 1, 1)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement