天天看点

基于Petalinux19.1的OpenCV APP搭建一、前言二、OpenCV App搭建

一、前言

 想在Xilinx ZCU102平台上运行Linux系统,并实现简单OpenCV App的运行,采用Petalinux19.1进行工程搭建。

二、OpenCV App搭建

1.准备Petalinux工程

1)新建Petalinux工程:

    >petalinux-create  --type project --template zynqMP --name opencvtest

2)指定HDF文件:   

    >petalinux-config --get-hw-description=hdf_file/

3)使能OpenCV、X11的Package:

    >petalinux-config -c rootfs

    使能

基于Petalinux19.1的OpenCV APP搭建一、前言二、OpenCV App搭建

    使能

基于Petalinux19.1的OpenCV APP搭建一、前言二、OpenCV App搭建

4)Build工程,封装得到BOOT.BIN和image.ub

    >petalinux-build

    >petalinux-package --boot --fsbl images/linux/zynqmp_fsbl.elf --fpga images/linux/system.bit --u-boot images/linux/u-boot.elf --force

把BOOT.BIN和image.ub考入SD卡,ZCU102平台可运行Linux;

2.新建OpenCV App

>petalinux--create -t apps --template c++ --name opencvapp --enable

>cd xxx/project-spec/meta-user/recipes-apps/opencvapp/files

1)opencvapp.cpp

#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv){

	Mat img;
	img = imread(argv[1],1);
	if((argc != 2) || (!img.data)){
		printf("Usage: XX yy.jpg\n");
		return -1;
	}
	imshow("imshooow",img);
	waitKey(0);
	return 0;
	
}
           

2)CMakeLists.txt

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

add_definitions(-std=c++11 -Werror=return-type)

# Define project name
project(opencvapp)

# 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)

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

set(SRC_LIST opencvapp.cpp )
# Declare the executable target built from your sources
add_executable(opencvapp ${SRC_LIST})

# Link your application with OpenCV libraries
target_link_libraries(opencvapp ${OpenCV_LIBS})
           

3)Makefile

APP = opencvapp

# Add any other object files to this list below
APP_OBJS = opencvapp.o

all: build
build: $(APP)

CXXFLAGS += $(shell pkg-config --cflags opencv)
LDFLAGS += $(shell pkg-config --libs opencv)

$(APP): $(APP_OBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o [email protected] $(APP_OBJS) $(LDLIBS)

clean:
	rm -f $(APP) *.elf *.gdb *.o
           

 4) opencvapp.bb

#
# This file is the opencvapp recipe.
#

SUMMARY = "Simple opencvapp application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://opencvapp.cpp \
           file://CMakeLists.txt \
		  "

S = "${WORKDIR}"

DEPENDS += "opencv"
inherit pkgconfig cmake


do_install() {
	     install -d ${D}${bindir}
	     install -m 0755 opencvapp ${D}${bindir}
}
           

3. 编译App

直接编译app:

    >petalinux-build -c opencvapp

编译完成后,找到xxxxx/tmp/opencvtest-2019.12.xx/deploy/rpm/aarch64/opencvapp-1.0-r0.aarch64.rpm文件,

将其在windows下解压,再解压,可得到:

/usr/bin/opencvapp

4. 运行

将opencvapp和test.jpg经SSH传入已运行的ZCU102平台中,

    >chmod 777 opencvapp test.jpg

配置SSH显示到本地:export DISPLAY=192.168.0.xx:0.0,然后运行

    >./opencvapp test.jpg

可(经SSH)显示出图片。

继续阅读