c++ - Ubuntu Illegal Instruction opencv -


i installed opencv on ubuntu 12.04.5 repository using command.

sudo apt-get install libopencv-dev python-opencv 

when try run following code confirm works illegal instruction (it compiled fine).

#include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include<iostream>  using namespace std;  int main(){     cv::mat img;     img = cv::imread("ro.ppm");     cout << img.size() << endl;     return 0;  } 

i compiled using command (due undefined reference errors).

g++ -o test test.cpp $(pkg-config opencv --cflags --libs) 

update: commenting out cout line not change result , i've triple checked ro.ppm exists in directory (even if didn't imread doesn't throw error illegal or not found input in experience). guess question two-fold causes illegal instruction errors , how fix it?

you can't cout cv::size directly without overloading '<<' operator cv::size. instead can rows , columns cv::size , multiply them in order total size of image:

#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include<iostream>  using namespace std;  int main(){     cv::mat img;     img = cv::imread("ro.ppm");     cv::size img_size = img.size();      int cols =  img_size.width;     int rows =  img_size.height;     cout << "image size: " << rows*cols << endl;       return 0;  } 

see similar post usage of cv::size.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -