I write some code to run on the iPad, I use cvLoadImage() to read image from Bundle Resources
, but it always return NULL
, I don't know why?
Asked
Active
Viewed 1,657 times
3

Ello
- 281
- 1
- 3
- 12
-
The path to the file is probably wrong. – Paul R Sep 14 '12 at 08:54
-
i add image to Bundle Resources,i think it does't need path,i just write the image's name. it's like "cvLoadImage("lena.jpg");" – Ello Sep 14 '12 at 09:01
-
You shouldn't make assumptions about the current working directory. Get the path to the bundle first and prefix your filename with the path. – Paul R Sep 14 '12 at 10:28
2 Answers
4
You can't load an image from your app bundle directly into OpenCV … Getting a proper cv::Mat involves two steps:
1.) Load your image using UIImage
2.) Convert the UIImage to a cv::Mat
Which looks like this:
cv::Mat img = [UIImageCVMatConverter cvMatFromUIImage:[UIImage imageNamed:@"my_image.png"]];
Grab the UIImageCVMatConverter class from this thread: OpenCV install in xcode
Hope that helps!
-
-
Please, can you explain why the images in the bundle can't be loaded directly with opencv functions? – Joe Aspara Sep 26 '15 at 15:33
0
use directly
[UIImage imageWithNamed:@"photo.png"];
if the image is in Bundle you can use directly.

Sanoj Kashyap
- 5,020
- 4
- 49
- 75