zl程序教程

您现在的位置是:首页 >  后端

当前栏目

【边缘设备】nanoPC-T4 安装OpenCV

2023-09-14 09:15:12 时间

nanoPC-T4 安装 OpenCV

Note: OpenCV has been pre-installed in FriendlyCore/FriendlyDesktop (Version after 201905) and does not require manual installation.

Please download the latest FriendlyCore/FriendlyDesktop Image file from the following URL: http://download.friendlyarm.com

参考 nanoPC-T4 环境配置
【边缘设备】基于RK3399核心板的nanoPC-T4 线刷桌面版系统

【边缘设备】nanoPC-T4 线刷ubuntu2004核心非桌面版

【边缘设备】解决nanoPC-T4 upgrade报错

【边缘设备】nanoPC-T4 挂载NVME硬盘

安装OpenCV

按照上述配置刷机系统已经预装了 OpenCV;

建立 Python3 的 OpenCV 开发环境

注意:这里仅仅拷贝激活脚本,不做其他任何操作

git clone https://github.com/friendlyarm/install-opencv-on-friendlycore
cd install-opencv-on-friendlycore
cp examples/py/cv-env.sh /usr/bin/

测试

pi@NanoPC-T4:/media/nvme/install-opencv-on-friendlycore$ cd examples/py/
pi@NanoPC-T4:/media/nvme/install-opencv-on-friendlycore/examples/py$ . cv-env.sh 
(cv) pi@NanoPC-T4:/media/nvme/install-opencv-on-friendlycore/examples/py$ python ver.py 
4.2.0

虚拟环境激活 . cv-env.sh
虚拟环境退出 deactivate

建立 C++ 的 OpenCV 开发环境

OpenCVnanoPC-T4 里已经预装了。

命令查看下版本号,/usr/local/bin/opencv_version

.
├── CMakeLists.txt
├── README.md
├── sample.png
└── showimage.cpp
# cmake needs this line 
cmake_minimum_required(VERSION 2.8) 

# Enable C++11 
set(CMAKE_CXX_STANDARD 11) 
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 

# Define project name 
project(showimage) 

# 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 COMPONENTS core highgui calib3d) 
include_directories( ${OpenCV_INCLUDE_DIRS} ) 

# Declare the executable target built from your sources 
add_executable(showimage showimage.cpp) 

# Link your application with OpenCV libraries 
target_link_libraries(showimage ${OpenCV_LIBS})
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <cstdlib>
#include <stdio.h>
#include <time.h> 

using namespace std;
using namespace cv;

int main(int argc,char* argv[]) 
{
	Mat image = imread("sample.png");
	if (image.empty())
	{
		cout<<"no image"<<endl;
		return -1;
	}	
	imshow("test", image);
	waitKey(0);	
	destroyAllWindows();
    return 0;
}
mkdir build 
cp sample.png build/
cd build
cmake .. 
make -j4
./showimage

别急,执行完这里会黑屏的,那还是因为环境没有配好,和代码没有关系。

继续执行以下命令:

su pi

输入密码: pi

export DISPLAY=:0.0
. setqt5env

再执行 ./showimage 效果正常。

【参考】

  1. install-opencv-on-friendlycore
  2. 官网 Wiki