MatToUIImage problem after Rotate Image from MAT

I have the following code running in iOS, using for convert UIImage To MAT. After that,
rotate the image by OpenCV and convert it back to UIImage. But after use in iOS 17,
this code is bug (return nil image from function MatToUIImage)
Here is my code:

cv::Mat src;
    UIImageToMat(image, src);

    cv::Mat rotation;
    switch (flip) {
        case VERTICAL:
            cv::flip(src, rotation, 0);
        case HORIZONTAL:
            cv::flip(src, rotation, 1);
        case RIGHT:
            cv::flip(src.t(), rotation, 0);
        case LEFT:
            cv::flip(src.t(), rotation, 0);
        case INVERTED:
            cv::flip(src, rotation, -1);

    image = MatToUIImage(rotation);

    return image;

This happens when using previously converted images from MAT.
Example: UIImage to Mat β†’ Mat to UIImage β†’ Use this UIImage to another function β†’ UIImage to Mat β†’ Rotate MAT β†’ Mat to UIImage β†’ BUG
If use UIImage to MAT β†’ Rotate MAT β†’ Mat to UIImage β†’ Work normally
Before that, in iOS 16 lower. Everything working normally, just happen in iOS 17.
Has anyone encountered this situation? Please give me some opinion. Thanks
Screenshot 2023-10-24 at 16.38.23

No idea about ios, but your code might check


before converting to UIImage

(your β€˜default’ case is not producing a valid rotation Mat !)

Yes. I think something wrong with Mat. But i am using OpenCV 2.4.9, if i i update to OpenCV 4.3.0, this problem will be fix.
I dont know why. The same picture, the same code

forget that. far too old, no more maintained, dead beef.

again, old, frozen, no more maintained
(current is 4.8.1)

1 Like

Hii , tangtuongco . Can you please help me convert UIImage to Mat type using opencv and vice versa ? It is not converting in my case .

I want to do affine transformation on an UIImage uisng openCV .