在Manjaro下用Clion配置OpenCV时发现编译失败
存在问题

opencv2/xxx.hpp:没有那个文件或目录

当前配置的CMakeList.txt文件为

cmake_minimum_required(VERSION 3.14)
project("图像处理")

find_package(OpenCV REQUIRED)
set(CMAKE_CXX_STANDARD 17)

add_executable(main main.cpp)

观测后发现文件中引入的是opencv4/opencv2/xxx.hpp
推测是因为在ArchLinux下默认滚动安装的opencv是有opencv4这个目录的

事实也是如此,OpenCV被安装在了/usr/include/opencv4

所以在CMakeList.txt下再次手动加入引用目录

修正后配置文件是

cmake_minimum_required(VERSION 3.14)
project("图像处理")

find_package(OpenCV REQUIRED)
include_directories("/usr/include/opencv4")
set(CMAKE_CXX_STANDARD 17)

add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})

编译后发现链接库失败。
发现安装OpenCV时缺失依赖hdf5和vtk两个依赖。安装上以后,运行正常。

附测试代码:

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

int main() {
    cv::Mat img = cv::imread("../pics/img.jpg");
    cv::namedWindow("Origin", cv::WINDOW_NORMAL);
    cv::resizeWindow("Origin", 640, 640);
    cv::imshow("Origin", img);
    //拉普拉斯算子
    cv::Mat imageEnhance1;
    cv::Mat kernel = (cv::Mat_<float>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
    cv::filter2D(img, imageEnhance1, CV_8UC3, kernel);
    cv::namedWindow("Enhanced", cv::WINDOW_NORMAL);
    cv::imshow("Enhanced", imageEnhance1);
    cv::resizeWindow("Enhanced", 640, 640);
    //基于对数Log变换
    cv::Mat imageLog(img.size(),CV_32FC3);
    for (int i = 0; i < img.rows; i++)
	{
		for (int j = 0; j < img.cols; j++)
		{
			imageLog.at<cv::Vec3f>(i, j)[0] = log(1 + img.at<cv::Vec3b>(i, j)[0]);
			imageLog.at<cv::Vec3f>(i, j)[1] = log(1 + img.at<cv::Vec3b>(i, j)[1]);
			imageLog.at<cv::Vec3f>(i, j)[2] = log(1 + img.at<cv::Vec3b>(i, j)[2]);
		}
	}
	//归一化到0~255  
	normalize(imageLog, imageLog, 0, 255, cv::NORM_MINMAX);
	//转换成8bit图像显示  
	convertScaleAbs(imageLog, imageLog);
    cv::namedWindow("Enhanced2", cv::WINDOW_NORMAL);
    cv::imshow("Enhanced2", imageLog);
    cv::resizeWindow("Enhanced2", 640, 640);
    cv::waitKey(0);
    return 0;
}
说点什么
支持Markdown语法
在"ArchLinux下OpenCV配置"已有1条评论
Loading...