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.)
- imread takes
const char*first argument , cannot passstd::stringdirectly it - 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.
- the
mat::ptr()templated (it not casting!) because mat hides datatype you. code risky, assumes imread createmat_<uchar>, right type access. better startcv::mat_<uchar>in first place, usemat_<t>::operator[]pointer first row etc. - i don't know comes next in code there might bug if stride (step) not considered.
Comments
Post a Comment