
分类: 数字图像处理 Qt2012-04-18 17:21 104人阅读 评论(0) 收藏 举报
打开Qt项目中的.pro文件,添加如下代码
INCLUDEPATH +=D:\\OpenCV\\opencv\\build\include\\opencv2 \
D:\\OpenCV\\opencv\\build\include\\opencv \
D:\\OpenCV\\opencv\\build\include
CONFIG(release,debug|release)
{
LIBS += D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_calib3d231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_contrib231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_core231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_features2d231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_flann231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_gpu231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_highgui231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_imgproc231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_legacy231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_ml231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_objdetect231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_ts231.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_video231.lib
}
CONFIG(debug,debug|release)
{
LIBS +=D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_calib3d231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_contrib231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_core231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_features2d231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_flann231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_gpu231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_highgui231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_imgproc231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_legacy231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_ml231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_objdetect231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_ts231d.lib \
D:\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_video231d.lib
}
注意,你的代码中的路径要根据OpenCV的具体安装路径做改变。
测试程序
#include #include using namespace std; using namespace cv; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); const char* imagename = ; //从文件中读入图像 Mat img = imread(imagename); //如果读入图像失败 if(img.empty()) { fprintf(stderr, "Can not load image %s\\n", imagename); waitKey(); return -1; } //显示图像 imshow("image", img); //此函数等待按键,按键盘任意键就返回 waitKey(); return a.exec(); }
