ubuntu+opencv显示图片

首先建立源码文件showPicture.cpp:

#include "opencv2/core.hpp"  
#include "opencv2/imgproc.hpp"  
#include "opencv2/highgui.hpp"  
#include <iostream>  
  
using namespace cv;  
using namespace std;  
  
  
int main()  
{  
    cout << "Hello OpenCV " << CV_VERSION << endl;  
  
    // 载入图像  
    Mat myMat = imread("天.jpg", 1);  
  
    // 创建一个窗口  
    namedWindow("Opencv Image", WINDOW_AUTOSIZE);  
  
    // 显示图像  
    imshow("Opencv Image", myMat);  
  
    // 等待按键延时 ms  
    waitKey(5000);  
  
    return 0;  
} 

然后建立编译文件CMakeLists.txt

# cmake needs this line 要求的最低版本  
cmake_minimum_required(VERSION 2.8)  
  
# Define project name 定义工程名  
project(example_project)  
  
# Find OpenCV, you may need to set OpenCV_DIR variable  
# to the absolute path to the directory containing OpenCVConfig.cmake file  
# via the command line or GUI 自动查找库  
find_package(OpenCV REQUIRED)  
  
# Declare the executable target built from your sources 声明可执行目标文件及源文件  
add_executable(example showPicture.cpp) # 目标文件,源文件0,源文件1,...  
  
# Link your application with OpenCV libraries 将目标文件与库链接  
target_link_libraries(example ${OpenCV_LIBS})   # 目标文件,库路径  

$cmeke . 后出现问题:

By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "OpenCV", but
  CMake did not find one.

  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake
原因:我装opencv的时候没有选择默认路径,所以要手动指定一下

OpenCVConfig.cmake

这个文件。

编译文件这样写:

# cmake needs this line 要求的最低版本  
cmake_minimum_required(VERSION 2.8)  
  
# Define project name 定义工程名  
project(example_project)  
  
# Find OpenCV, you may need to set OpenCV_DIR variable  
set(OpenCV_DIR /usr/opencv-3.2.0/build) 手动设置OpenCVConfig.cmake的路径!
# to the absolute path to the directory containing OpenCVConfig.cmake file  
# via the command line or GUI 自动查找库  
find_package(OpenCV REQUIRED)  
  
# Declare the executable target built from your sources 声明可执行目标文件及源文件  
add_executable(example showPicture.cpp) # 目标文件,源文件0,源文件1,...  
  
# Link your application with OpenCV libraries 将目标文件与库链接  
target_link_libraries(example ${OpenCV_LIBS})   # 目标文件,库路径  

接着

$cmake .

$make .

..

成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值