hi all,
I have a big image defined as :
img_whole_ = std::make_sharedcv::Mat(800, 5120, CV_8UC1)
and I want to divide it into four 800x1280 images.
If I do the following, my four images come out screwed up:
img1->data = ((*img_whole_)(cv::Range(0, 800),cv::Range(0 , 1280))).data;
img2->data = ((*img_whole_)(cv::Range(0, 800),cv::Range(1280, 2560))).data;
img3->data = ((*img_whole_)(cv::Range(0, 800),cv::Range(2560, 3840))).data;
img4->data = ((*img_whole_)(cv::Range(0, 800),cv::Range(3840, 5120))).data;
While if I create a new Mat this way:
cv::Mat pd1 = ((*img_whole_)(cv::Range(0, 800),cv::Range(0 , 1280)));
it works correctly.
The Step value of every Mat is correct.
What am I doing wrong?
Thanks
You don’t need std::make_sharedcv::Mat(800, 5120, CV_8UC1)
Mat already use shared data
instead of roi you should try
◆ Mat() [13/29]
I would strongly recommend formatting code as code, not as a comment. you will notice how your comment swallows some syntax.
thanks i will give it a try
berak
6
using pointers.
this correctly saves the offsets of the roi within the ‘parent’ Mat
this only copies a (private !) data pointer, it neither updates refcounts or offsets/strides
cv::Mat img_whole { 800, 5120, CV_8UC1 };
cv::Mat img1 { img_whole, cv::Range(0, 800), cv::Range(0, 1280) };
// ...
img1
is a view into img_whole
. data can be altered through either of them.