c++ - Understanding openCV code snippet -


i have question peace of code.

...............  cv::mat image;  image = cv::imread(filename.c_str(), cv_load_image_color);    if (image.empty()) {    std::cerr << "couldn't open file: " << filename << std::endl;    exit(1);  }   cv::cvtcolor(image, imagergba, cv_bgr2rgba);    imagegrey.create(image.rows, image.cols, cv_8uc1);   *inputimage = (uchar4 *)imagergba.ptr<unsigned char>(0);  *greyimage  = imagegrey.ptr<unsigned char>(0); 

as understand create opencv mat object. read image it. why use filename.c_str()? instead of filename? , why convert bgr rgba? cv::cvtcolor(image, imagergba, cv_bgr2rgba); read in documentation imread reads image rgb not bgr. confusing part:

  *inputimage = (uchar4 *)imagergba.ptr<unsigned char>(0);   *greyimage  = imagegrey.ptr<unsigned char>(0); 

what's happening here? why need casts? know lot of question, want know whats happening here.)

  1. imread takes const char* first argument , cannot pass std::string directly it
  2. opencv stores matrices bgr. imread adheres channel order (documentation might misleading, don't confuse image format read (rgb) versus internal representation (bgr)). based on cuda tag guess wants pass image data gpu. gpus typically work rgba format. not bgr<->rgb having 4 channels in interleaved format.
  3. the mat::ptr() templated (it not casting!) because mat hides datatype you. code risky, assumes imread create mat_<uchar> , right type access. better start cv::mat_<uchar> in first place, use mat_<t>::operator[] pointer first row etc.
  4. i don't know comes next in code there might bug if stride (step) not considered.

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -