kwiver icon indicating copy to clipboard operation
kwiver copied to clipboard

ocv::image_container::vital_to_ocv memory issue for grayscale image

Open mattbrown11 opened this issue 8 years ago • 0 comments

When converting a grayscale image within an image_container_sptr to a cv::Mat cv_dest = ocv::image_container::vital_to_ocv(image_dest->get_image()); I am encountering image corruption at random times throughout the pipeline processing, which leads me to believe something is going on with the image data memory. If I follow the above with cv_dest = cv_dest.clone();, the issue goes away.

If you look at https://github.com/Kitware/kwiver/blob/master/arrows/ocv/image_container.cxx#L140, you can see that it exercises a different code path for mono images. I don't have these issues with RGB images.

I think it might be related to this TODO https://github.com/Kitware/kwiver/blob/master/arrows/ocv/image_container.cxx#L162

If I recall, Converting cv::Mat —> vital::image —> cv::Mat for shallow copies works with reference counting because Vital keeps a copy of OpenCV’s reference counter. However, vital::image —> cv::Mat —> vital::image is incomplete because we have to hack OpenCV somehow to make it remember Vital’s reference counter. So where that TODO is we might need an “else return deep copy” until we figure out how to hack OpenCV.

mattbrown11 avatar Aug 25 '17 02:08 mattbrown11