Ask Your Question
0

How to save cv::mat in opencv c++ function to image file in IOS for debugging

asked 2017-04-12 10:38:20 -0600

Jun Fang gravatar image

I am building an image processing project in IOS using c++ opencv and objective c in Xcode. It captures every frames and does some image processing work. When debugging the image processing c++ function for every frames from the phone's camera (running the project in the iphone), i need to save cv::mat to image files in IOS. Then I can check these image files to debug image processing algorithms.

In Android, we can use cv::imwrite to write cv::mat to image files to the defined path of the android phone. However, it doesn't work in IOS. It maybe some protection mechanism of IOS system.

There should be another method to achieve it. Or display the cv::mat when running IOS-based opencv project in the phone.

Thanks very much!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-04-14 00:52:07 -0600

Luis Oscar gravatar image

1) Include this header

#include <opencv2/imgcodecs/ios.h>

2) Use the OpenCV's "MatToUIImage(...)" to transform your Mat to an UIImage.

3) Save the UIImage using the standard methods. (Swift code, but you can figure out the Objective-C counterpart for it)

UIImageWriteToSavedPhotosAlbum(imageToSave, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
edit flag offensive delete link more

Comments

It works. Thanks very much.

Jun Fang gravatar imageJun Fang ( 2017-04-22 07:01:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-12 10:38:20 -0600

Seen: 2,894 times

Last updated: Apr 14 '17