天天看點

基于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)顯示出圖檔。

繼續閱讀