Converting UIImage to cv::Mat

后端 未结 2 874
天命终不由人
天命终不由人 2020-12-23 11:10

I have a UIImage which is a pic captured from an iPhone Camera now I want the UIImage to be converted to cv::Mat (OpenCV). I am using the following lines of code to accompli

2条回答
  •  抹茶落季
    2020-12-23 11:51

    You should consider using native OpenCV functions to convert forth and back :

    #import 
    ...
    UIImage* MatToUIImage(const cv::Mat& image);
    void UIImageToMat(const UIImage* image,
                             cv::Mat& m, bool alphaExist = false);
    

    Note: if your UIImage comes from the camera, you should 'normalize' it ( iOS UIImagePickerController result image orientation after upload) before converting to cv::Mat since OpenCV does not take into account Exif data. If you don't do that the result should be misoriented.

提交回复
热议问题