Hans Sperker
Hans Sperker

Reputation: 1347

Xcode (4.3.2) problems with openCV (2.3.1) installed from port

I have a problem using openCV 2.3.1 installed from mac ports. For installation and configuration of the xcode project I used this post from Salem's blog. The example code shown in the post works great. But if I change the mail.cpp file to just show an image it fails. Here is my example code:

#include <iostream>

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main (int argc, const char * argv[])
{
    cv::Mat img = cv::imread("Lena.jpg");
    cv::namedWindow("Image");
    cv::imshow("Image", img);
}

The error I get is the following:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/OpenCV-2.3.1/modules/core/src/array.cpp, line 2482
terminate called throwing an exception(lldb) 

Now I am a bit confused since I'm also not that familiar with c++.

Any advice?

Upvotes: 2

Views: 1223

Answers (1)

karlphillip
karlphillip

Reputation: 93468

There's a chance that the crash is being caused by imread() failing to locate the image on the disk:

cv::Mat img = cv::imread("Lena.jpg");
if (!img.data)
{
     // print error and abort execution
}

and you'll never know unless you start to code safely.

Upvotes: 3

Related Questions